Skip to content

Commit ec33c78

Browse files
committed
[Mailer] fix encoding of addresses using SmtpTransport
1 parent cccd01a commit ec33c78

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

Tests/Transport/Smtp/SmtpTransportTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,25 @@ public function testSendInvalidMessage()
114114
$this->assertNotContains("\r\n.\r\n", $stream->getCommands());
115115
$this->assertTrue($stream->isClosed());
116116
}
117+
118+
public function testWriteEncodedRecipientAndSenderAddresses()
119+
{
120+
$stream = new DummyStream();
121+
122+
$transport = new SmtpTransport($stream);
123+
124+
$message = new Email();
125+
$message->from('sender@exämple.org');
126+
$message->addTo('recipient@exämple.org');
127+
$message->addTo('recipient2@example.org');
128+
$message->text('.');
129+
130+
$transport->send($message);
131+
132+
$this->assertContains("MAIL FROM:<sender@xn--exmple-cua.org>\r\n", $stream->getCommands());
133+
$this->assertContains("RCPT TO:<recipient@xn--exmple-cua.org>\r\n", $stream->getCommands());
134+
$this->assertContains("RCPT TO:<recipient2@example.org>\r\n", $stream->getCommands());
135+
}
117136
}
118137

119138
class DummyStream extends AbstractStream

Transport/Smtp/SmtpTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ protected function doSend(SentMessage $message): void
194194

195195
try {
196196
$envelope = $message->getEnvelope();
197-
$this->doMailFromCommand($envelope->getSender()->getAddress());
197+
$this->doMailFromCommand($envelope->getSender()->getEncodedAddress());
198198
foreach ($envelope->getRecipients() as $recipient) {
199-
$this->doRcptToCommand($recipient->getAddress());
199+
$this->doRcptToCommand($recipient->getEncodedAddress());
200200
}
201201

202202
$this->executeCommand("DATA\r\n", [354]);

0 commit comments

Comments
 (0)