]> code.delx.au - offlineimap/commitdiff
Additional date validity check
authorJohn Goerzen <jgoerzen@complete.org>
Wed, 1 Aug 2007 01:25:05 +0000 (02:25 +0100)
committerJohn Goerzen <jgoerzen@complete.org>
Wed, 1 Aug 2007 01:25:05 +0000 (02:25 +0100)
patch from Mike Gerber

Two times today I have found my offlineimap to have died with this same
situation. It appears as if certain types of messages (both spam in my
situation), cause offlineimap to choke. When it does it cannot proceed.
This means that when I run offlineimap, it pulls in messages from some
folders, then it hits the folder with the bad message and dies, leaving
undownloaded mail on the server. The only fix to this problem is to find
the problem message on the server and remove it by hand. This isn't such
a huge deal for me, since I run the server, but other people have to
come to me to ask me to delete these messages, and until I do they
cannot download their email.

I have captured the output by running script during one of these
incidents, this has been attached. Additionally, I have also attach the
problematic message.

The patch seems to work for me, might need some Python wizard and better
testing, though.

fixes deb#396443

offlineimap/folder/IMAP.py

index 26a12fd6a801faff58d4cdb53c4a78aff10df233..8772c122d353e41b65a2a121f2b79b8641ac901f 100644 (file)
@@ -213,6 +213,12 @@ class IMAPFolder(BaseFolder):
             try:
                 if datetuple[0] < 1981:
                     raise ValueError
+
+                # Check for invalid date
+                datetuple_check = time.localtime(time.mktime(datetuple))
+                if datetuple[:2] != datetuple_check[:2]:
+                    raise ValueError
+
                 # This could raise a value error if it's not a valid format.
                 date = imaplib.Time2Internaldate(datetuple) 
             except (ValueError, OverflowError):