Fixed bug

This commit is contained in:
Thomas Forgione 2018-11-30 10:43:25 +01:00
parent bc09145408
commit 6a12e2bb9d
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
1 changed files with 4 additions and 4 deletions

View File

@ -5,7 +5,7 @@ import email.header
import datetime import datetime
def decode_mime_words(s): def decode_mime_words(s):
return u''.join( return ''.join(
word.decode(encoding or 'utf8') if isinstance(word, bytes) else word word.decode(encoding or 'utf8') if isinstance(word, bytes) else word
for word, encoding in email.header.decode_header(s)) for word, encoding in email.header.decode_header(s))
@ -27,14 +27,14 @@ def process_mailbox(mailbox, to = None):
print('To: ', to) print('To: ', to)
print('From:', msg['From']) print('From:', msg['From'])
decode = email.header.decode_header(msg['Subject']) subject = decode_mime_words(msg['Subject'])
subject = decode_mime_words(decode)
print('Subject: %s' % subject) print('Subject: %s' % decode_mime_words(msg['Subject']))
date_tuple = email.utils.parsedate_tz(msg['Date']) date_tuple = email.utils.parsedate_tz(msg['Date'])
if date_tuple: if date_tuple:
local_date = datetime.datetime.fromtimestamp(email.utils.mktime_tz(date_tuple)) local_date = datetime.datetime.fromtimestamp(email.utils.mktime_tz(date_tuple))
print("Local Date:", local_date.strftime("%a, %d %b %Y %H:%M:%S")) print("Local Date:", local_date.strftime("%a, %d %b %Y %H:%M:%S"))
print()
# with code below you can process text of email # with code below you can process text of email
# if msg.is_multipart(): # if msg.is_multipart():
# for payload in msg.get_payload(): # for payload in msg.get_payload():