simple-java-mail icon indicating copy to clipboard operation
simple-java-mail copied to clipboard

Support having different Content-Transfer-Encoding in multipart messages

Open mnmallea opened this issue 4 months ago • 0 comments

Hi. I noticed that when parsing an email from its .eml representation and sending it over to an SMTP server using simple-java-mail the Content-Transfer-Encoding header is changed for some parts of the message. For example: This is my .eml file:

From: [email protected]
To: [email protected]
Subject: Example multipart message
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="boundary123"

--boundary123
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Hello,
This is the plain text version of the email.

--boundary123
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<html>
  <body>
    <p>Hello,</p>
    <p>This is the <b>HTML</b> version of the email.</p>
    <p>Notice the non-breaking space:&nbsp; and =C2=A9 symbols.</p>
  </body>
</html>

--boundary123--

After parsing it from a file and sending it to the SMTP like this:

var eml = Files.readString("etc etc");
var email = EmailConverter.emlToEmail(eml);
mailer.sendEmail(email);

What I got on the other side is something like this:

Content-Type: multipart/alternative; 	boundary="----=_Part_0_416639874.1756482293892"
Date: Fri, 29 Aug 2025 12:44:53 -0300 (ART)
From: [email protected]
MIME-Version: 1.0
Message-ID: <mex07fbe.1hqvcchgqwx16@localhost>
Received: from 192.168.250.164 by mailhog.example (MailHog)
          id [email protected]; Fri, 29 Aug 2025 15:44:53 +0000
Reply-To: [email protected]
Subject: Example multipart message
To: [email protected]

------=_Part_0_416639874.1756482293892
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Hello,
This is the plain text version of the email.

------=_Part_0_416639874.1756482293892
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: 7bit

<html>
  <body>
    <p>Hello,</p>
    <p>This is the <b>HTML</b> version of the email.</p>
    <p>Notice the non-breaking space:&nbsp; and © symbols.</p>
  </body>
</html>

------=_Part_0_416639874.1756482293892--

Please note that in the second part of the message, the Content-Transfer-Encoding was changed fro quoted-printable to 7bit. I think that the converter is just taking the first Content-Transfer-Encoding that it sees and applying it to every part that the message has.

Do you think there's a way that having different transfer encodings for each part can be supported?

mnmallea avatar Aug 29 '25 15:08 mnmallea