Trouble with imaplib fetch formats: RFC822 unequel utf8?
I want to read an email messe开发者_如何学运维ge 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
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 is quopri.decodestring()
.
精彩评论