Skip to content
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

Headers::fromString strips local part quotes which turns it into invalid dot-atom format #250

Open
Traisuma opened this issue Aug 24, 2023 · 2 comments
Labels
Bug Something isn't working

Comments

@Traisuma
Copy link

Traisuma commented Aug 24, 2023

Bug Report

Version 2.34

Summary

When passing a valid E-Mail Headers part to the Headers#fromString method, an exception is thrown due to the fact that AbstractAddressList#fromString is stripping quotes from From E-Mail local-part.

Current behavior

Uncaught Laminas\Mail\Exception\InvalidArgumentException: 'System Administrator' can not be matched against dot-atom format.
    0.0059    1639224   2. Laminas\Mail\Headers::fromString($string = 'From: "System Administrator"@example.org', $eol = ???) /path/scratch_38.php:4
    0.0060    1640112   3. Laminas\Mail\Headers->addHeaderLine($headerFieldNameOrLine = 'From: "System Administrator"@example.org', $fieldValue = ???) /path/vendor/laminas/laminas-mail/src/Headers.php:142
    0.0060    1640112   4. Laminas\Mail\Headers->loadHeader($headerLine = 'From: "System Administrator"@example.org') /path/vendor/laminas/laminas-mail/src/Headers.php:306
    0.0065    1720376   5. Laminas\Mail\Header\AbstractAddressList::fromString($headerLine = 'From: "System Administrator"@example.org') /path/vendor/laminas/laminas-mail/src/Headers.php:572
    0.0066    1728528   6. array_map($callback = class Closure { virtual $closure = "Laminas\Mail\Header\AbstractAddressList::Laminas\Mail\Header\{closure}" }, $array = [0 => '"System Administrator"@example.org']) /path/vendor/laminas/laminas-mail/src/Header/AbstractAddressList.php:123
    0.0066    1729008   7. Laminas\Mail\Header\AbstractAddressList::Laminas\Mail\Header\{closure:/path/vendor/laminas/laminas-mail/src/Header/AbstractAddressList.php:104-122}($value = '"System Administrator"@example.org') /path/vendor/laminas/laminas-mail/src/Header/AbstractAddressList.php:123
    0.0068    1759648   8. Laminas\Mail\Address::fromString($address = 'System [email protected]', $comment = '') /path/vendor/laminas/laminas-mail/src/Header/AbstractAddressList.php:121
    0.0068    1760480   9. Laminas\Mail\Address->__construct($email = 'System [email protected]', $name = NULL, $comment = '') /path/vendor/laminas/laminas-mail/src/Address.php:59

Reproduction

\Laminas\Mail\Headers::fromString('From: "System Administrator"@example.org');

By removing the quotes from the E-Mail localpart, the local part becomes invalid from a validation PoV.

Expected behavior

The local part of an address is not modified when passing headers via Headers::fromString.

@Traisuma Traisuma added the Bug Something isn't working label Aug 24, 2023
@Xerkus
Copy link
Member

Xerkus commented Aug 24, 2023

What is the full address you are trying to validate? Space is not permitted in local part unless local part is double quoted.

@boesing
Copy link
Member

boesing commented Aug 24, 2023

This issue is related to laminas-mail and is caused by

$value = preg_replace(
[
'#(?<!\\\)"(.*)(?<!\\\)"#', // quoted-text
'#\\\([\x01-\x09\x0b\x0c\x0e-\x7f])#', // quoted-pair
],
[
'\\1',
'\\1',
],
$value
);

I will move this issue accordingly.

@boesing boesing transferred this issue from laminas/laminas-validator Aug 24, 2023
@boesing boesing changed the title validateLocalPart (src/EmailAddress.php) is not working with Whitespaces Headers::fromString strips local part quotes which turns it into invalid dot-atom format Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants