laminas / laminas-mail

Provides generalized functionality to compose and send both text and MIME-compliant multipart e-mail messages
https://docs.laminas.dev/laminas-mail/
BSD 3-Clause "New" or "Revised" License
93 stars 64 forks source link

Throwing email invalid exception on the email from field of emails being read from an IMAP server #4

Open weierophinney opened 4 years ago

weierophinney commented 4 years ago

I am attempting to read bounced emails and mark the address as bouncy.

Code to reproduce the issue

        //connect to the mail server
        $mail = new Imap([
            'host'     => 'REDACTED',
            'port'     => '993',
            'user'     => 'REDACTED',
            'password' => 'REDACTED',
            'ssl'      => 'SSL'
        ]);

        //open the bounced folder
        $folder = $mail->getFolders()->Bounced;
        $mail->selectFolder($folder);

        //will throw an Exception: The input is not a valid email address. Use the basic format local-part@hostname /vendor/zendframework/zend-mail/src/Address.php 77 if it encounters an email from "MAILER-DAEMON@messagingengine.com" - it will wrongly interpret the email address as simply "MAILER-DAEMON"
        foreach ($mail as $messageNum => $message) {
        }

Expected results

When trying to parse a fairly standard bounced email that comes from MAILER-DAEMON@messagingengine.com it will throw an exception stating that MAILER-DAEMON is not a valid email address.

I suppose it should parse the email from address properly... or perhaps it should have an option to ignore these types of exceptions - since we are not constructing an email, and are simply parsing an email that exists on an actual email server it doesn't make much sense to throw an interrupting exception stating that the email is invalid, when it is in fact a real email that exists on a real mailserver. Since the exception is encountered during a foreach iteration it's not even an option to simply catch and ignore the exception.

Actual results

Exception: The input is not a valid email address. Use the basic format local-part@hostname /vendor/zendframework/zend-mail/src/Address.php 77


Originally posted by @ibindoff at https://github.com/zendframework/zend-mail/issues/248

abulhol commented 1 month ago

I get the same error due to a To: header that looks like this: To: Undisclosed@xyz.default, recipients: