我正在使用imaplib2 ( docs ) 与 IMAP 服务器交互。
我正在使用带有超时和回调的空闲命令。
问题是,我看不到任何方法来判断回调是否是由于达到超时而触发的,或者服务器上是否有我需要检查的更改。
我每次都会得到('OK', ['IDLE终止(成功)'])
。
这是两种情况的调试输出:
超时:
15:43.94 MainThread server IDLE started, timeout in 5.00 secs
15:48.94 imap.gmail.com handler server IDLE timedout
15:48.94 imap.gmail.com handler server IDLE finished
15:48.94 imap.gmail.com writer > DONE\r\n
15:49.17 imap.gmail.com reader < DDDM6 OK IDLE terminated (Success)\r\n
15:49.17 imap.gmail.com handler _request_pop(DDDM6, ('OK', ['IDLE terminated (Success)']))
发生了一些事情:
18:41.34 MainThread server IDLE started, timeout in 50.00 secs
19:01.35 imap.gmail.com reader < * 1 EXISTS\r\n
19:01.37 imap.gmail.com handler server IDLE finished
19:01.37 imap.gmail.com writer > DONE\r\n
19:01.59 imap.gmail.com reader < BFCN6 OK IDLE terminated (Success)\r\n
19:01.59 imap.gmail.com handler _request_pop(BFCN6, ('OK', ['IDLE terminated (Success)']))
我错过了什么?
imaplib2 中不存在该功能吗?
最佳答案
Piers Lauder(imaplib2 的作者)刚刚在 imaplib2-devel 邮件列表上回答了这个问题。他说:
I think the way to test if an IDLE has timed out is to execute:
instance.response('IDLE')
which will return:
('IDLE', ['TIMEOUT'])
if the reason that the idle returned as a timeout, rather than something else (such as
('IDLE', [None])
).I agree that this should be documented, so I'll fix the imaplib2.html document
关于python - 如何判断imaplib2空闲响应是否是超时造成的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5359134/