Closed glassfishrobot closed 7 years ago
@bshannon Commented Actually, whitespace is allowed. RFC 2045 references RFC 822, which says:
3.1.4. STRUCTURED FIELD BODIES
To aid in the creation and reading of structured fields, the
free insertion of linear-white-space (which permits folding
by inclusion of CRLFs) is allowed between lexical tokens.
...
JavaMail ignores whitespace when parsing these parameter lists. Perhaps the Spring MimeType class is not ignoring whitespace like it should? This doesn't look like a bug in JavaMail, but let me know if I missed something.
Outlook/Exchange can generate Mime messages with headers like this:
The folding is done within the parameters immediately after the "name=" and "filename=". This only happens with long filenames. Unfolding this lines with the current unfolding code of javax.mail.internet.MimeUtility results in a line with at least a space after the '='. This space violates the https://www.ietf.org/rfc/rfc2045.txt specification clause 5.1:
And this violation can cause problems, e.g. when parsing the line using Springs org.springframework.util.MimeType.MimeType.valueOf method.
For me it's clear the folding done by Outlook is strange and seems invalid compared to clause 2.2.3 in https://www.ietf.org/rfc/rfc5322.txt . But because Outlook/Exchange is a big player I guess it will be a good idea to take into account their folding strategy.
A simple solution can be to change in method unfold:
to:
For now I have the following workaround for content-type, but that's not ideal: