Crashing on invalid dates
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Backup Gmail |
New
|
Undecided
|
Unassigned |
Bug Description
Excellent backup solution, works very well. One issue I found is that in the processMail function, if the date is wrongly formatted, it fails (for some reason some of my messages had -1:-1:-1 +0000 as the time, however the date part was fine).
However, as it only requires the date part to generate the folder name I did a quick work around where the time is replaced with a valid time if it fails, code attached with change start/end marked with comments:
def processMail(self, rfc, seen, label):
mail = email.message_
#CHANGE START---
datestring = mail.get('date')
date = email.utils.
try:
fold = time.strftime(
except:
datestring = datestring[:16] + ' 01:01:01 +0000'
date = email.utils.
fold = time.strftime(
#CHANGE END---
h = hashlib.
mid = mail.get(
if mid == None:
mid = "<%<email address hidden>>" % (h, )
mail.
rfc = mail.as_string()
mail = email.message_
try:
os.mkdir("%s/%s" % (self.dest, fold))
except OSError as e:
pass
with open("%s/%s/%s" % (self.dest, fold, h), 'w') as f:
f.write(rfc)
if mid not in self.mails:
self.mails[mid] = MailMetaData(mid, h, fold)
self.
self.
self.
As you say, given that only the month and year are needed for the folder, an even simpler workaround is to avoid strftime and use the email date directly.
Replace this line:
fold = time.strftime( "%Y-%m" , date)
with this:
fold = "%04d-%02d" % (date[0], date[1])