bbottema/simple-java-mail

[Bug] Message headers not treated with case insensitivity as per RFC, causing deviating headers to slip through the filters

Closed this issue · 1 comments

I'm using an older version, but have recreated on 8.8.2. If an email is converted using EmailConverter.emlToEmail, and then back again using EmailConverter.emailToEML, and the email has the Cc header in all caps ("CC") then duplicate Cc / CC headers are created on the EML.

Outlook / Exchange appears to use upper case when sending mails - the RFC822 spec doesn't mention case, and the examples in the spec vary between cc, Cc and CC.

The code below shows the problem on the attached sample emails.

Path path = Paths.get("TestingCCPass.eml");
//Path path = Paths.get("TestingCCFail.eml");

contents = Files.readString(path,StandardCharsets.UTF_8);
Email t_message = EmailConverter.emlToEmail(new ByteArrayInputStream(contents.getBytes()));
System.out.println(t_message.getRecipients());			
String t_eml = EmailConverter.emailToEML(t_message);
System.out.println(t_eml);

Pass:

[Recipient{name='someone else', address='someone_else@example.com', type=To}, Recipient{name='Another Person', address='another_person@example.com', type=Cc}]
Date: Tue, 9 Apr 2024 23:57:57 +0100 (BST)
From: someone someone@example.com
Reply-To: someone someone@example.com
To: someone else someone_else@example.com
Cc: Another Person another_person@example.com
Message-ID: 858952163.0.1712703477049@UK-LT-19664.civica.root.local
Subject: An RFC 822 formatted message
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

This is the plain text body of the message. Note the blank line
between the header information and the body of the message.

Fail:

[Recipient{name='someone else', address='someone_else@example.com', type=To}, Recipient{name='Another Person', address='another_person@example.com', type=Cc}]
Date: Wed, 10 Apr 2024 00:08:18 +0100 (BST)
From: someone someone@example.com
Reply-To: someone someone@example.com
To: someone else someone_else@example.com
Cc: Another Person another_person@example.com
CC: Another Person another_person@example.com
Message-ID: 1201484275.0.1712704098760@UK-LT-19664.civica.root.local
Subject: An RFC 822 formatted message
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

This is the plain text body of the message. Note the blank line
between the header information and the body of the message.

TestingSamples.zip

Fix released in 8.8.3. Thank you for bringing this to my attention!