Question

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    
Was it helpful?

Solution

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().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top