0

The API reference for Python 3 says imaplib's Internaldate2tuple parses an IMAP4 INTERNALDATE string, yet I can't find the information anywhere what that exactly means. The reverse function (Time2Internaldate) seems to produce one of these INTERNALDATE strings yet it's apparently not good enough for the Internaldate2tuple string. Is this a bug, shouldn't imaplib's functions be compatible with each other?

Is there any other way to parse the internaldate besides regexes and some strftime whatever magic?

from time import localtime

internaldate = imaplib.Time2Internaldate(localtime())
print("Coded: " + internaldate)

coded = imaplib.Internaldate2tuple(internaldate.encode('ascii'))
if coded == None:
    print("Wrong format")
else:
    print("Success")

internaldate = internaldate.replace('"', '')
print("Coded: " + internaldate)

coded = imaplib.Internaldate2tuple(internaldate.encode('ascii'))
if coded == None:
    print("Wrong format")
else:
    print("Success")

Output:

Coded: "14-Dec-2019 15:15:47 +0200"
Wrong format
Coded: 14-Dec-2019 15:15:47 +0200
Wrong format
Villahousut
  • 115
  • 1
  • 11

1 Answers1

1

Refer here

A sample input is:

Internaldate2tuple(b'INTERNALDATE "01-Jan-2000 12:00:00 +0000"')
yoon
  • 1,177
  • 2
  • 15
  • 28