-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Mailer][Mime] Support unicode email addresses #58361
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d43b832
Add new accessors to help determine whether to use the SMTPUTF8 exten…
arnt 6f07a17
Send SMTPUTF8 if the message needs it and the server supports it.
arnt 2d74b98
Fix minor spelling error.
arnt 8597c1e
Update src/Symfony/Component/Mime/Address.php
OskarStark 3fbbb23
Resolve code review comments from stof and oska
arnt c11d6e0
Code style conformance and dependency updates.
arnt b1deef8
Reinstate the restriction that the sender's localpart must be all-ASCII.
arnt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,7 +98,7 @@ public function testSenderFromHeadersWithoutFrom() | |
$this->assertEquals($from, $e->getSender()); | ||
} | ||
|
||
public function testSenderFromHeadersWithMulitpleHeaders() | ||
public function testSenderFromHeadersWithMultipleHeaders() | ||
{ | ||
$headers = new Headers(); | ||
$headers->addMailboxListHeader('From', [new Address('[email protected]', 'from'), '[email protected]']); | ||
|
@@ -127,6 +127,19 @@ public function testRecipientsFromHeaders() | |
$this->assertEquals([new Address('[email protected]'), new Address('[email protected]'), new Address('[email protected]')], $e->getRecipients()); | ||
} | ||
|
||
public function testUnicodeLocalparts() | ||
{ | ||
/* dømi means example and is reserved by the .fo registry */ | ||
$i = new Address('info@dømi.fo'); | ||
$d = new Address('dømi@dømi.fo'); | ||
$e = new Envelope($i, [$i]); | ||
$this->assertFalse($e->anyAddressHasUnicodeLocalpart()); | ||
$e = new Envelope($i, [$d]); | ||
$this->assertTrue($e->anyAddressHasUnicodeLocalpart()); | ||
$e = new Envelope($i, [$i, $d]); | ||
$this->assertTrue($e->anyAddressHasUnicodeLocalpart()); | ||
} | ||
|
||
public function testRecipientsFromHeadersWithNames() | ||
{ | ||
$headers = new Headers(); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
namespace Symfony\Component\Mailer\Tests\Transport\Smtp; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Mailer\Exception\InvalidArgumentException; | ||
use Symfony\Component\Mailer\Exception\TransportException; | ||
use Symfony\Component\Mailer\Transport\Smtp\Auth\CramMd5Authenticator; | ||
use Symfony\Component\Mailer\Transport\Smtp\Auth\LoginAuthenticator; | ||
|
@@ -62,6 +63,53 @@ public function testExtensibility() | |
$this->assertContains("RCPT TO:<[email protected]> NOTIFY=FAILURE\r\n", $stream->getCommands()); | ||
} | ||
|
||
public function testSmtpUtf8() | ||
{ | ||
$stream = new DummyStream(); | ||
$transport = new SmtpUtf8EsmtpTransport(stream: $stream); | ||
|
||
$message = new Email(); | ||
$message->from('info@dømi.fo'); | ||
$message->addTo('dømi@dømi.fo'); | ||
$message->text('.'); | ||
|
||
$transport->send($message); | ||
|
||
$this->assertContains("MAIL FROM:<[email protected]> SMTPUTF8\r\n", $stream->getCommands()); | ||
$this->assertContains("RCPT TO:<dø[email protected]>\r\n", $stream->getCommands()); | ||
} | ||
|
||
public function testMissingSmtpUtf8() | ||
{ | ||
$stream = new DummyStream(); | ||
$transport = new EsmtpTransport(stream: $stream); | ||
|
||
$message = new Email(); | ||
$message->from('info@dømi.fo'); | ||
$message->addTo('dømi@dømi.fo'); | ||
$message->text('.'); | ||
|
||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage('Invalid addresses: non-ASCII characters not supported in local-part of email.'); | ||
$transport->send($message); | ||
} | ||
|
||
public function testSmtpUtf8FallbackToIDN() | ||
{ | ||
$stream = new DummyStream(); | ||
$transport = new EsmtpTransport(stream: $stream); | ||
|
||
$message = new Email(); | ||
$message->from('info@dømi.fo'); // UTF8 only in the domain | ||
$message->addTo('[email protected]'); | ||
$message->text('.'); | ||
|
||
$transport->send($message); | ||
|
||
$this->assertContains("MAIL FROM:<[email protected]>\r\n", $stream->getCommands()); | ||
$this->assertContains("RCPT TO:<[email protected]>\r\n", $stream->getCommands()); | ||
} | ||
|
||
public function testConstructorWithDefaultAuthenticators() | ||
{ | ||
$stream = new DummyStream(); | ||
|
@@ -270,3 +318,17 @@ public function executeCommand(string $command, array $codes): string | |
return $response; | ||
} | ||
} | ||
|
||
class SmtpUtf8EsmtpTransport extends EsmtpTransport | ||
{ | ||
public function executeCommand(string $command, array $codes): string | ||
{ | ||
$response = parent::executeCommand($command, $codes); | ||
|
||
if (str_starts_with($command, 'EHLO ')) { | ||
$response .= "250 SMTPUTF8\r\n"; | ||
} | ||
|
||
return $response; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,13 @@ public function testCreateArray() | |
$this->assertEquals([$fabien], Address::createArray(['[email protected]'])); | ||
} | ||
|
||
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); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.