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

标签 python timeout imap python-idle imaplib

我正在使用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/

相关文章:

python - 从 bytearray 转换为 bytes 会产生一个副本吗?

python - 我似乎无法在 python 中找到前面的零的正确格式规范

ffmpeg - 无法识别的选项 'stimeout'

python - Discord.py 按钮响应交互在一定时间后失败

java - Android JavaMail IMAP 10 秒后超时

smtp - 如何使用 IMAP 发送邮件?

python - SVM - 如何向量化核化克矩阵?

python 根据二叉树检查值,空输出

PHP超时错误处理

php - 如何在 PHP 中使用 imap 从电子邮件中提取内联图像(不是附件)