bbottema/simple-java-mail

Improve encoding of attachment file names

fadeyev opened this issue · 5 comments

The org.simplejavamail.email.internal.EmailPopulatingBuilderImpl#withAttachment() methods contain call to MiscUtil.encodeText(text) which encode attachment names. If I want later to query attachments on my Email object, I'll see encoded messages, which are different from what was populated. It's not very convenient, I would expect this encoding to happen at a later stage, just before sending the email, keeping Java model clean and not overriding values I populated it with initially.

When parsing an msg file it also creates a problem, since resulting Email object won't have original file name at all - I have to decode it manually.

Morever, MimeUtility.encodeText() and MimeUtility.decodeText() do not work reliably on all platforms. I couldn't get to the bottom of it, but on my machine MimeUtility.encodeText(text) produces output which can't be parsed by MimeUtility.decodeText(text), although MimeUtility.encodeText(text, "UTF-8", "B") works well in all cases.

Good points all around. I take it you're not on a released version, since you're quoting 6.0.0 develop code?

Implemented enhancement for 6.0.0.

Released in 6.0.0-rc1.

6.0.0 has released as well, finally.

FYI, as per #271 and https://javaee.github.io/javamail/FAQ#encodefilename, I'm going to turn off encoding of filenames, but I will make sure the value it is tested for injection attacks.