Webklex / laravel-imap

Laravel IMAP is an easy way to integrate both the native php-imap module and an extended custom imap protocol into your Laravel app.
https://www.php-imap.com
MIT License
637 stars 182 forks source link

How to query using OR #472

Open gmartinez opened 1 year ago

gmartinez commented 1 year ago

Hi there, new to the package here, could not find or infer from documentation so here it goes the question.

How can I search using ORs, trying to query for messages sent to one OR another recipient, trie the following with no luck.

Thanks in advance !

Webklex commented 1 year ago

Hi @gmartinez , if the "OR" operation is supported by your mail provider you can use it a few different ways. Here are a few examples:

$messages = $folder->query()->subject("some subject")->orWhere()->to("some@one.tld")->orWhere(function($query){
    $query->text("some custom text")->orWhere("from@someone.com");
})->get();

Best regards & happy hacking,

gmartinez commented 1 year ago

Using orWhere(function... seem to build the query fine, but upon issuing the get() I get an ImapServerErrorException

FYI I am querying gmail, which according to documentation does support OR.

When turning degub the text around the error reads;

<< TAG3 OK [READ-WRITE] INBOX selected. (Success)

TAG4 UID SEARCH TO "one" OR TO "another"

<< TAG4 BAD Could not parse command

Webklex\PHPIMAP\Exceptions\ImapServerErrorException

Any idea ?