|
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,37 @@ 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 | + |
65 | 97 | public function testConstructorWithDefaultAuthenticators()
|
66 | 98 | {
|
67 | 99 | $stream = new DummyStream();
|
@@ -270,3 +302,17 @@ public function executeCommand(string $command, array $codes): string
|
270 | 302 | return $response;
|
271 | 303 | }
|
272 | 304 | }
|
| 305 | + |
| 306 | +class Smtputf8EsmtpTransport extends EsmtpTransport |
| 307 | +{ |
| 308 | + public function executeCommand(string $command, array $codes): string |
| 309 | + { |
| 310 | + $response = parent::executeCommand($command, $codes); |
| 311 | + |
| 312 | + if (str_starts_with($command, 'EHLO ')) { |
| 313 | + $response .= "250 SMTPUTF8\r\n"; |
| 314 | + } |
| 315 | + |
| 316 | + return $response; |
| 317 | + } |
| 318 | +} |
0 commit comments