barbushin / php-imap

Manage mailboxes, filter/get/delete emails in PHP (supports IMAP/POP3/NNTP)
MIT License
1.66k stars 457 forks source link

[BUG] Imap::sort() throws exceptions for empty sets #647

Closed psiberx closed 2 years ago

psiberx commented 2 years ago

Environment:

Describe the bug Imap::sort() throws exceptions when there is no error because it incorrectly handles the result of imap_sort() call.

This check:

if (!$result) {
    throw new UnexpectedValueException('Could not sort messages!', 0, self::HandleErrors(\imap_errors(), 'imap_sort'));
}

Should be replaced with:

if ($result === false) {
    throw new UnexpectedValueException('Could not sort messages!', 0, self::HandleErrors(\imap_errors(), 'imap_sort'));
}

https://www.php.net/manual/en/function.imap-sort.php

To Reproduce Call Imap::sort() with criteria that should return an empty set.

Expected behavior No exception.