-
-
Notifications
You must be signed in to change notification settings - Fork 252
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
MessageIterator::current() fails when there are no messages #288
Comments
Hi, can you post the code that reproduce the error? Because this can only happens when you manually instantiate I've just pushed a new commit caacd25 to prove this, and as you can see on Travis the build succeeds: https://travis-ci.org/ddeboer/imap/builds/331410487 |
Hi @Slamdunk, thank you for fast response :) Here is block of code which caused the error. I use $searchExpression = new SearchExpression();
$searchExpression->addCondition(new From($rule['from']));
$searchExpression->addCondition(new Subject($rule['subject']));
return $mailbox->getMessages($searchExpression, SORTDATE)->current(); // ouch Maybe I'm doing something wrong. You can see my workaround bellow. // build search expression, fetch messages into $messages - same code as above
if ($messages->valid()) {
$message = $messages->current();
} else {
$this->logger->notice('No message found for this rule.', $rule);
continue;
} |
Hi, I reproduced the bug, you are right. But I am honestly against changing the current behaviour to fulfil a valid value, because there isn't a unique result neither in the simple case; take for example: $array = new \ArrayIterator(array());
var_dump(current($array));
var_dump($array->current()); What do you expect? Here the answers: https://3v4l.org/WuFZ0 I don't want to return |
Wow, null and false is wtf... Thank you for fixing it in PR, good job! What do you think about my workaround? Could you recommend me better way to get the oldest message from search? I do not need more messages, just the oldest one. |
Your way looks good, makes sense and its purpose is easy to understand, keep it like that. |
Hi,
MessageIterator::current()
fails when you perform search in mailbox and no messages. This probably also occurs when you list messages bygetMessages
and mailbox is emptyThe text was updated successfully, but these errors were encountered: