开发者

java Mail API receiving email attachment with vietnamese characters

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 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. T开发者_开发技巧hank you!


You can use MimeUtility.decodeWord(bodyPart.getFileName()) to get the actual name of the file.

Since mail headers can only contain ASCII characters, RFC 2047 describes how to encode other character sets and this method decodes the name as specified in RFC 2047.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜