Thursday, April 24, 2008

Java Mail API with Encoded Attachment FileNames

This is very strange problem i faces as per me. May be because different email clients have different encodings or something else, but we will get encoded filename header from some email clients like lotus, blackberry phone etc.

Message header for attachment:
Content-Transfer-Encoding: base64
Content-Type: image/jpeg
Content-Disposition:attachment;
filename="=?Windows-1252?B?SU1HMDAwMTYuanBn?="
Then i was stucked with the thing that how to decode the filename.I have the filename only in subject line.But i can not trust that because say if 3 attachments are there, then there will be 3 filenames in subject in order.But we should not depend on the subject of the email.

javax.mail.internet.MimeUtility util class which helps to decode the encoded strings in message header values as below

Method:
javax.mail.internet.MimeUtility.decodeText(strValueToBeDecoded);
But most of the encodings with java 1.3.1 are not supported. At least 1.4.1 must be used.

via javaLibs Blog

0 Comments: