Better decode
This commit is contained in:
parent
3d7eeaefe7
commit
09cf022b6a
|
@ -4,6 +4,11 @@ import imaplib
|
||||||
import email.header
|
import email.header
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
def decode_mime_words(s):
|
||||||
|
return u''.join(
|
||||||
|
word.decode(encoding or 'utf8') if isinstance(word, bytes) else word
|
||||||
|
for word, encoding in email.header.decode_header(s))
|
||||||
|
|
||||||
def process_mailbox(mailbox, to = None):
|
def process_mailbox(mailbox, to = None):
|
||||||
rv, data = mailbox.search(None, "(UNSEEN)")
|
rv, data = mailbox.search(None, "(UNSEEN)")
|
||||||
if rv != 'OK':
|
if rv != 'OK':
|
||||||
|
@ -23,7 +28,7 @@ def process_mailbox(mailbox, to = None):
|
||||||
|
|
||||||
print('From:', msg['From'])
|
print('From:', msg['From'])
|
||||||
decode = email.header.decode_header(msg['Subject'])
|
decode = email.header.decode_header(msg['Subject'])
|
||||||
subject = ''.join(map(lambda x: x[0].decode(), decode))
|
subject = decode_mime_words(decode)
|
||||||
|
|
||||||
print('Subject: %s' % subject)
|
print('Subject: %s' % subject)
|
||||||
date_tuple = email.utils.parsedate_tz(msg['Date'])
|
date_tuple = email.utils.parsedate_tz(msg['Date'])
|
||||||
|
|
Loading…
Reference in New Issue