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

Improve error description in getMessageSequence/getMessages methods #436

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ public function getMessages(ConditionInterface $search = null, int $sortCriteria
$messageNumbers = \imap_search(...$params);
}
if (false === $messageNumbers) {
if (false !== \imap_last_error()) {
throw new InvalidSearchCriteriaException(\sprintf('Invalid search criteria [%s]', $query));
if (false !== $errorMessage = \imap_last_error()) {
throw new InvalidSearchCriteriaException(
$errorMessage ?: \sprintf('Invalid search criteria [%s]', $query)
);
}

// imap_search can also return false
Expand All @@ -206,8 +208,10 @@ public function getMessageSequence(string $sequence): MessageIteratorInterface
if (\is_array($overview) && [] !== $overview) {
$messageNumbers = \array_column($overview, 'uid');
} else {
if (false !== \imap_last_error()) {
throw new InvalidSearchCriteriaException(\sprintf('Invalid sequence [%s]', $sequence));
if (false !== $errorMessage = \imap_last_error()) {
throw new InvalidSearchCriteriaException(
$errorMessage ?: \sprintf('Invalid sequence [%s]', $sequence)
);
}

$messageNumbers = [];
Expand Down
2 changes: 2 additions & 0 deletions tests/MailboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public function testGetMessageSequence(): void
public function testGetMessageSequenceThrowsException(): void
{
$this->expectException(InvalidSearchCriteriaException::class);
$this->expectExceptionMessageRegExp('/Syntax error in sequence/');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test succeeds even without your changes in Mailbox, and this is because all the errors are outputted in the exception trace:

Ddeboer\Imap\Exception\InvalidSearchCriteriaException: Invalid sequence [-1:x]
imap_alerts (0):
imap_errors (1):
- Syntax error in sequence

See https://github.com/ddeboer/imap/blob/master/src/Exception/AbstractException.php#L44

So as far as I can tell, there is no need for this PR :\


$this->mailbox->getMessageSequence('-1:x');
}

Expand Down