Alternative for IMAP search command
I need an alternative for IMAP search command "A search 1:* unseen not del开发者_如何学Goeted" 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.
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.
精彩评论