如何判断imaplib2空闲响应是否由timeou引起

2024-06-16 13:18:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用imaplib2docs)与IMAP服务器交互。在

我使用idle命令,有一个超时和一个回调。在

问题是,我看不到任何方法来判断回调是由超时触发的,还是服务器上是否有需要我检查的更改。在

我每次都得到('OK', ['IDLE terminated (Success)'])。在

以下是两种情况下的调试输出:

时间点:

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)']))

出事了:

^{pr2}$

我错过了什么?在

imaplib2中不存在这个功能吗?在


Tags: 服务器comdocsserverokgmailhandlersuccess
2条回答

每次收到此响应时,必须手动检查新消息。您可以将消息的uid存储在一个列表中,并在每次回调时将新uid与它进行比较。这样您就可以很容易地判断是否有新消息或超时。在

作者刚刚回答了这个问题。他说:

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

相关问题 更多 >