2

I have a self written Java mail client, that reads messages from mail server.

I did not have any problem with it, but recently I found an exception, when this client tried to read one complicated email message. The stack trace says, that encoding 'quoted/printable' is unknown, and probably this information is enough to find the solution.

Anyway, I'll complete the question and put the log here:

java.io.IOException: Unknown encoding: quoted/printable
at javax.mail.internet.MimePartDataSource.getInputStream(MimePartDataSource.java:113)
at com.sun.mail.handlers.text_plain.getContent(text_plain.java:107)
at javax.activation.DataSourceDataContentHandler.getContent(DataHandler.java:790)
at javax.activation.DataHandler.getContent(DataHandler.java:537)
at javax.mail.internet.MimeBodyPart.getContent(MimeBodyPart.java:644)

Here's message part, containing this encoding information

--=_374450e655545f2af979375837b3e516
Content-Transfer-Encoding: quoted/printable
Content-Type: text/plain; charset=utf-8

Rest of information is some thml-formatted text.

So, is there a way to solve the problem without changing the javax.mail provider/version ? Now I'm using

 group: 'com.sun.mail', name: 'javax.mail', version: '1.5.1'

Or maybe I just misunderstood the problem and I should solve it another way?

4

1 回答 1

2

无论创建该邮件的邮件是什么,都已损坏。请将该问题报告给该邮件的所有者。正确的名称是“quoted-printable”,而不是“quoted/printable”。

大多数情况下,此类错误是业余爱好者编写垃圾邮件而没有先阅读 RFC 的结果。

您可以将系统属性“mail.mime.ignoreunknownencoding”设置为“true”,让 JavaMail 简单地忽略错误而不尝试解码数据。也可以捕获异常,使用getEncoding方法获取header的值,尝试猜测发送者心里想的是什么,然后使用getRawInputStream方法自己解码数据。

于 2014-10-21T18:38:50.073 回答