imaplib 获取格式出现问题:RFC822 unequel utf8?
我想阅读 utf8 格式的电子邮件消息。这不适用于以下代码:我想我必须采用不同的格式,但是哪种格式以及如何格式?输出给出了某物。就像“=C3=96sterreich”代表“Österreich”。到目前为止我有这个...谢谢
import imaplib
import email
imap4 = imaplib.IMAP4(SERVER)
imap4.login(USER, PASSWORD)
imap4.select()
typ, data = imap4.search(None,'(UNSEEN SUBJECT "%s")' % subject)
for num in data[0].split():
typ, data = imap4.fetch(num,'(RFC822)')
msg = email.message_from_string(data[0][1])
typ, data = imap4.store(num,'-FLAGS','\\Seen')
print msg
I want to read an email messege which is in utf8 format. And this is not working with the following code: I guess i have to take a different format, but which and how? The output gives sth. like "=C3=96sterreich" for "Österreich". So far I have this...Thanx
import imaplib
import email
imap4 = imaplib.IMAP4(SERVER)
imap4.login(USER, PASSWORD)
imap4.select()
typ, data = imap4.search(None,'(UNSEEN SUBJECT "%s")' % subject)
for num in data[0].split():
typ, data = imap4.fetch(num,'(RFC822)')
msg = email.message_from_string(data[0][1])
typ, data = imap4.store(num,'-FLAGS','\\Seen')
print msg
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MIME 容器中的数据通常使用“quoted-printable”编解码器进行编码。我不知道 imaplib 的内部结构,但我相信您正在寻找的是
quopri.decodestring()
。Data in MIME containers is usually encoded using “quoted-printable” codec. I don't know the internals of
imaplib
but I believe what you're looking for isquopri.decodestring()
.