massage unread message data to be serializable dict

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

@ -261,8 +261,27 @@ class MailRoom(Bureau):
"""
messages = self.imapserv.sort("ARRIVAL", ["UNSEEN"])
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'])
# 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():

Loading…
Cancel
Save