Python IMAP:= ? utf - 8问?在主题字符串

时间:2023-01-05 23:12:45

I am displaying new email with IMAP, and everything looks fine, except for one message subject shows as:

我正在用IMAP显示新邮件,除了一个邮件主题显示为:

=?utf-8?Q?Subject?=

utf - 8 = ?问主题? =

How can I fix it?

我怎样才能修好它呢?

2 个解决方案

#1


23  

In MIME terminology, those encoded chunks are called encoded-words. You can decode them like this:

在MIME术语中,这些被编码的块被称为encoded-words。你可以这样解码:

import email.Header
text, encoding = email.Header.decode_header('=?utf-8?Q?Subject?=')[0]

Check out the docs for email.Header for more details.

查看文档以获取电子邮件。头为更多的细节。

#2


4  

This is a MIME encoded-word. You can parse it with email.header:

这是一个MIME编码的词。你可以用email.header:

import email.header

def decode_mime_words(s):
    return u''.join(
        word.decode(encoding or 'utf8') if isinstance(word, bytes) else word
        for word, encoding in email.header.decode_header(s))

print(decode_mime_words(u'=?utf-8?Q?Subject=c3=a4?=X=?utf-8?Q?=c3=bc?='))

#1


23  

In MIME terminology, those encoded chunks are called encoded-words. You can decode them like this:

在MIME术语中,这些被编码的块被称为encoded-words。你可以这样解码:

import email.Header
text, encoding = email.Header.decode_header('=?utf-8?Q?Subject?=')[0]

Check out the docs for email.Header for more details.

查看文档以获取电子邮件。头为更多的细节。

#2


4  

This is a MIME encoded-word. You can parse it with email.header:

这是一个MIME编码的词。你可以用email.header:

import email.header

def decode_mime_words(s):
    return u''.join(
        word.decode(encoding or 'utf8') if isinstance(word, bytes) else word
        for word, encoding in email.header.decode_header(s))

print(decode_mime_words(u'=?utf-8?Q?Subject=c3=a4?=X=?utf-8?Q?=c3=bc?='))