假设我正在使用 IMAP IDLE 来监视邮件文件夹中的更改。
IMAP 规范规定空闲连接最多只能保持 30 分钟,但建议选择较低的分钟数 - 例如 20 分钟,然后取消空闲并重新启动。
我想知道如果邮件内容在空闲取消和创建新空闲之间发生变化会发生什么。可能会错过一封电子邮件。鉴于 RECENT 有点模糊,这可能会导致在旧空闲结束和新空闲开始之前获取消息列表。
但这几乎与每 20 分钟轮询一次相同,并且抵消了空闲的一些好处。
或者,可以在终止到期会话之前启动新的空闲会话。
但无论如何,我认为这个问题已经解决了,所以我在这里寻求建议。
谢谢,
保罗
Lets say I am using IMAP IDLE to monitor changes in a mail folder.
The IMAP spec says that IDLE connections should only stay alive for 30 minutes max, but it is recommended that a lower number of minutes is selected - say 20 minutes, then cancel the idle and restart.
I am wondering what would happen if the mail contents changed between the idle canceling, and the new idle being created. An email could potentially be missed. Given that RECENT is a bit vague, this could lead to getting a message list before the old idle ends, and a new idle starts.
But this is almost the same as polling every 20 minutes, and defeats some of the benefit of idle.
Alternatively, a new idle session could be started prior to terminating the expiring one.
But in any case, I think this problem has already been solved so here I am asking for recommendations.
Thanks,
Paul
发布评论
评论(2)
如您所知,IMAP IDLE 命令(RFC 2177)的目的是使其可以让服务器将状态更新实时传输到客户端。在此上下文中,状态更新是指在新消息到达、消息状态更新或消息删除时发送的未标记 IMAP 服务器响应,例如 EXISTS、RECENT、FETCH 或 EXPUNGE。
但是,这些 IMAP 状态更新可以由任何 IMAP 命令返回,而不仅仅是 IDLE 命令 - 例如,NOOP 命令(请参阅 RFC 3501 第 6.1.2 节)也可用于轮询服务器更新(它早于IDLE 命令)。 IDLE 只能使更有效地获取这些更新成为可能 - 如果您不使用 IDLE 命令,服务器更新将仅在客户端执行另一个命令时(或者甚至没有命令被执行时)由服务器发送。在某些情况下正在进行中) - 请参阅 RFC 3501 第 5.2 和 5.3 节了解详情。
这意味着,如果消息在 IDLE 取消和新 IDLE 命令之间发生更改,状态更新不应丢失,就像如果您从未使用过 IDLE(并且例如,每隔几秒使用 NOOP 一次) - 它们应该在新的 IDLE 命令启动后简单地发送。
As you know, the purpose of IMAP IDLE command (RFC 2177) is to make it possible to have the server transmit status updates to the client in real time. In this context, status updates means untagged IMAP server responses such as EXISTS, RECENT, FETCH or EXPUNGE that are sent when new messages arrive, message status is updated or a message is removed.
However, these IMAP status updates can be returned by any IMAP command, not just the IDLE command - for example, the NOOP command (see RFC 3501 section 6.1.2) can be used to poll for server updates as well (it predates the IDLE command). IDLE only makes it possible to get these updates more efficiently - if you don't use IDLE command, server updates will simply be sent by the server when the client executes another command (or even when no command is in progress in some cases) - see RFC 3501 section 5.2 and 5.3 for details.
This means that if a message is changed between the IDLE canceling and the new IDLE command, the status updates should not be lost, just as they are not lost if you never used IDLE in the first place (and use NOOP every few seconds instead, for example) - they should simply be sent after the new IDLE command is started.
另一种方法是记住正在监视的文件夹的最后一个最高 uid。每当您认为有可能错过更新时。按如下方式进行搜索:*
Another approach would be to remember last highest uid of the folder being monitored. Whenever you think there is chance that you missed update. Do a search as follows :*