javax.mail.internet.MimeUtility.decodeWord()
On the other hand, if you use JavaMail to decode your emails, you don’t have to worry about parsing the subject at all, nor about the syntax of the MIME body (attachment).
By the way, it doesn’t have to be Base64 (usually with Apple clients), it can also be Quoted-Printable (usually with MS Outlook client).
Thunderbird uses a format that is shorter (Base64 for Japanese, QP for most European languages).
If you really want to implement it yourself, look at RFC2047 and RFC2184 (you need to have a few subtleties, such as split coding in two different character sets or merging adjacent coded words, separated by just dropping the space)
source share