IMAP - 获取上一个和下一个 UID
使用标准规范 IMAP 命令,如何根据传递的 UID 确定邮箱中的上一个和下一个 UID,并按日期对邮箱消息进行排序,最新的在前?
Using standard spec IMAP commands, how can I determine the previous and next UIDs in a mailbox based on a passed UID, sorting the mailbox messages by date, newest first?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我找到了带有以下代码的新邮件 UID。
I have found new mail UID with below code.
假设“按日期对邮箱邮件进行排序,最新的在前”是指邮件添加到邮箱的时间,而不是
INTERNALDATE
或日期
header:需要注意的事项:
SEARCH
将不会返回任何结果。BAD
响应。如果您不想使用
SEARCH
,也可以通过UID FETCH
执行 UID 到序列:Assuming that "sorting the mailbox messages by date, newest first" refers to the time the messages were added to the mailbox rather than
INTERNALDATE
or theDate
header:Things to look out for:
SEARCH
will return no results.BAD
response.If you'd prefer not to use
SEARCH
, you could also do the UID-to-sequence viaUID FETCH
:我认为唯一的方法是首先询问所有 UID:
...然后排序。添加到邮箱的每条消息都会分配一个比之前添加的消息更高的 UID。
所以更高的 UID = 更新的电子邮件。
I think the only way would be to ask for all UIDs first:
...and sort. Each message added to the mailbox is assigned a higher UID than the messages which were added previously.
So higher UID = newer email.
如果你想搜索 12345 之前的 UID,这个命令可以做到:
查找下一个:
这需要 ESEARCH 扩展,大多数现代服务器都实现。值得注意的是 gmail 实现了它。不过,循环发出的成本有点太高了,所以也许您最好以其他方式解决问题。以下是获取 12345 之前的 50 个 UID 的两个命令序列:
950 是“c1 - 50 的结果”,999 是“c1 - 1 的结果”。
If you want to search for the UID before 12345, this command will do it:
Finding the next after:
This requires the ESEARCH extension, which most modern servers implement. Notably gmail implements it. It's a little too expensive to issue in a loop, though, so perhaps you're better off solving your issue in another way. Here's a two-command sequence to get the 50 UIDs immediately preceding 12345:
950 is "result of c1 - 50", 999 is "result of c1 - 1".
我不熟悉确切的命令,但你检查过 RFC 吗?
https://www.rfc-editor.org/rfc/rfc3501
看起来像那里是您可以发送的 UIDNEXT 命令,它为您提供下一个 UID。
I'm not familiar with the exact commands, but have you checked out the RFC?
https://www.rfc-editor.org/rfc/rfc3501
Looks like there is a UIDNEXT command you can send that gives you the next UID.