imaplib的Internaldate2tuple期望什么输入?

问题描述 投票:0回答:1

[Python 3的API reference说imaplib的Internaldate2tuple解析了IMAP4 INTERNALDATE字符串,但我无法在任何地方找到该信息的确切含义。反向函数(Time2Internaldate)似乎产生了这些INTERNALDATE字符串之一,但对于Internaldate2tuple字符串来说显然不够好。这是一个错误,imaplib的功能不应该相互兼容吗?

除了正则表达式和某些strftime以外,还有其他方法可以解析内部日期吗?

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")

输出:

Coded: "14-Dec-2019 15:15:47 +0200"
Wrong format
Coded: 14-Dec-2019 15:15:47 +0200
Wrong format
python-3.x imaplib
1个回答
0
投票

参考here

示例输入为:

Internaldate2tuple(b'INTERNALDATE "01-Jan-2000 12:00:00 +0000"')
© www.soinside.com 2019 - 2024. All rights reserved.