如何判断imaplib2空闲响应是否是超时造成的
我正在使用 imaplib2 (docs) 与 IMAP 服务器交互。
我正在使用带有超时和回调的空闲命令。
问题是,我看不到任何方法来判断回调是否是由于达到超时而触发的,或者服务器上是否有我需要检查的更改。
我每次都会得到 ('OK', ['IDLE returned (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)']))
发生了一些事情:
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 中不存在该功能吗?
I'm using imaplib2 (docs) to interact with an IMAP server.
I'm using the idle command, with a timeout and a callback.
The problem is, I don't see any way of telling if the callback was triggered by the timeout being reached, or if there was a change on the server that I need to check out.
I just get ('OK', ['IDLE terminated (Success)'])
every time.
Here's the debug output for both cases:
Timedout:
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)']))
Something happened:
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)']))
What am I missing?
Does the functionality just not exist in imaplib2?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Piers Lauder(imaplib2 的作者)刚刚在 imaplib2-devel 邮件列表上回答了这个问题。他说:
Piers Lauder (author of imaplib2) just answered this question on the imaplib2-devel mailing list. He said:
每次收到此回复时,您都必须手动检查新消息。您可以将消息的 UID 存储在列表中,并在每次回调时将新的 UID 与其进行比较。这样您就可以轻松判断是否有新消息或超时。
You'll have to manually check for new messages each time you get this response. You can store the UIDs of messages in a list and compare new UIDs with it upon each callback. This way you can easily tell if there are new messages or a timeout.