[issue10921] imaplib: Internaldate2tuple crashes, does not handle negative TZ offsets, does not handle DST correctly, and outputs localtime (not UTC)

Joe Peterson 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)
files: imaplib_Internaldate2tuple.patch
keywords: patch
messages: 126386
nosy: lavajoe
priority: normal
severity: normal
status: open
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>
<http://bugs.python.org/issue10921>
_______________________________________


More information about the Python-bugs-list mailing list