Merge branch '4.3' into 4.4
* 4.3: maintain sender/recipient name in SMTP envelopes Fix #32148 TransportException was not thrown
This commit is contained in:
commit
3e8a726c41
@ -45,7 +45,7 @@ final class DelayedSmtpEnvelope extends SmtpEnvelope
|
||||
return parent::getSender();
|
||||
}
|
||||
|
||||
return new Address(self::getSenderFromHeaders($this->message->getHeaders())->getAddress());
|
||||
return self::getSenderFromHeaders($this->message->getHeaders());
|
||||
}
|
||||
|
||||
public function setRecipients(array $recipients): void
|
||||
@ -73,7 +73,7 @@ final class DelayedSmtpEnvelope extends SmtpEnvelope
|
||||
foreach (['to', 'cc', 'bcc'] as $name) {
|
||||
foreach ($headers->all($name) as $header) {
|
||||
foreach ($header->getAddresses() as $address) {
|
||||
$recipients[] = new Address($address->getAddress());
|
||||
$recipients[] = $address;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,19 +57,19 @@ class SmtpEnvelopeTest extends TestCase
|
||||
$headers->addPathHeader('Return-Path', new Address('return@symfony.com', 'return'));
|
||||
$headers->addMailboxListHeader('To', ['from@symfony.com']);
|
||||
$e = SmtpEnvelope::create(new Message($headers));
|
||||
$this->assertEquals('return@symfony.com', $e->getSender()->getAddress());
|
||||
$this->assertEquals(new Address('return@symfony.com', 'return'), $e->getSender());
|
||||
|
||||
$headers = new Headers();
|
||||
$headers->addMailboxHeader('Sender', new Address('sender@symfony.com', 'sender'));
|
||||
$headers->addMailboxListHeader('To', ['from@symfony.com']);
|
||||
$e = SmtpEnvelope::create(new Message($headers));
|
||||
$this->assertEquals('sender@symfony.com', $e->getSender()->getAddress());
|
||||
$this->assertEquals(new Address('sender@symfony.com', 'sender'), $e->getSender());
|
||||
|
||||
$headers = new Headers();
|
||||
$headers->addMailboxListHeader('From', [new Address('from@symfony.com', 'from'), 'some@symfony.com']);
|
||||
$headers->addMailboxListHeader('To', ['from@symfony.com']);
|
||||
$e = SmtpEnvelope::create(new Message($headers));
|
||||
$this->assertEquals('from@symfony.com', $e->getSender()->getAddress());
|
||||
$this->assertEquals(new Address('from@symfony.com', 'from'), $e->getSender());
|
||||
}
|
||||
|
||||
public function testSenderFromHeadersWithoutFrom()
|
||||
@ -78,10 +78,21 @@ class SmtpEnvelopeTest extends TestCase
|
||||
$headers->addMailboxListHeader('To', ['from@symfony.com']);
|
||||
$e = SmtpEnvelope::create($message = new Message($headers));
|
||||
$message->getHeaders()->addMailboxListHeader('From', [new Address('from@symfony.com', 'from')]);
|
||||
$this->assertEquals('from@symfony.com', $e->getSender()->getAddress());
|
||||
$this->assertEquals(new Address('from@symfony.com', 'from'), $e->getSender());
|
||||
}
|
||||
|
||||
public function testRecipientsFromHeaders()
|
||||
{
|
||||
$headers = new Headers();
|
||||
$headers->addPathHeader('Return-Path', 'return@symfony.com');
|
||||
$headers->addMailboxListHeader('To', [new Address('to@symfony.com')]);
|
||||
$headers->addMailboxListHeader('Cc', [new Address('cc@symfony.com')]);
|
||||
$headers->addMailboxListHeader('Bcc', [new Address('bcc@symfony.com')]);
|
||||
$e = SmtpEnvelope::create(new Message($headers));
|
||||
$this->assertEquals([new Address('to@symfony.com'), new Address('cc@symfony.com'), new Address('bcc@symfony.com')], $e->getRecipients());
|
||||
}
|
||||
|
||||
public function testRecipientsFromHeadersWithNames()
|
||||
{
|
||||
$headers = new Headers();
|
||||
$headers->addPathHeader('Return-Path', 'return@symfony.com');
|
||||
@ -89,7 +100,7 @@ class SmtpEnvelopeTest extends TestCase
|
||||
$headers->addMailboxListHeader('Cc', [new Address('cc@symfony.com', 'cc')]);
|
||||
$headers->addMailboxListHeader('Bcc', [new Address('bcc@symfony.com', 'bcc')]);
|
||||
$e = SmtpEnvelope::create(new Message($headers));
|
||||
$this->assertEquals([new Address('to@symfony.com'), new Address('cc@symfony.com'), new Address('bcc@symfony.com')], $e->getRecipients());
|
||||
$this->assertEquals([new Address('to@symfony.com', 'to'), new Address('cc@symfony.com', 'cc'), new Address('bcc@symfony.com', 'bcc')], $e->getRecipients());
|
||||
}
|
||||
|
||||
public function testFromRawMessages()
|
||||
|
@ -165,9 +165,9 @@ class SmtpTransport extends AbstractTransport
|
||||
{
|
||||
try {
|
||||
$envelope = $message->getEnvelope();
|
||||
$this->doMailFromCommand($envelope->getSender()->toString());
|
||||
$this->doMailFromCommand($envelope->getSender()->getAddress());
|
||||
foreach ($envelope->getRecipients() as $recipient) {
|
||||
$this->doRcptToCommand($recipient->toString());
|
||||
$this->doRcptToCommand($recipient->getAddress());
|
||||
}
|
||||
|
||||
$this->executeCommand("DATA\r\n", [354]);
|
||||
|
@ -41,7 +41,7 @@ abstract class AbstractStream
|
||||
$bytesToWrite = \strlen($bytes);
|
||||
$totalBytesWritten = 0;
|
||||
while ($totalBytesWritten < $bytesToWrite) {
|
||||
$bytesWritten = fwrite($this->in, substr($bytes, $totalBytesWritten));
|
||||
$bytesWritten = @fwrite($this->in, substr($bytes, $totalBytesWritten));
|
||||
if (false === $bytesWritten || 0 === $bytesWritten) {
|
||||
throw new TransportException('Unable to write bytes on the wire.');
|
||||
}
|
||||
|
Reference in New Issue
Block a user