Index: Lib/imaplib.py =================================================================== --- Lib/imaplib.py (revision 88102) +++ Lib/imaplib.py (working copy) @@ -22,7 +22,7 @@ __version__ = "2.58" -import binascii, errno, random, re, socket, subprocess, sys, time +import binascii, errno, random, re, socket, subprocess, sys, time, calendar try: import ssl @@ -1312,7 +1312,7 @@ b'Jul': 7, b'Aug': 8, b'Sep': 9, b'Oct': 10, b'Nov': 11, b'Dec': 12} def Internaldate2tuple(resp): - """Convert IMAP4 INTERNALDATE to UT. + """Convert IMAP4 INTERNALDATE to local time. Returns Python time module tuple. """ @@ -1339,19 +1339,9 @@ zone = -zone tt = (year, mon, day, hour, min, sec, -1, -1, -1) + utc = calendar.timegm(tt) - zone - utc = time.mktime(tt) - - # Following is necessary because the time module has no 'mkgmtime'. - # 'mktime' assumes arg in local timezone, so adds timezone/altzone. - - lt = time.localtime(utc) - if time.daylight and lt[-1]: - zone = zone + time.altzone - else: - zone = zone + time.timezone - - return time.localtime(utc - zone) + return time.localtime(utc) @@ -1381,7 +1371,7 @@ def Time2Internaldate(date_time): - """Convert 'date_time' to IMAP4 INTERNALDATE representation. + """Convert 'date_time' (local time) to IMAP4 INTERNALDATE representation. Return string in form: '"DD-Mmm-YYYY HH:MM:SS +HHMM"' """ Index: Lib/test/test_imaplib.py =================================================================== --- Lib/test/test_imaplib.py (revision 88102) +++ Lib/test/test_imaplib.py (working copy) @@ -24,7 +24,9 @@ class TestImaplib(unittest.TestCase): def test_Internaldate2tuple(self): + # The following two should produce the same result (see issue 10941). self.assertEqual(imaplib.Internaldate2tuple(b'25 (INTERNALDATE "01-Apr-2000 19:02:23 -0700")')[0:6], (2000, 4, 1, 19, 2, 23)) + self.assertEqual(imaplib.Internaldate2tuple(b'101 (INTERNALDATE "02-Apr-2000 02:02:23 +0000")')[0:6], (2000, 4, 1, 19, 2, 23)) def test_that_Time2Internaldate_returns_a_result(self): # We can check only that it successfully produces a result,