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 <cs@zip.com.au> Signed-off-by: Janna Martl <janna.martl109@gmail.com> Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
e2f2ec16a5
commit
ee0de28cc4
@ -350,9 +350,19 @@ class MaildirFolder(BaseFolder):
|
|||||||
tmpname = self.save_to_tmp_file(messagename, content)
|
tmpname = self.save_to_tmp_file(messagename, content)
|
||||||
|
|
||||||
if self.utime_from_header:
|
if self.utime_from_header:
|
||||||
|
try:
|
||||||
date = emailutil.get_message_date(content, 'Date')
|
date = emailutil.get_message_date(content, 'Date')
|
||||||
if date != None:
|
if date is not None:
|
||||||
os.utime(os.path.join(self.getfullname(), tmpname), (date, date))
|
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] = self.msglist_item_initializer(uid)
|
||||||
self.messagelist[uid]['flags'] = flags
|
self.messagelist[uid]['flags'] = flags
|
||||||
|
Loading…
Reference in New Issue
Block a user