laminas-mail
laminas-mail copied to clipboard
Problems with mailadress parsing
Example Email-header: "Foo <bar" [email protected]
Description: The example email-header should be valid according to https://tools.ietf.org/html/rfc2822#section-3.4 but the function AdressList.php/addFromString matches it incorrect. The result has the following form: "bar <[email protected]" This is clearly not a valid adress and therefore causes exceptions in the following code
Solution: Changing the regex in the addFromString function from lazzy to greedy by removing "?" from the named capture group "name"
- old: ^((?P.*?)<(?P[^>]+)>|(?P.+))$
- new: ^((?P.*)<(?P[^>]+)>|(?P.+))$
Originally posted by @Baztey at https://github.com/zendframework/zend-mail/issues/127
@Baztey created PR based on your comments, including tests: https://github.com/zendframework/zend-mail/pull/143
however, it needs more fixes, because encoding back creates invalid result.
btw, your bugreport here has lost <>
, use markdown code blocks to preserve them.
Originally posted by @glensc at https://github.com/zendframework/zend-mail/issues/127#issuecomment-301312488
Let me know if I should create a new issue... this is topical, but probably different code.
I'm reading messages (from an IMAP inbox) and when getting $msg->from
an InvalidArgumentException is generated for an address with a hostname with a subdomain e.g.
Discover Card <[email protected]>
[19-Feb-2020 17:22:51 UTC] PHP Fatal error: Uncaught Laminas\Mail\Exception\InvalidArgumentException: The input is not a valid email address. Use the basic format local-part@hostname in.../vendor/laminas/laminas-mail/src/Address.php:78
Stack trace:
#0 .../vendor/laminas/laminas-mail/src/Header/Sender.php(132): Laminas\Mail\Address->__construct('service.discove...', NULL)
#1 .../vendor/laminas/laminas-mail/src/Header/Sender.php(67): Laminas\Mail\Header\Sender->setAddress('service.discove...', NULL)
#2 .../vendor/laminas/laminas-mail/src/Headers.php(485): Laminas\Mail\Header\Sender::fromString('Sender: service...')
#3 .../vendor/laminas/laminas-mail/src/Headers.php(232): Laminas\Mail\Headers->loadHeader('Sender: service...')
#4 .../vendor/laminas/laminas-mail/src/H in .../vendor/laminas/laminas-mail/src/Address.php on line 78