Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javamail ISO-8859-1 formatting

I made an E- Mail Client for my Android phone with the Javamail Api. If I try to get the sender's mail address and the recipients mail address with 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 back:

"Georg =?ISO-8859-1?Q?SP=E4the?= and it has to be Georg Späthe or Georg Spaethe.

I think the Problem is that this are German Mails with another encoding. Can anybody help me to solve that problem?

like image 849
jwandscheer Avatar asked Sep 16 '25 01:09

jwandscheer


1 Answers

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

like image 138
stacker Avatar answered Sep 17 '25 17:09

stacker