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'])