简体   繁体   English

使用Imap - Mail编码怪异

[英]Using Imap - Mail encoding weirdness

I'm using imap to retrieve mails from a server which works fine. 我正在使用imap从服务器检索邮件,工作正常。 I'm fetching the mails in RFC 822 like so: 我正在读取RFC 822中的邮件,如下所示:

r, data = mailserver.fetch(mailnr, '(RFC822)')

This gives me decipherable mails for the most part but now I have a multipart mail that looks like this: 这给了我大部分可辨认的邮件,但现在我有一个如下所示的多部分邮件:

From : xxx xxx 来自:xxx xxx

To : xxx xxx 收件人:xxx xxx

Subject : =?utf-8?Q?online_verf=C3=BCgbar_-_TESTQUELLE_f=C3=BCr_Regel?= =?utf-8?Q?-_u_Benachrichtigungdienst_()?= 主题:=?utf-8?Q?online_verf = C3 = BCgbar _-_ TESTQUELLE_f = C3 = BCr_Regel?= =?utf-8?Q?-_ u_Benachrichtigungdienst _()?=

Content-Type : multipart/alternative; 内容类型:multipart / alternative; boundary="----=_NextPart_457512452482695058637" 边界= “---- = _ NextPart_457512452482695058637”

Content-Transfer-Encoding : None 内容传输编码:无

MIME-Version : 1.0 MIME版本:1.0

Payload: 有效载荷:

=20 =20 sourcename:TESTQUELLE f=C3=BCr Regel- u Benachrichtigungdienst;csi:123456= ;publishdate:05=2E11=2E2013 = 20 = 20 sourcename:TESTQUELLE f = C3 = BCr Regel- u Benachrichtigungdienst; csi:123456 =; publishdate:05 = 2E11 = 2E2013

The mail appears to be utf-8 but somehow the text is also url-encoded or something like that. 邮件似乎是utf-8但不知何故文本也是网址编码或类似的东西。

It seem like url encoded only instead of "%" "=" is used. 它似乎只编码url而不是“%”“=”。

Any ideas on how i get this to look like normal text ? 关于我如何让它看起来像普通文本的任何想法?

The data appears to be unicode text that has been encoded as UTF-8, and then encoded as quotable-printable. 数据似乎是已编码为UTF-8的unicode文本,然后编码为quotable-printable。 There is a module " quopri " to encode / decode this - http://docs.python.org/3.3/library/quopri.html . 有一个模块“ quopri ”来编码/解码这个 - http://docs.python.org/3.3/library/quopri.html

If you use quopri.decodestring to decode to UTF-8, and then decode that to unicode, yuo should be able to read it. 如果你使用quopri.decodestring解码为UTF-8,然后将其解码为unicode,yuo应该能够读取它。

Finally found this: 终于找到了这个:

mail.get_payload(decode=1).decode('utf-8')

I've only used get_payload() which gave me that string. 我只使用了给我字符串的get_payload()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM