0

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    
Jurudocs
  • 8,595
  • 19
  • 64
  • 88

1 Answers1

3

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

patrys
  • 2,729
  • 17
  • 27
  • Thanx. Your hint was good. i can decode it with import quopri b = '=C3=96sterreich' s = b.decode('quopri').decode('utf-8') print s – Jurudocs Sep 27 '11 at 11:48