-
Notifications
You must be signed in to change notification settings - Fork 4
/
MboxParser.py
23 lines (20 loc) · 865 Bytes
/
MboxParser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import mailbox
import time
#https://pymotw.com/2/mailbox/
from email.utils import parsedate_tz, mktime_tz
def parseMbox(locationName, beginTimeFrame = 0, endTimeFrame = int(time.time())):
mbox = mailbox.mbox(locationName)
listOfMails = []
for message in mbox:
try:
timestamp = mktime_tz(parsedate_tz(message['date']))
if int(timestamp) < endTimeFrame and int(timestamp) > beginTimeFrame:
#http://stackoverflow.com/questions/12160010/email-datetime-parsing-with-python
mailInfo = timestamp, 'Mbox', \
"From: " + str(message['from']) + ", " \
"To: " + str(message['to']) + ", " \
"Subject: " + str(message['subject'])
listOfMails.append(mailInfo)
except TypeError:
pass
return listOfMails