Javamail ISO-8859-1格式化 [英] Javamail ISO-8859-1 formatting

查看:133
本文介绍了Javamail ISO-8859-1格式化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Javamail Api为我的Android手机制作了一个电子邮件客户端。如果我尝试通过以下方法获取发件人的邮件地址和收件人邮件地址:

 地址[] froma = m。从获得(); 
String from = InternetAddress.toString(froma);

地址[] toa = m.getRecipients(Message.RecipientType.TO);
String to = InternetAddress.toString(toa);

我得到一个这样的字符串:



Georg =?ISO-8859-1?Q?SP = E4the?=
,它必须是GeorgSpäthe或Georg Spaethe。



I认为问题是这是德语邮件的另一个编码,有人可以帮我解决这个问题吗?

解决方案

根据 RFC 2047 编码,因此您需要先解码它们。

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

JDK导入:

  import javax.mail.internet.MimeUtility; 

对于Android:

  import com.android.email.mail.internet; 

另请参阅 MimeUtili的Javadoc ty


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?

解决方案

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

这篇关于Javamail ISO-8859-1格式化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆