Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to query using OR #472

Open
gmartinez opened this issue Apr 16, 2023 · 2 comments
Open

How to query using OR #472

gmartinez opened this issue Apr 16, 2023 · 2 comments
Labels

Comments

@gmartinez
Copy link

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.

  • client->getFolder('INBOX')->query()->to("one")->to("another")->get()
  • client->getFolder('INBOX')->query()->where([["TO"=>"one"],["TO"=>"another"]])->get()

Thanks in advance !

@Webklex
Copy link
Owner

Webklex commented Apr 16, 2023

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("[email protected]")->orWhere(function($query){
    $query->text("some custom text")->orWhere("[email protected]");
})->get();

Best regards & happy hacking,

@gmartinez
Copy link
Author

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants