Skip to content

Commit

Permalink
utime_from_header: handle out-of-bounds dates
Browse files Browse the repository at this point in the history
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 <cs@zip.com.au>
Signed-off-by: Janna Martl <janna.martl109@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
  • Loading branch information
Janna Martl authored and nicolas33 committed Oct 12, 2015
1 parent e2f2ec1 commit ee0de28
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions offlineimap/folder/Maildir.py
Expand Up @@ -350,9 +350,19 @@ def savemessage(self, uid, content, flags, rtime):
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
Expand Down

0 comments on commit ee0de28

Please sign in to comment.