Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: JavaMail file attachment in non-latin not displayed properly

theyuv:

I am using Javamail (version 1.5) in a web application.

Users Upload Files via an file input element on an html form.

I then send the file via email. I use the same name as the file that was attached via the form (ie: I don't give it some custom name).

Some users upload files with non-latin file names.

According to docs I understand that no special encoding/decoding is needed with JavaMail unless I'm manipulating raw headers. Therefore I set the file name of the Attachment via mimeBodyPart.setFileName(fileName) without encoding the file name.

However, this results in the file name showing up as question marks or underscores in the received email. Testing printing fileName to the console or to a System folder displays the file name correctly.

Things I've tried

  1. I tried setting "mail.mime.encodefilename", and "mail.mime.decodefilename" to true in the app's ServletContextListener.

  2. I tried using the MimeUtility method encodeText(text,charset, encoding).

This worked and displayed the file name correctly but occasionally it would completely garble the file name: rather than question marks or underscores, it would garble the entire file name to look something like "=_UTF-8_B_16rXqNeS15XXnSDXnNeg15zXlCAt157XmdeV157XoNeV16og15___ ___filename_1=__4..."

I did extensive testing to try to figure out what caused this garbling but couldn't get consistent results (tested for browsers and file name length). I suspect something was getting cached during testing because the results weren't consistent.

  1. I tried getting the file name both from the Java Part method getSubmittedFileName() and via a js script.

Any suggestions?

Sample headers:

Content-Type: application/x-any; name="=?UTF-8?B?16TXlCDXoteV15Mg157Xmdec15nXnSDXnA==?= =?UTF-8?B?1\"; name*1=\"5DXqNeV15og157Xodek16guZG9jeA==?=" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="=?UTF-8?B?16TXlCDXoteV15Mg157Xmdec15nXnSDXnA==?= =?UTF-8?B?1\"; filename*1=\"5DXqNeV15og157Xodek16guZG9jeA==?="

Clients used to view received emails: Gmail website, Microsoft Outlook.



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: JavaMail file attachment in non-latin not displayed properly

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×