OfflineIMAP/offlineimap — pull request #7 by 15characterlimi (2012-10-01 11:25:50+00:00)
Title: Fix IMAP folder ignoring timezone when parsing email Date: header

Fix imapfolder.getmessageinternaldate misparsing the Date: header from emails due to a bug or surprising behaviour by email.utils.parsedate. This is because email.utils.parsedate's return value contains the unadjusted hour value from the string parsed but does not include information about the time zone in which it is specified. For example,

email.utils.parsedate("Mon, 20 Nov 1995 19:12:08 -0500")

yields (tested on Python 2.7.3):

(1995, 11, 20, 19, 12, 8, 0, 1, -1)

(the -1 is the isdst field). When passed too time.struct_time as allowed per the parsedate documentation, this time is interpreted in GMT and thus deviates from the correct value by the timezone offset (in this example, -5 hours).

I consider this a bug in email.utils.parsedate, or at least an anomaly; the existence of email.utils.parsedate_tz, to which I've switched, indicates that maybe the authors were aware of this behavior.