|
|
|
@ -261,9 +261,28 @@ 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():
|
|
|
|
|
mr = MailRoom()
|
|
|
|
|