473,407 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

imaplib function bug?

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

Jul 18 '05 #1
1 2014

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" <cb****@metservice.com> wrote in message
news:41********@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

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bill Sneddon | last post by:
Anyone have an example they are willing to share that shows how to use the store command in imaplib? store( message_set, command, flag_list) Alters flag dispositions for messages in mailbox. ...
0
by: Mr. Magoo | last post by:
I'm working with imaplib. I'm trying to flag (or move or copy - anything that takes a message_set as an argument) a bunch of messages with one command and am having trouble. === def...
2
by: Max M | last post by:
I am using the fetch command from the imaplib to fetch messages. I get a result, but I am a bit uncertain as to how I should interpret it. The result is described at...
1
by: Raghul | last post by:
Is it posssible to read only the new messages or unread messages using imaplib in python? If it is possible pls specify the module or give a sample code. Thanks in advance
0
by: Wolfgang Kohnen | last post by:
Hello out there! I am new to python and so far I like it a lot. Now I want to create some IMAP mailboxes on my cyrus imapd, with quotas and each user should be subscribed to her/his own spam...
5
by: Antoon Pardon | last post by:
This little program gives IMO a strange result. import imaplib user = "cpapen" cyr = imaplib.IMAP4("imap.vub.ac.be") cyr.login("cyrus", "cOn-A1r") rc, lst = cyr.list('""', "user/%s/*" %...
1
by: aspineux | last post by:
imaplib use exception to report errors, but some problems must be detected by checking the return value ! For example, when trying to append into a mailbox with wrong ACL, imaplib return 'NO',...
0
by: aspineux | last post by:
setacl and getacl look to be already "Cyrus" specific (according the doc), why not to extend imaplib a little bit more ? Here are some code I wrote and tested to support cyrus "expire" that...
4
by: gregpinero | last post by:
I'm trying to get a list of messages from GMAIL using it's new IMAP access. So far I've tried running this command but it just hangs. Any ideas? I figured that's the first line to run from...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.