tags:

views:

31

answers:

1

Recently i have follow the Sun online guide on Java Mail API to send email, download email and download attachment. When comes to extracting attachment from an email, my code looks very similar to this post http://stackoverflow.com/questions/1748183/download-attachments-using-java-mail

However, i encounter a problem when the user send the email attachment file name with vietnamese character, something like this: hệ thống thông.xls

When the code tries to get the filename with: bodyPart.getFileName() , the return file name is like this: h? th?ng =?iso-8859-1?b?dGj0bmcueGxz?=

I have try the following but without any luck

1) set Java VM parameter: -Dfile.encoding=UTF-8

2) try to look further into the Java Mail API on UTF-8 Character support, but cant find any

Any hint will help. Thank you!

+1  A: 

ISO-8859-1 is the Latin-1 character set. It only includes Western European characters. So that might be a hint. Maybe the problem is with the client that's sending the attachment? Take a look at the raw source for the message, check if any of the headers say anything about the text encoding.

Mike Baranczak
Is there any way to set the JavaMail BodyPart to recognize UTF-8?
Reusable
If the message is properly encoded in UTF-8, then JavaMail should handle it automatically. My point was, maybe the message isn't actually getting encoded in UTF-8.
Mike Baranczak
I see... The email client that i see from one of the headers show that it is not a common email client. When i try to attach the same file with outlook email client, the program can get the filename correctly. Thank you!
Reusable