0

I'm trying to do a search on a Gmail account through IMAP, using imap_search to filter the to and from email addresses and I'm getting back syntax errors. Can anyone advise on what's wrong with this, or of any good documentation to assist me?

FROM "address@example1.co.uk" OR TO "address@example1.co.uk" OR FROM "address@example2.co.uk" OR TO "address@example2.co.uk"



( OR (FROM "address@example1.co.uk") (TO "address@example1.co.uk") (FROM "address@example2.co.uk") (TO "address@example2.co.uk"))

I have tried both of the above example, both resulting in the error below

Messages not found. Or this criteria not supported on your email server.
yivi
  • 42,438
  • 18
  • 116
  • 138
Luke Pring
  • 992
  • 3
  • 11
  • 16
  • Have changed and tested, has not had any effect :( – Luke Pring May 25 '20 at 07:41
  • Are you sure those messages exist in the inbox (e.g. not archived). Individual messages can be archived, and yet be shown as part of conversation shown in inbox (because some of the messages were not archived). – yivi May 25 '20 at 07:56
  • I pulled those addresses I'm testing with directly from my inbox. It also works with just one clause (FROM "x@y.com") – Luke Pring May 25 '20 at 08:09
  • There was some discussion about removing the `imap` extension since it's unmantained and move to a pure php library (can't find the exact link with the rationale, only the [proposal](https://wiki.php.net/rfc/removal_of_dead_sapis_and_exts#extimap)). Maybe `OR` clauses is one of the unsupported functionality ([this question](https://stackoverflow.com/questions/36356715/imap-search-unknown-search-criterion-or) and [this comment](https://www.php.net/manual/en/function.imap-search.php#119148) in the php site support that theory). – msg May 25 '20 at 12:47
  • OR is a prefix function that takes only two search terms `OR A B`. If you want more than that, you need to chain them. Either `OR (OR A B) (OR C D)`, or `OR (OR (OR A B) C) D`, which can probably just be reduced to `OR OR OR A B C D` – Max May 25 '20 at 13:44
  • An update to my previous comment: [Info on the php wiki](https://wiki.php.net/todo/ext/imap) (with additional information related to gmail specifically, see the `XOAUTH` link) and related discussion in [the bug tracker](https://bugs.php.net/bug.php?id=78572). – msg May 25 '20 at 14:41

0 Answers0