massage unread message data to be serializable dict

workspace
Brendan Howell 8 years ago
parent 0288f6976a
commit 487994b633

@ -261,9 +261,28 @@ class MailRoom(Bureau):
""" """
messages = self.imapserv.sort("ARRIVAL", ["UNSEEN"]) messages = self.imapserv.sort("ARRIVAL", ["UNSEEN"])
print("%d unread messages in INBOX" % len(messages)) print("%d unread messages in INBOX" % len(messages))
return self.imapserv.fetch(messages, ['FLAGS', 'INTERNALDATE', resp = self.imapserv.fetch(messages, ['FLAGS', 'INTERNALDATE',
'ENVELOPE', 'RFC822.SIZE']) 'ENVELOPE', 'RFC822.SIZE'])
# massage into a serializable dict
msgs = []
for msgid, data in resp.items():
msg = {}
env = data["ENVELOPE"]
msg["msgid"] = str(msgid)
sender = env.from_[0]
msg["fromaddr"] = sender.mailbox + "@" + sender.host
msg["fromname"] = sender.name
msg["date"] = data["INTERNALDATE"]
msg["size"] = data["RFC822.SIZE"]
msg["subject"] = env.subject
msgs.append(msg)
return msgs
def main(): def main():
mr = MailRoom() mr = MailRoom()

Loading…
Cancel
Save