imaplib function bug?

Colin Brown cbrown at metservice.com
Sun Sep 26 20:29:56 EDT 2004


Importing calendar and then making the modification as below to imaplib.py
fixes the problem ;-)

=======================================

def Internaldate2tuple(resp):
    """Convert IMAP4 INTERNALDATE to UT.

    Returns Python time module tuple.
    """

    mo = InternalDate.match(resp)
    if not mo:
        return None

    mon = Mon2num[mo.group('mon')]
    zonen = mo.group('zonen')

    day = int(mo.group('day'))
    year = int(mo.group('year'))
    hour = int(mo.group('hour'))
    min = int(mo.group('min'))
    sec = int(mo.group('sec'))
    zoneh = int(mo.group('zoneh'))
    zonem = int(mo.group('zonem'))

    # INTERNALDATE timezone must be subtracted to get UT

    zone = (zoneh*60 + zonem)*60
    if zonen == '-':
        zone = -zone

    tt = (year, mon, day, hour, min, sec, -1, -1, -1)
    return time.gmtime(calendar.timegm(tt) - zone)

==============================================

Colin Brown
PyNZ

"Colin Brown" <cbrown at metservice.com> wrote in message
news:4153575a$1 at news.iconz.co.nz...
> The Python 2.3 documentation in imaplib says:
>   Internaldate2tuple( datestr)
>   Converts an IMAP4 INTERNALDATE string to Coordinated Universal Time.
> Returns a time module tuple.
>
>   Time2Internaldate( date_time)
>   Converts a time module tuple to an IMAP4 "INTERNALDATE" representation.
> Returns a string in the form: "DD-Mmm-YYYY HH:MM:SS +HHMM" (including
> double-quotes).
> Yet running the following code produces inconsistent results (returning
> local not UTC time for Internaldate2tuple):
>
> import imaplib, time
> tmtup = time.localtime()
> imaptm = imaplib.Time2Internaldate(tmtup)
> print 'local_time:',tmtup
> print 'local_time:',imaptm
> utc = imaplib.Internaldate2tuple('INTERNALDATE '+imaptm)
> print 'utc_time  :',utc
>
> C:\>python imapbug.py
> local_time: (2004, 9, 24, 10, 52, 59, 4, 268, 0)
> local_time: "24-Sep-2004 10:52:59 +1200"
> utc_time  : (2004, 9, 24, 10, 52, 59, 4, 268, 0)
>
> Is this a bug?
>
> Colin Brown
> PyNZ
>
>
>





More information about the Python-list mailing list