From ee0de28cc457b6983f1e75cf28748f5a16320ed9 Mon Sep 17 00:00:00 2001 From: Janna Martl Date: Sat, 29 Aug 2015 16:02:33 -0400 Subject: [PATCH] utime_from_header: handle out-of-bounds dates Handle case where email's internal time is erroneously so large as to cause overflow errors when setting file modification time with utime_from_header = true. Reported-by: Cameron Simpson Signed-off-by: Janna Martl Signed-off-by: Nicolas Sebrecht --- offlineimap/folder/Maildir.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/offlineimap/folder/Maildir.py b/offlineimap/folder/Maildir.py index 3f5c071..07d1b73 100644 --- a/offlineimap/folder/Maildir.py +++ b/offlineimap/folder/Maildir.py @@ -350,9 +350,19 @@ class MaildirFolder(BaseFolder): tmpname = self.save_to_tmp_file(messagename, content) if self.utime_from_header: - date = emailutil.get_message_date(content, 'Date') - if date != None: - os.utime(os.path.join(self.getfullname(), tmpname), (date, date)) + try: + date = emailutil.get_message_date(content, 'Date') + if date is not None: + os.utime(os.path.join(self.getfullname(), tmpname), + (date, date)) + # In case date is wrongly so far into the future as to be > max int32 + except Exception as e: + from email.Parser import Parser + from offlineimap.ui import getglobalui + datestr = Parser().parsestr(content, True).get("Date") + ui = getglobalui() + ui.warn("UID %d has invalid date %s: %s\n" + "Not changing file modification time" % (uid, datestr, e)) self.messagelist[uid] = self.msglist_item_initializer(uid) self.messagelist[uid]['flags'] = flags