Python支持一个相当实用的MIME-Library叫做email.mime
。
我想要实现的是将包含纯文本UTF-8的MIME部件编码为引用打印而不是base64。虽然该库中所有功能都可用,但我未能使用它:
示例:
import email.mime.text, email.encoders
m=email.mime.text.MIMEText(u'This is the text containing ünicöde', _charset='utf-8')
m.as_string()
# => Leads to a base64-encoded message, as base64 is the default.
email.encoders.encode_quopri(m)
m.as_string()
# => Leads to a strange message
最后一个命令会输出一个奇怪的信息:
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Transfer-Encoding: quoted-printable
GhpcyBpcyB0aGUgdGV4dCBjb250YWluaW5nIMO8bmljw7ZkZQ=3D=3D
很明显这不是被编码为可引用打印字符,双重transfer-encoding
头在最后很奇怪(如果不是非法的话)。
我该怎么才能让我的文本在mime-message中被编码为可引用打印字符呢?