we are trying to encode NonBreaking-Space (0xC2 0xA0) and Euro-Sign (0xE2 0x82 0xAC)
with the Spring MimeMessageHelper setText
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/mail/javamail/MimeMessageHelper.html#setText-java.lang.String-java.lang.String-
and for the html-body we get the output =C2=A0?
, which is the correct space followed by the replacement-character '?'.
From: nix@foo.de
Reply-To: valid@foo.de
To: valid@foo.de
Message-ID: <935520971.3.1574258294133@hp-machine>
Subject: testing email
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_0_1089341986.1574258294045"
------=_Part_0_1089341986.1574258294045
Content-Type: multipart/related;
boundary="----=_Part_1_801142660.1574258294066"
------=_Part_1_801142660.1574258294066
Content-Type: multipart/alternative;
boundary="----=_Part_2_685219002.1574258294091"
------=_Part_2_685219002.1574258294091
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: base64
MjgsNDDCoOKCrA==
------=_Part_2_685219002.1574258294091
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
28,40=C2=A0?
------=_Part_2_685219002.1574258294091--
------=_Part_1_801142660.1574258294066--
------=_Part_0_1089341986.1574258294045--
Any idea why this might happen?
the behaviour was actually rooted in the javax.mail package doing some encoding-detection-voodoo and ultimately leading to that behaviour. if explicitly setting a utf-8 charset and thus avoiding auto-detection, the content gets even base64-encoded.
we did now put a workaround in place that explicitly encodes unicode-codepoints into html-entities for html-attachments. wenn all unicode-codepoints are encoded in such a way, javax.mail will treat the whole content as being us-ascii and does no special encoding at all.