On Thu, Aug 27, 2015 at 10:48:29PM +0200, Nicolas Sebrecht wrote:<br>
>On Thu, Aug 27, 2015 at 12:31:53PM -0700, Martin Carpella wrote:<br>
>> Issue is caused by utime_from_header = yes for the local repository and<br>
>> a SPAM message that is quite far in the future, exceeding int32 as<br>
>> timestamp.<br>
>><br>
>> The message's date header is:<br>
>> Date: Thu, 03 Sep 3610 21:32:03 +0300<br>
>><br>
>> Maybe a check should be added if the date is that far in the future and<br>
>> set to native C's long max-value (depending if i386 or amd64).<br>
><br>
>Aargh. This should be a rare case. I think it would be better to just<br>
>discard the offending mail and notice the user. Playing with data type<br>
>is annoying, code intrusive and prone to errors.<br>
><br>
>Patches welcome.<br>
<br>
OK, how about this:<br>
<br>
--------<br>
<br>
Handle out-of-bounds dates<br>
<br>
Handle case where email's internal time is erroneously so large as to<br>
cause overflow errors when setting file modification time with<br>
utime_from_header = true.<br>
<br>
Signed-off-by: Janna Martl <janna.martl109@gmail.com><br>
---<br>
offlineimap/folder/Maildir.py | 16 +++++++++++++---<br>
1 file changed, 13 insertions(+), 3 deletions(-)<br>
<br>
diff --git a/offlineimap/folder/Maildir.py b/offlineimap/folder/Maildir.py<br>
index 3f5c071..f969390 100644<br>
--- a/offlineimap/folder/Maildir.py<br>
+++ b/offlineimap/folder/Maildir.py<br>
@@ -350,9 +350,19 @@ class MaildirFolder(BaseFolder):<br>
tmpname = self.save_to_tmp_file(messagename, content)<br>
<br>
if self.utime_from_header:<br>
- date = emailutil.get_message_date(content, 'Date')<br>
- if date != None:<br>
- os.utime(os.path.join(self.getfullname(), tmpname), (date, date))<br>
+ try:<br>
+ date = emailutil.get_message_date(content, 'Date')<br>
+ if date != None:<br>
+ os.utime(os.path.join(self.getfullname(), tmpname),<br>
+ (date, date))<br>
+ # In case date is wrongly so far into the future as to be > max int32<br>
+ except:<br>
+ from email.Parser import Parser<br>
+ from offlineimap.ui import getglobalui<br>
+ datestr = Parser().parsestr(content, True).get("Date")<br>
+ ui = getglobalui()<br>
+ ui.warn("UID %d has invalid date %s; not changing file "\<br>
+ "modification time" % (uid, datestr))<br>
<br>
self.messagelist[uid] = self.msglist_item_initializer(uid)<br>
self.messagelist[uid]['flags'] = flags<br>
-- <br>
2.5.0<br>
<br>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br>Reply to this email directly or <a href="https://github.com/OfflineIMAP/offlineimap/issues/231#issuecomment-135922356">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AKFSECxQsPw2JUCyvjDIqvVk4PKClGbIks5osPaDgaJpZM4FzkWX.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
<link itemprop="url" href="https://github.com/OfflineIMAP/offlineimap/issues/231#issuecomment-135922356"></link>
<meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>