Javamail ISO-8859-1 formatting

ぃ、小莉子 提交于 2019-12-06 00:04:56

MIME headers are encoded as per RFC 2047, therefore you need to decode them first.

String decoded = MimeUtility.decodeText("Georg =?ISO-8859-1?Q?SP=E4the?=");

JDK import:

import javax.mail.internet.MimeUtility;

For Android:

import com.android.email.mail.internet;

See also Javadoc of MimeUtility

Each of the Address objects will be an InternetAddress, cast it to that and use the getAddress or getPersonal method depending on what you want.

For what it's worth: You can cast to InternetAddress and use toUnicodeString that will return the decoded mail in the form of "Georg Späthe" <georg.spaethe@example.com> if your input address was "Georg =?ISO-8859-1?Q?SP=E4the?=" <georg.spaethe@example.com>. ALso, as explained by Bill Shannon, you can call getPersonal and getAddress to get the decoded values, so there is no need to fiddle around with MimeUtility yourself.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!