gpt4 book ai didi

ruby - 有效检查整个帐户的未读计数

转载 作者:数据小太阳 更新时间:2023-10-29 08:54:18 25 4
gpt4 key购买 nike

据我了解,无论邮箱如何,都无法查询整个 IMAP 帐户的未读总数或所有最近邮件的 UID。为了获得帐户的未读总数,您需要遍历所有 mbox 并检查它们的状态。我已经这样做了,但是速度很慢(在我的一个有很多邮箱的帐户上需要 45 秒)。

Mail.app 可以在几秒钟内找到新邮件,即使是在深度嵌套的邮箱中。

这里的速度是否只是使用 Net::IMAP 的限制?或者我是否缺少一些功能,这些功能将返回一组更有限的邮箱,比如只有那些有最近消息的邮箱?

我能想到的唯一其他选择是使用响应处理程序,并保留一个缓存,其中 mboxes 的计数器 > 1,然后每个周期只检查两者的组合。但由于我希望在脚本中执行此操作,因此如果不需要的话,消除对缓存的需求将是理想的。

最佳答案

在 IMAP 中检测新消息的规范方法是通过 UIDNEXT。发行

A001 STATUS "foldername" (UIDVALIDITY UIDNEXT)

在您关心的每个 文件夹上,将为您提供该文件夹的预期下一个 UID。 Here's what the RFC has to say :

Unique identifiersare assigned in a strictly ascending fashion in the mailbox; as eachmessage is added to the mailbox it is assigned a higher UID than themessage(s) which were added previously. Unlike message sequencenumbers, unique identifiers are not necessarily contiguous.

The next unique identifier value is the predicted value that will beassigned to a new message in the mailbox. Unless the uniqueidentifier validity also changes (see below), the next uniqueidentifier value MUST have the following two characteristics. First,the next unique identifier value MUST NOT change unless new messagesare added to the mailbox; and second, the next unique identifiervalue MUST change whenever new messages are added to the mailbox,even if those new messages are subsequently expunged.

因此只需跟踪每个文件夹的预期下一个 UID 和 UID 有效性值。如果 STATUS 命令导致 UIDNEXTUIDVALIDITY 从您的缓存值更改,您知道您需要检查新邮件(如果前者) 或重新同步(如果是后者)。

Something like this :

imap.status("foldername", ["UIDNEXT", "UIDVALIDITY"])

关于ruby - 有效检查整个帐户的未读计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5399990/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com