有效检查整个帐户的未读计数
据我了解,无论邮箱如何,都无法查询整个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 IMAP 中检测新消息的规范方法是通过
UIDNEXT
。 发出在您关心的每个文件夹上 将为您提供该文件夹的预期下一个 UID。 这是 RFC 的规定:
因此,只需跟踪每个文件夹的预期下一个 UID 和 UID 有效性值即可。如果
STATUS
命令导致UIDNEXT
或UIDVALIDITY
更改缓存值,则您知道需要检查新邮件(如果前者)或重新同步(如果是后者)。类似的东西:
The canonical way to detect new messages in IMAP is via
UIDNEXT
. Issuingon each folder that you care about will give you the expected next UID for that folder. Here's what the RFC has to say:
So just keep track of the each folder's expected next UID and UID validity value. If a
STATUS
command results in eitherUIDNEXT
orUIDVALIDITY
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: