JavaMail iso-8859-1 formatting
•
Java
I made an email client for my Android phone using JavaMail API If I try to get the sender's email address and the recipient's email address using the following methods:
Address[] froma = m.getFrom(); String from = InternetAddress.toString(froma); Address[] toa = m.getRecipients(Message.RecipientType.TO); String to = InternetAddress.toString(toa);
I get a string like this:
"Georg =? Iso-8859-1? Q? SP = e4the? = it must be georgsp ä the or Georg spaethe
I think the problem is that this is German mail with another code Can someone help me solve this problem?
Solution
Mime headers are encoded according to RFC 2047, so 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
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码