如何判断imaplib2空闲响应是否是超时造成的

发布于 2024-10-25 06:02:59 字数 1281 浏览 5 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迎风吟唱 2024-11-01 06:02:59

Piers Lauder(imaplib2 的作者)刚刚在 imaplib2-devel 邮件列表上回答了这个问题。他说:

我认为测试IDLE是否超时的方法是执行:

instance.response('IDLE')

将返回:

('空闲', ['超时'])

如果空闲返回的原因是超时,而不是
其他内容(例如 ('IDLE', [None]))。

我同意这应该被记录下来,所以我将修复 imaplib2.html
文档

Piers Lauder (author of imaplib2) just answered this question on the imaplib2-devel mailing list. He said:

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

海未深 2024-11-01 06:02:59

每次收到此回复时,您都必须手动检查新消息。您可以将消息的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文