From 09cf022b6ab27f95c796ca17ef6846140326d154 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Thu, 29 Nov 2018 11:54:54 +0100 Subject: [PATCH] Better decode --- awesome-wm-widgets/email-widget/read_unread_emails.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/awesome-wm-widgets/email-widget/read_unread_emails.py b/awesome-wm-widgets/email-widget/read_unread_emails.py index aa2acef..c9c5857 100755 --- a/awesome-wm-widgets/email-widget/read_unread_emails.py +++ b/awesome-wm-widgets/email-widget/read_unread_emails.py @@ -4,6 +4,11 @@ import imaplib import email.header 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): rv, data = mailbox.search(None, "(UNSEEN)") if rv != 'OK': @@ -23,7 +28,7 @@ def process_mailbox(mailbox, to = None): print('From:', msg['From']) 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) date_tuple = email.utils.parsedate_tz(msg['Date'])