laminas-mail icon indicating copy to clipboard operation
laminas-mail copied to clipboard

Storage\Message Iterator Implementation is not Robust

Open ginkgomzd opened this issue 5 years ago • 0 comments

Bug Report

Q A
Version(s) 2.10.0

Summary

Storage\Message Iterator implementation does not catch exceptions and so is of limited to no use. In the case where you simply want to deal with valid emails, you must instead...

for ($n = $boxCount+1; $n>0; $n--) {
    try {
        $msg = $mailbox[$n];
        $from = $msg->from;
    } catch (Exception $x) {
        continue;
    }
...

... because using a foreach, the try-catch must wrap the loop and there is no way to continue processing the mailbox.

This is likely to only present when using Remote Storage adapters.

Current behavior

Exceptions are not caught, preventing writing robust looping logic.

How to reproduce

I encountered the bug reading an IMAP inbox that contained a message with a from-address that triggered an exception in loadHeaders(). https://github.com/laminas/laminas-mail/issues/45#issuecomment-588354001

Expected behavior

I'm not sure what a common paradigm for this would be. Perhaps there is a way to avoid risky routines like loadHeaders when using the Iterator?

ginkgomzd avatar Feb 19 '20 19:02 ginkgomzd