[PATCH] Handle out-of-bounds dates

Name Removed unknown at example.com
Sat Aug 29 21:02:33 BST 2015


On Sat, Aug 29, 2015 at 11:24:57AM +0200, Nicolas Sebrecht wrote:
>On Sat, Aug 29, 2015 at 12:48:20AM -0700, OfflineIMAP mailing list wrote:
>
>> >+ date = emailutil.get_message_date(content, 'Date')
>> >+ if date != None:
>
>>    Please, use "is not".
>>

OK

>> >+ except:
>> Please warn about the exception and the date causing it.

Not sure what you want... I already put the offending date in the
ui.warn() line, but I guess I could put the actual exception message
there too.

------------------8<------------------------

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.

Signed-off-by: Janna Martl <janna.martl109 at gmail.com>
---
 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
-- 
2.5.0




More information about the OfflineIMAP-project mailing list