Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MimeMessageHelper.addAttachment: configurable encoding of attachment filename #25755

Closed
achimbitzer opened this issue Sep 11, 2020 · 2 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@achimbitzer
Copy link

achimbitzer commented Sep 11, 2020

Affects: \5.2.8.RELEASE


I've encountered the following issue in org.springframework.mail.javamail.MimeMessageHelper#addAttachment(java.lang.String, javax.activation.DataSource):

The attachment filename ist added to the MimeBodyPart after calling MimeUtility.encodeText():
mimeBodyPart.setFileName(MimeUtility.encodeText(attachmentFilename));

For longer filenames with non-ASCII characters like german umlauts, this results in a wrong encoding of the filename.

Example: Filename is:
xxxxxxxxxxxxxxxxx xxxxxäxßxxxxx xxxxxxx.pdf

This get's encoded as:

Content-Type: application/pdf;
name*0="=?UTF-8?Q?xxxxxxxxxxxxxxxxx=5Fxxxxx=C3=A4u=C3=9Fxxxxx=5Fxxx";
name*1="xxxx.pdf?="
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename*0="=?UTF-8?Q?xxxxxxxxxxxxxxxxxx=5Fxxxxx=C3=A4x=C3=9Fxxxxx=5Fxxx";
filename*1="xxxx.pdf?="

Please note:

  • The encoded filename starts with =?UTF-8?Q?, which implies encoding according to RFC-1342
  • The encoded filename is splitted into two lines, indicated by the parameter name suffiexes *0 and *1. This implies encoding accroding to RFC-2231.

This mix of encodings is invalid and it leads to a faulty display of attachment filenames in mailclients, most prominently perhaps Microsoft Outlook.
Please refer to the javamail FAQ for more details: https://javaee.github.io/javamail/FAQ#encodefilename

Would it be possible to remove the call to MimeUtility.encodeText from this method or make it optional?

(edit: fixed typos)

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 11, 2020
@jhoeller jhoeller self-assigned this Sep 11, 2020
@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 11, 2020
@jhoeller jhoeller added this to the 5.2.9 milestone Sep 11, 2020
@jhoeller jhoeller changed the title MimeMessageHelper.addAttachment(...): faulty encoding of attachment filename MimeMessageHelper.addAttachment: configurable encoding of attachment filename Sep 11, 2020
@jhoeller
Copy link
Contributor

Good point, this is rather outdated. I'm introducing a setEncodeFilenames(boolean) method on MimeMessageHelper for 5.2.9, making this configurable but leaving the current default behavior as true... and considering a default change to false in 5.3.

@achimbitzer
Copy link
Author

Thank you for your quick reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants