简体   繁体   English

IMAP提取编码

[英]IMAP Fetch Encoding

I'm trying to fetch some email info from gmail using imap like this 我正在尝试使用imap这样从gmail获取一些电子邮件信息

"(BODY.PEEK[HEADER.FIELDS (subject from date)] X-GM-MSGID X-GM-LABELS X-GM-THRID)"

The problem is that it doesn't work well with special and accented characters. 问题在于,它不能与特殊字符和重音字符配合使用。 For example, 例如,

Stéphane Maniaci

is rendered as 呈现为

=?ISO-8859-1?Q?St=E9phane_Maniaci?=

How do I tell Gmail to return the strings with an encoding of my choice, say I want Charset to be UTF-8. 我如何告诉Gmail以我选择的编码返回字符串,比如说我希望Charset为UTF-8。

How to adjust that in the IMAP command I mentioned above? 如何在上述IMAP命令中进行调整?

Okay. 好的。 I found out that email.utils can help out a lot here. 我发现email.utils在这里可以提供很多帮助。

It has methods to parse date, emails, and any other information from imap messages. 它具有解析日期,电子邮件和imap消息中任何其他信息的方法。

It also has methods to decode imap strings. 它还具有解码imap字符串的方法。 Like this 像这样

from email.header import decode_header
value, charset = decode_header(string_to_be_decoded)

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

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