php-imap icon indicating copy to clipboard operation
php-imap copied to clipboard

Error when searching Flagged Messages

Open oriolfuentes opened this issue 2 years ago • 1 comments

Hello,

I 'm trying to fetch flagged mails from a specified folder. I tried: $folder->query()->not()->unflagged()->setFetchBody(false)->leaveUnread()->get(); $folder->query()->not()->where([["UNFLAGGED"]])->leaveUnread()->get();

And some other I don't have now.

It throws me this reponse: Too few arguments to function Webklex\PHPIMAP\Query\WhereQuery::where(), 0 passed and at least 1 expected

Also tried:

    $folder->query()->flagged('Flagged')->setFetchBody(false)->leaveUnread()->get();

This throws me: Webklex \PHPIMAP\ Exceptions\ImapServerErrorException

I also tried: $aMessage = $folder->query()->seen()->setFetchBody(false)->leaveUnread()->get(); $aMessage = $folder->query()->unseen()->setFetchBody(false)->leaveUnread()->get(); $aMessage = $folder->query()->unflagged()->setFetchBody(false)->leaveUnread()->get(); $aMessage = $folder->query()->whereAll()->setFetchBody(false)->leaveUnread()->get();

And they work perfectly.

Any ideas why I can not retrive flagged messages or where is my error?

Thanks in advance.

Oriol

oriolfuentes avatar May 14 '23 08:05 oriolfuentes

I'm pretty sure the answer is too late, but in case anyone else stumbles over this. I had the exact same issue, the trick is, to pass an empty string to the flagged method like so:

$folder->query()->flagged('')->setFetchBody(false)->leaveUnread()->get();

The reason is, that the IMAP standard doesn't expect any value associated with the FLAGGED search. By passing an empty string, the library will only pass the required filter without any value.

brainformatik avatar Jan 24 '25 09:01 brainformatik