Index: Lib/imaplib.py =================================================================== --- Lib/imaplib.py (revision 88215) +++ Lib/imaplib.py (working copy) @@ -1308,9 +1308,11 @@ -Mon2num = {'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun': 6, - 'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12} +_month_names = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', + 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] +Mon2num = dict(zip((x.encode() for x in _month_names), range(1, 13))) + def Internaldate2tuple(resp): """Parse an IMAP4 INTERNALDATE string. @@ -1401,17 +1403,21 @@ else: raise ValueError("date_time not of a known type") - dt = time.strftime("%d-%b-%Y %H:%M:%S", tt) - if dt[0] == '0': - dt = ' ' + dt[1:] if time.daylight and tt[-1]: zone = -time.altzone else: zone = -time.timezone - return '"' + dt + " %+03d%02d" % divmod(zone//60, 60) + '"' + result = (('%02d-%s-%04d %02d:%02d:%02d' % + (tt[2], _month_names[tt[1] - 1], tt[0], tt[3], tt[4], tt[5])) + + (' %+03d%02d' % divmod(zone//60, 60))) + if result[0] == '0': + result = ' ' + result[1:] + return '"' + result + '"' + + if __name__ == '__main__': # To test: invoke either as 'python imaplib.py [IMAP4_server_hostname]'