[New-bugs-announce] [issue10921] imaplib: Internaldate2tuple crashes, does not handle negative TZ offsets, does not handle DST correctly, and outputs localtime (not UTC)
report at bugs.python.org
Mon Jan 17 00:32:36 CET 2011
New submission from Joe Peterson <joe at skyrush.com>:
Internaldate2tuple() is broken in several ways. The last two issues have existed in the code for some time.
New issues in Python 3:
1. It crashes with "KeyError". This is because the Mon2num dictionary's keys are strings, not bytes objects (note that other strings in imaplib have been updated, but not Mon2num).
2. The sign of the TZ offset (e.g. -0700) is compared to the string '-', not b'-', so the compare is never true, causing a large error when TZ offset is negative.
Left over from Python 2.x:
3. DST is not handled correctly. Specifically, when the date is such that its local time form and its UTC form (if both interpreted as local time) are on different sides of a DST changeover, the result will be off by one hour. This is because the check for DST is done after treating the time as local time, even if it is not local time, causing it be tested while sometimes on the wrong side of a DST change. This can be corrected by using calls that keep time in UTC.
4. Related to #3, the result is returned in local time, whereas the documentation states that the result is in UT. The fix for #3 takes care of this one, as well.
Here is an example: Run the following two dates, that represent exactly the same time, through Internaldate2tuple:
'25 (INTERNALDATE "01-Apr-2000 19:02:23 -0700")'
'101 (INTERNALDATE "02-Apr-2000 02:02:23 +0000")'
Once the Mon2num issue is fixed, Python 3 will perform the conversions, but with a 15 hour difference. Python 2 will produce results with a one hour difference.
Note that the last two issues (but describing only #4 above) were also addressed in a similar way in an old post I found by Colin Brown in 2004 (http://www.velocityreviews.com/forums/t336162-imaplib-function-bug.html).
components: Library (Lib)
title: imaplib: Internaldate2tuple crashes, does not handle negative TZ offsets, does not handle DST correctly, and outputs localtime (not UTC)
versions: Python 3.2
Added file: http://bugs.python.org/file20419/imaplib_Internaldate2tuple.patch
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce