Can you use conditionals in IMAP_SEARCH from the P

2019-09-05 14:15发布

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-search.php

标签: php email imap
1条回答
Emotional °昔
2楼-- · 2019-09-05 14:42

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.

查看更多
登录 后发表回答