Can you use conditionals in IMAP_SEARCH from the PHP IMAP library?
I haven't been able to find anything while exploring the code and searching for documentation. Has anyone been able to achieve this?
http://php.net/manual/en/function.imap-sea开发者_运维知识库rch.php
No, you can't. (Hard to believe, right?)
PHP uses Mark Crispin's c-client library under the hood to do its IMAP work. In the c-client library, there is a deprecated method mail_criteria
in mail.c
that translates an IMAP search string to a c-client search program. mail_criteria
has been deprecated for the past 8 years or so and, as such, was never updated to support the IMAP4 search syntax. So search terms like OR
that weren't present in IMAP2 never got support in the mail_criteria
function. Here's all the terms it supports starting with an 'O
':
case 'O': /* possible OLD, ON */
if (!strcmp (criterion+1,"LD")) f = pgm->old = T;
else if (!strcmp (criterion+1,"N"))
f = mail_criteria_date (&pgm->on,&r);
break;
OR
isn't on that list. So even though the c-client supports OR
in its SEARCHPGM
structs, it doesn't parse OR
in the deprecated mail_criteria
function.
And PHP still uses mail_criteria
to parse search queries. In 2011. So until either the c-client library un-deprecates mail_criteria
and makes it IMAP4-compliant or PHP writes its own IMAP search parser, you are stuck with whatever IMAP2 supported. Which doesn't include OR
.
精彩评论