问题
I am using gmail's IMAP API to search for mails.
I use the 'OR' criteria to search for different keywords. This works well if I go one level only, i.e. something like
'UID SEARCH OR (FROM "somebody@email.com") (TO "somebody@email.com")'
however, it does not work when I try a longer expression like
criteria OR criteria OR criteria or criteria
which translates to (as far as I understand the syntax)
'UID SEARCH OR ( OR (FROM "somebodyelse@email.com") (TO "somebodyelse@email.com")) ( OR (FROM "somebody@email.com") (TO "somebody@email.com"))'
to make it clear I basically want all messages that are either sent from or sent to ANY of a given list of emails
The error I get from the libray is
[ 'A34', 'BAD', 'Could', 'not', 'parse', 'command' ]
any suggestions?
回答1:
Do not use parenthesis.
IMAP uses polish notation which does not need them:
UID SEARCH OR OR FROM one@mail.com TO one@mail.com OR FROM two@mail.com TO two@mail.com
There are cases where parenthesis are needed (as IMAP AND operator can take more than 2 operands): https://www.limilabs.com/blog/imap-search-requires-parentheses
回答2:
So if you have N expressions that you want to "OR" together, you would prefix those N expressions by N-1 "OR"s.
In Perl, for example, that would be:
$search = join " ", ("OR") x (@exprs - 1), @exprs;
来源:https://stackoverflow.com/questions/12809709/imap-criteria-with-multiple-ors