Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Allow non-strict email address validation #83

Open
davidwindell opened this issue Apr 20, 2016 · 6 comments
Open

Allow non-strict email address validation #83

davidwindell opened this issue Apr 20, 2016 · 6 comments

Comments

@davidwindell
Copy link
Contributor

Add ability to specify whether EmailAddressValidator used by AddressList should validate the email with the strict flag set or not.

@steffenweber
Copy link
Contributor

This would be very useful. I'm using Zend-Mail to parse emails that arrive in an inbox and therefore have no control over their header values. When calling Zend\Mail\Storage\Imap->getMessage() an Exception is thrown from deep inside the Zend Framework if the Return-Path header contains a long address:

Fatal error: Uncaught Zend\Mail\Exception\InvalidArgumentException: The input exceeds the allowed length in vendor/zendframework/zend-mail/src/Address.php:41
Stack trace:
#0 vendor/zendframework/zend-mail/src/AddressList.php(249): Zend\Mail\Address->__construct('...', NULL)
#1 vendor/zendframework/zend-mail/src/AddressList.php(35): Zend\Mail\AddressList->createAddress('...', NULL)
#2 vendor/zendframework/zend-mail/src/AddressList.php(113): Zend\Mail\AddressList->add('...', NULL)
#3 vendor/zendframework/zend-mail/src/Header/AbstractAddressList.php(87): Zend\Mail\AddressList->addFromString('...')
#4 vendor/zendframework/zend-mail/src/Headers.php(482): Zend\Mail\Header\AbstractAddressList::fromString('To: ...')
#5 vendor/zendframework/zend-mail/src/Headers.php(231): Zend\Mail\Headers->loadHeader('To: ...')
#6 vendor/zendframework/zend-mail/src/Headers.php(95): Zend\Mail\Headers->addHeaderLine('To: ...')
#7 vendor/zendframework/zend-mime/src/Decode.php(142): Zend\Mail\Headers::fromString('Return-Path: ...', '\n')
#8 vendor/zendframework/zend-mail/src/Storage/Part.php(112): Zend\Mime\Decode::splitMessage('Return-Path: ...', 'Return-Path: ...', '')
#9 vendor/zendframework/zend-mail/src/Storage/Message.php(54): Zend\Mail\Storage\Part->__construct(Array)
#10 vendor/zendframework/zend-mail/src/Storage/Imap.php(128): Zend\Mail\Storage\Message->__construct(Array)
#11 mycode.php(31): Zend\Mail\Storage\Imap->getMessage(18)

A quick and dirty solution would be to add some static method like setStrictMode to the EmailAddress class. Any better ideas?

@kaero598
Copy link

I completely agree with @steffenweber. We use Zend Mail along with Zend Mime to parse bounce reports. And those often contain something like Return-Path: <> which triggers exception in AddressList.

@svaningelgem
Copy link

+1

@DominikTo
Copy link

DominikTo commented Sep 5, 2018

Similar issue here. When iterating over an inbox (where you don't have control over the messages in there), I am e.g. running into Uncaught Zend\Mail\Exception\InvalidArgumentException: 'example.org ()' is not a valid hostname for the email address in zendframework/zend-mail/src/Address.php:77.

In my case the To header contains this garbage: To: user@example.org ().

Is there a good way to work around this? I'd guess that almost every "real life" inbox contains mails with such unexpected headers, which makes it almost impossible to iterate over an inbox.

mickael-moreau added a commit to Monwoo/MoonBox that referenced this issue Jan 15, 2019
@Monwoo
Copy link

Monwoo commented Jan 15, 2019

Hello, I did solve it with Validator quick fix for Moon Box. Cf : Monwoo/MoonBox@0636a95#diff-1a8dca4bf22bff2976d4f1eac7e2f50f

Use composer Autoload feature to quick fix vendors files :
"autoload": { "files": [ "vendorFixies/zend-validator/EmailAddress.php" ] },
=> Monwoo/MoonBox@0636a95#diff-1a8dca4bf22bff2976d4f1eac7e2f50fL16

Then, allow validation on failing case ('<>' for my case) :

...
    public function isValid($value)
    {
        if (! is_string($value)) {
            $this->error(self::INVALID);
            return false;
        }
        if ('<>' === $value) {
            // https://github.com/zendframework/zend-mail/issues/83
            // + add to your composer :
            // https://stackoverflow.com/questions/28104574/strategy-to-override-a-class-in-a-library-installed-with-composer
            return true;
        }
...

=> Monwoo/MoonBox@0636a95#diff-54278b9d8fed58a67d9f6b35ad65321dR525

@michalbundyra
Copy link
Member

This repository has been closed and moved to laminas/laminas-mail; a new issue has been opened at laminas/laminas-mail#64.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants