|
12 | 12 | namespace Symfony\Component\Mailer\Tests\Transport\Smtp;
|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
| 15 | +use Symfony\Component\Mailer\Exception\InvalidArgumentException; |
15 | 16 | use Symfony\Component\Mailer\Exception\TransportException;
|
16 | 17 | use Symfony\Component\Mailer\Transport\Smtp\Auth\CramMd5Authenticator;
|
17 | 18 | use Symfony\Component\Mailer\Transport\Smtp\Auth\LoginAuthenticator;
|
@@ -62,6 +63,53 @@ public function testExtensibility()
|
62 | 63 | $this-> assertContains( "RCPT TO:<[email protected]> NOTIFY=FAILURE\r\n", $stream-> getCommands());
|
63 | 64 | }
|
64 | 65 |
|
| 66 | + public function testSmtpUtf8() |
| 67 | + { |
| 68 | + $stream = new DummyStream(); |
| 69 | + $transport = new SmtpUtf8EsmtpTransport(stream: $stream); |
| 70 | + |
| 71 | + $message = new Email(); |
| 72 | + $message->from('info@dømi.fo'); |
| 73 | + $message->addTo('dømi@dømi.fo'); |
| 74 | + $message->text('.'); |
| 75 | + |
| 76 | + $transport->send($message); |
| 77 | + |
| 78 | + $this-> assertContains( "MAIL FROM:<[email protected]> SMTPUTF8\r\n", $stream-> getCommands()); |
| 79 | + $this-> assertContains( "RCPT TO:<dø[email protected]>\r\n", $stream-> getCommands()); |
| 80 | + } |
| 81 | + |
| 82 | + public function testMissingSmtpUtf8() |
| 83 | + { |
| 84 | + $stream = new DummyStream(); |
| 85 | + $transport = new EsmtpTransport(stream: $stream); |
| 86 | + |
| 87 | + $message = new Email(); |
| 88 | + $message->from('info@dømi.fo'); |
| 89 | + $message->addTo('dømi@dømi.fo'); |
| 90 | + $message->text('.'); |
| 91 | + |
| 92 | + $this->expectException(InvalidArgumentException::class); |
| 93 | + $this->expectExceptionMessage('Invalid addresses: non-ASCII characters not supported in local-part of email.'); |
| 94 | + $transport->send($message); |
| 95 | + } |
| 96 | + |
| 97 | + public function testSmtpUtf8FallbackToIDN() |
| 98 | + { |
| 99 | + $stream = new DummyStream(); |
| 100 | + $transport = new EsmtpTransport(stream: $stream); |
| 101 | + |
| 102 | + $message = new Email(); |
| 103 | + $message->from('info@dømi.fo'); // UTF8 only in the domain |
| 104 | + $message-> addTo( '[email protected]'); |
| 105 | + $message->text('.'); |
| 106 | + |
| 107 | + $transport->send($message); |
| 108 | + |
| 109 | + $this-> assertContains( "MAIL FROM:<[email protected]>\r\n", $stream-> getCommands()); |
| 110 | + $this-> assertContains( "RCPT TO:<[email protected]>\r\n", $stream-> getCommands()); |
| 111 | + } |
| 112 | + |
65 | 113 | public function testConstructorWithDefaultAuthenticators()
|
66 | 114 | {
|
67 | 115 | $stream = new DummyStream();
|
@@ -270,3 +318,17 @@ public function executeCommand(string $command, array $codes): string
|
270 | 318 | return $response;
|
271 | 319 | }
|
272 | 320 | }
|
| 321 | + |
| 322 | +class SmtpUtf8EsmtpTransport extends EsmtpTransport |
| 323 | +{ |
| 324 | + public function executeCommand(string $command, array $codes): string |
| 325 | + { |
| 326 | + $response = parent::executeCommand($command, $codes); |
| 327 | + |
| 328 | + if (str_starts_with($command, 'EHLO ')) { |
| 329 | + $response .= "250 SMTPUTF8\r\n"; |
| 330 | + } |
| 331 | + |
| 332 | + return $response; |
| 333 | + } |
| 334 | +} |
0 commit comments