Skip to content

Commit ee8c613

Browse files
committed
feature #58361 [Mailer][Mime] Support unicode email addresses (arnt, 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
2 parents fb61771 + 6a53da3 commit ee8c613

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Address.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,24 @@ public static function createArray(array $addresses): array
117117

118118
return $addrs;
119119
}
120+
121+
/**
122+
* Returns true if this address' localpart contains at least one
123+
* non-ASCII character, and false if it is only ASCII (or empty).
124+
*
125+
* This is a helper for Envelope, which has to decide whether to
126+
* the SMTPUTF8 extensions (RFC 6530 and following) for any given
127+
* message.
128+
*
129+
* The SMTPUTF8 extension is strictly required if any address
130+
* contains a non-ASCII character in its localpart. If non-ASCII
131+
* is only used in domains (e.g. horst@freiherr-von-mühlhausen.de)
132+
* then it is possible to to send the message using IDN encoding
133+
* instead of SMTPUTF8. The most common software will display the
134+
* message as intended.
135+
*/
136+
public function hasUnicodeLocalpart(): bool
137+
{
138+
return (bool) preg_match('/[\x80-\xFF].*@/', $this->address);
139+
}
120140
}

Tests/AddressTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ public function testCreateArray()
8181
$this->assertEquals([$fabien], Address::createArray(['[email protected]']));
8282
}
8383

84+
public function testUnicodeLocalpart()
85+
{
86+
/* dømi means example and is reserved by the .fo registry */
87+
$this->assertFalse((new Address('info@dømi.fo'))->hasUnicodeLocalpart());
88+
$this->assertTrue((new Address('dømi@dømi.fo'))->hasUnicodeLocalpart());
89+
}
90+
8491
public function testCreateArrayWrongArg()
8592
{
8693
$this->expectException(\TypeError::class);

0 commit comments

Comments
 (0)