IMAP提取编码 [英] IMAP Fetch Encoding

查看:509
本文介绍了IMAP提取编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用imap从gmail中获取一些电子邮件信息,例如

I'm trying to fetch some email info from gmail using imap like this

"(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

被表示为

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

如何告诉Gmail返回带有我选择的编码的字符串,例如我想要Charset

How do I tell Gmail to return the strings with an encoding of my choice, say I want Charset to be UTF-8.

推荐答案

如何调整上述IMAP命令?

解决方案

好的。我发现email.utils可以帮助很多在这里。

Okay. I found out that email.utils can help out a lot here.

它有方法来解析日期,电子邮件和任何其他信息从imap消息。

It has methods to parse date, emails, and any other information from imap messages.

它还有解码imap字符串的方法。像这样

It also has methods to decode imap strings. Like this

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

这篇关于IMAP提取编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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