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

发布于 2024-10-26 06:55:45 字数 354 浏览 3 评论 0原文

据我了解,无论邮箱如何,都无法查询整个 IMAP 帐户的未读总数或所有最近邮件的 UID。要获取帐户的未读总数,您需要迭代所有 mbox 并检查其状态。我已经这样做了,但速度非常慢(我的一个有很多邮箱的帐户需要 45 秒)。

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

这里的速度只是使用 Net::IMAP 的限制吗?或者我是否缺少一些功能,这些功能将返回一组更有限的邮箱,例如仅包含最近邮件的邮箱?

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

To my understanding, there is no way to query an entire IMAP account for a total unread count, or the UIDs of all recent messages, regardless of mailbox. That to get a total unread count for the account, you need to iterate over all mboxes and check their status. I've done that, but it's very slow (45 seconds on one of my accounts with many mailboxes).

Mail.app can find new messages, even in deeply nested mailboxes, in just a couple seconds.

Is the speed here just a limitation of using Net::IMAP? Or am I missing some functionality that will return a more limited set of mailboxes, like only ones that have RECENT messages?

The only other option I can think of to use response handlers, and also keep a cache of which mboxes have a counter > 1, and then only check the combination of the two each cycle. But since I'm looking to do this in a script, eliminating the need to carry over a cache would be ideal, if not required.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

提笔书几行 2024-11-02 06:55:45

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

A001 STATUS "foldername" (UIDVALIDITY UIDNEXT)

在您关心的每个文件夹上 将为您提供该文件夹的预期下一个 UID。 这是 RFC 的规定

唯一标识符
在邮箱中以严格升序的方式分配;作为每个
消息被添加到邮箱,它被分配了比消息更高的 UID
之前添加的消息。与消息序列不同
数字、唯一标识符不一定是连续的。

下一个唯一标识符值是预测值
分配给邮箱中的新邮件。除非独一无二
标识符的有效性也发生变化(见下文),下一个唯一的
标识符值必须具有以下两个特征。第一的,
除非有新消息,否则下一个唯一标识符值不得更改
已添加至邮箱;其次,下一个唯一标识符
每当新消息添加到邮箱时,值必须更改,
即使这些新消息随后被删除。

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

类似的东西

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

The canonical way to detect new messages in IMAP is via UIDNEXT. Issuing

A001 STATUS "foldername" (UIDVALIDITY UIDNEXT)

on each folder that you care about will give you the expected next UID for that folder. Here's what the RFC has to say:

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

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

So just keep track of the each folder's expected next UID and UID validity value. If a STATUS command results in either UIDNEXT or UIDVALIDITY changing from your cached value, you know you need to check for new mail (if the former) or resync (if the latter).

Something like this:

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