summaryrefslogtreecommitdiff
path: root/email-widget
diff options
context:
space:
mode:
authorstreetturtle <streetturtle@users.noreply.github.com>2020-03-04 16:51:10 -0500
committerGitHub <noreply@github.com>2020-03-04 16:51:10 -0500
commitd2bbf765faffdb5628edbae3b169f3f6fcdad356 (patch)
treeb8f4a3adec0702c5dcee7e5a00ab2cbb011feea4 /email-widget
parent95f1e25c03ebf0223252f62bdb4505764148508f (diff)
parent69825ad2381276cb179c9c7c0630ead9b536cfb6 (diff)
Merge pull request #119 from brestows/patch-1
fix for python 3
Diffstat (limited to 'email-widget')
-rw-r--r--email-widget/read_unread_emails.py34
1 files changed, 18 insertions, 16 deletions
diff --git a/email-widget/read_unread_emails.py b/email-widget/read_unread_emails.py
index 343fe66..607bdcc 100644
--- a/email-widget/read_unread_emails.py
+++ b/email-widget/read_unread_emails.py
@@ -15,21 +15,23 @@ def process_mailbox(M):
if rv != 'OK':
print "ERROR getting message", num
return
-
- msg = email.message_from_string(data[0][1])
- print 'From:', msg['From']
- print 'Subject: %s' % (msg['Subject'])
- date_tuple = email.utils.parsedate_tz(msg['Date'])
- if 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")
- # with code below you can process text of email
- # if msg.is_multipart():
- # for payload in msg.get_payload():
- # if payload.get_content_maintype() == 'text':
- # print payload.get_payload()
- # else:
- # print msg.get_payload()
+ msg = email.message_from_bytes(data[0][1])
+ for header in [ 'From', 'Subject', 'Date' ]:
+ hdr = email.header.make_header(email.header.decode_header(msg[header]))
+ if header == 'Date':
+ date_tuple = email.utils.parsedate_tz(str(hdr))
+ if date_tuple:
+ local_date = datetime.datetime.fromtimestamp(email.utils.mktime_tz(date_tuple))
+ print("{}: {}".format(header, local_date.strftime("%a, %d %b %Y %H:%M:%S")))
+ else:
+ print('{}: {}'.format(header, hdr)
+ # with code below you can process text of email
+ # if msg.is_multipart():
+ # for payload in msg.get_payload():
+ # if payload.get_content_maintype() == 'text':
+ # print payload.get_payload()
+ # else:
+ # print msg.get_payload()
M=imaplib.IMAP4_SSL("mail.teenagemutantninjaturtles.com", 993)
@@ -39,4 +41,4 @@ rv, data = M.select("INBOX")
if rv == 'OK':
process_mailbox(M)
M.close()
-M.logout() \ No newline at end of file
+M.logout()