java - MimeMessage 内容传输编码问题

标签 java character-encoding jakarta-mail

大家好... 我希望有人能给我一些关于我遇到的问题的线索。

阅读 MimeMessage 的 getInputStream() 的 Javadoc,它说“返回此消息内容的已解码输入流” 然而,这不是我所经历的。输出未解码。例如,如果我有一条消息,则如下

Date: Wed, 24 Feb 2010 11:29:13 +1100
From: xxxxxxxxx
To: xxxxxxxxxxxx
Message-ID: <4B8472D9.5050901@xxxxxxxxx>
Subject: xxxxxxxxxxxxxxxxxx
MIME-Version: 1.0
Content-Type: multipart/mixed;
 boundary="------------000801030004000206000901"
Content-Transfer-Encoding: quoted-printable
Organization: xxxxxxxxxxxxxxxxxx
User-Agent: Thunderbird 2.0.0.23 (Windows/20090812)

This is a multi-part message in MIME format.
--------------000801030004000206000901
Content-Type: text/plain; charset=3DISO-8859-1; format=3Dflowed
Content-Transfer-Encoding: 7bit

!

--------------000801030004000206000901
Content-Type: text/plain;
 name=3D"bla.bla"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline;
filename=3D"bla.bla"

 my.username =3D holly
my.host =3D molly
--------------000801030004000206000901--

然后,假设我有一个用上述内容构造的名为“m”的对象,然后调用 m.getInputStream() 并将输出转储到屏幕上显示那些“=3D”字符集。 我做错了什么?

如果我使用 QPDecoderStream 来解码 m.getInputStream() 的输出,那么结果当然是正确的。然而,它达不到目的,因为 Javadoc 说 getInputStream() 返回一个已解码的输入流。

最佳答案

此处的问题是消息格式错误。 You're not allowed to set Content-Transfer-Encoding to quoted-printable on a multipart part :

If a Content-Transfer-Encoding header field appears as part of a message header, it applies to the entire body of that message. If a Content-Transfer-Encoding header field appears as part of an entity's headers, it applies only to the body of that entity. If an entity is of type "multipart" the Content-Transfer-Encoding is not permitted to have any value other than "7bit", "8bit" or "binary".

您可能可以获取顶级 MimeMessage 的解码内容流并从中实例化 MimeMultipart,但这只是解决了损坏消息的基本问题.

关于java - MimeMessage 内容传输编码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5493735/

相关文章:

java - 无法序列化包含 orientdb 记录 ID 的映射

javascript - 将 emoji javascript unicode 代码转换为 utf-8

源码出现奇怪字符导致编译失败

java - 读取带有附件文件的消息时缺少起始边界异常

java - 使用 Java 在电子邮件正文中发送图像

android - 此类文件的 Jar 属于容器 'Android Dependencies',该容器不允许修改其条目上的源附件

java - appengine 动态实例的问题

java - Spring 数据 Cassandra @Indexed 注解

java - 从 php 调用 java

visual-studio-2010 - 尽管字符集正确,德语元音仍显示错误