Python IMAP: =?utf-8?Q? in subject string(Python IMAP: =?utf-8?Q?在主题字符串中)
问题描述
我正在显示带有 IMAP
的新电子邮件,一切看起来都很好,除了一个邮件主题显示为:
I am displaying new email with IMAP
, and everything looks fine, except for one message subject shows as:
=?utf-8?Q?Subject?=
我该如何解决?
推荐答案
在 MIME 术语中,那些编码的块称为编码词.您可以像这样解码它们:
In MIME terminology, those encoded chunks are called encoded-words. You can decode them like this:
import email.Header
text, encoding = email.Header.decode_header('=?utf-8?Q?Subject?=')[0]
查看 email.Header
的文档了解更多详情.
Check out the docs for email.Header
for more details.
这篇关于Python IMAP: =?utf-8?Q?在主题字符串中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!