Alternative for IMAP search command

被刻印的时光 ゝ 提交于 2019-12-24 13:26:36

问题


I need an alternative for IMAP search command "A search 1:* unseen not deleted" since the email server is forbidding the search command. I tried using "A status (unseen)" but it always returns zero though there's an unread message. Is there any alternative for the command? Thanks in advance.


回答1:


Is your problem that the IMAP server doesn't support SEARCH at all, or that it doesn't like your particular SEARCH command? If it's the latter, we can simplify:

A SEARCH UNSEEN UNDELETED

(as 1:* is implicit). Even simpler -- just in case the server doesn't like and-ing SEARCH terms together at all -- would be:

A SEARCH UNSEEN
B SEARCH DELETED

and logically doing the AND in your code.

The brute-force way of doing it is:

C UID FETCH 1:* FLAGS

and then picking out all the ones with neither \Seen nor \Deleted. (I'm suggesting UID FETCH because a similar FETCH command will return BAD on an empty folder.)

Also, you're not supposed to call the STATUS command on the currently-selected folder:

Note: The STATUS command is intended to access the status of mailboxes other than the currently selected mailbox. Because the STATUS command can cause the mailbox to be opened internally, and because this information is available by other means on the selected mailbox, the STATUS command SHOULD NOT be used on the currently selected mailbox.



来源:https://stackoverflow.com/questions/5386696/alternative-for-imap-search-command

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