IMAP: Search for messages with UID greater than X (or generally, after my last search)

廉价感情. 提交于 2019-11-27 06:37:58

问题


I'm writing a script to analyze my mailbox and want to periodically check for new messages. The search criteria would be: give me the UIDs for all emails with UID greater than X, where X is the UID of the last email I processed.

Or, more generally, I'm looking for a way to only see messages since my last search.

Note that I'm not looking for seen/unseen messages; the script opens the mailbox as read-only, and I'd like it to not interfere with my flags, etc.

I know I can specify a date in the IMAP search, but the granularity of that seems to be by day, so not exactly what I need.

I'm starting with Gmail as the IMAP server, but would like to support generic IMAP servers in the future.

Is there way to search for emails with UID greater than X? Or another means of specify all messages since message X?


回答1:


You can use IMAP SEARCH for UIDs. Assuming your most recently fetched UID is 1999, I think you would do:

SEARCH UID 2000:*




回答2:


Why not use IMAP IDLE for this?

with IMAP IDLE, the server warns you every time a new message arrives



来源:https://stackoverflow.com/questions/9147424/imap-search-for-messages-with-uid-greater-than-x-or-generally-after-my-last-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!