Skip to content

Commit

Permalink
feature #58361 [Mailer][Mime] Support unicode email addresses (arnt, …
Browse files Browse the repository at this point in the history
…OskarStark)

This PR was merged into the 7.2 branch.

Discussion
----------

[Mailer][Mime] Support unicode email addresses

| Q             | A
| ------------- | ---
| Branch?       | 7.2
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| License       | MIT

This allows applications to send mail to all-Chinese email addresses, or like my test address grå`@gr`å.org. Code that uses Symfony needs no change and should experience no difference, although if the upstream MTA doesn't support it (most do by now) then an exception is thrown slightly later than before this change.

Commits
-------

b1deef8ff3 Reinstate the restriction that the sender's localpart must be all-ASCII.
c11d6e068d Code style conformance and dependency updates.
3fbbb235d6 Resolve code review comments from stof and oska
8597c1ee8d Update src/Symfony/Component/Mime/Address.php
2d74b98061 Fix minor spelling error.
6f07a17bbf Send SMTPUTF8 if the message needs it and the server supports it.
d43b8329f2 Add new accessors to help determine whether to use the SMTPUTF8 extension
  • Loading branch information
fabpot committed Oct 6, 2024
2 parents fb61771 + 6a53da3 commit ee8c613
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,24 @@ public static function createArray(array $addresses): array

return $addrs;
}

/**
* Returns true if this address' localpart contains at least one
* non-ASCII character, and false if it is only ASCII (or empty).
*
* This is a helper for Envelope, which has to decide whether to
* the SMTPUTF8 extensions (RFC 6530 and following) for any given
* message.
*
* The SMTPUTF8 extension is strictly required if any address
* contains a non-ASCII character in its localpart. If non-ASCII
* is only used in domains (e.g. horst@freiherr-von-mühlhausen.de)
* then it is possible to to send the message using IDN encoding
* instead of SMTPUTF8. The most common software will display the
* message as intended.
*/
public function hasUnicodeLocalpart(): bool
{
return (bool) preg_match('/[\x80-\xFF].*@/', $this->address);
}
}
7 changes: 7 additions & 0 deletions Tests/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ public function testCreateArray()
$this->assertEquals([$fabien], Address::createArray(['fabien@symfony.com']));
}

public function testUnicodeLocalpart()
{
/* dømi means example and is reserved by the .fo registry */
$this->assertFalse((new Address('info@dømi.fo'))->hasUnicodeLocalpart());
$this->assertTrue((new Address('dømi@dømi.fo'))->hasUnicodeLocalpart());
}

public function testCreateArrayWrongArg()
{
$this->expectException(\TypeError::class);
Expand Down

0 comments on commit ee8c613

Please sign in to comment.