Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decoding UTF-8 email subject?

I have a string in this form: =?utf-8?B?zr...

And I want to get the name of the file in proper UTF-8 encoding. Is there a library method somewhere in maven central that will do this decoding for me, or will I need to test the pattern and decode base64 manually?

like image 936
Stefan Kendall Avatar asked Sep 27 '11 18:09

Stefan Kendall


2 Answers

MimeUtility.decodeText is working for me,

eg,

MimeUtility.decodeText("=?UTF-8?B?4K6q4K+N4K6q4K+K4K604K6/4K614K+BIQ==?=");
like image 138
mathi Avatar answered Sep 21 '22 21:09

mathi


In MIME terminology, those encoded chunks are called encoded-words. Check out javax.mail.internet.MimeUtility.decodeText in JavaMail. The decodeText method will decode all the encoded-words in a string.

You can grab it from maven with

 <groupId>javax.mail</groupId>
 <artifactId>mail</artifactId>
 <version>1.4.4</version>
like image 27
ataylor Avatar answered Sep 21 '22 21:09

ataylor