Skip to content
Permalink
Browse files

bug #31992 Fix sender/recipients in SMTP Envelope (fabpot)

This PR was merged into the 4.3 branch.

Discussion
----------

Fix sender/recipients in SMTP Envelope

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #31986
| License       | MIT
| Doc PR        | n/a

<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/roadmap):
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against branch 4.4.
 - Legacy code removals go to the master branch.
-->

Commits
-------

7a2f9bf fixed sender/recipients in SMTP Envelope
  • Loading branch information...
fabpot committed Jun 12, 2019
2 parents 41ff9d3 + 7a2f9bf commit 1c1d6d9edf3e51838e03b3404d1d8b7f2edd0e75
@@ -47,7 +47,7 @@ public function getSender(): Address
return parent::getSender();
}
return self::getSenderFromHeaders($this->message->getHeaders());
return new Address(self::getSenderFromHeaders($this->message->getHeaders())->getAddress());
}
public function setRecipients(array $recipients): void
@@ -74,7 +74,9 @@ private static function getRecipientsFromHeaders(Headers $headers): array
$recipients = [];
foreach (['to', 'cc', 'bcc'] as $name) {
foreach ($headers->getAll($name) as $header) {
$recipients = array_merge($recipients, $header->getAddresses());
foreach ($header->getAddresses() as $address) {
$recipients[] = new Address($address->getAddress());
}
}
}
@@ -17,7 +17,6 @@
use Symfony\Component\Mime\Header\Headers;
use Symfony\Component\Mime\Message;
use Symfony\Component\Mime\NamedAddress;
use Symfony\Component\Mime\RawMessage;
class SmtpEnvelopeTest extends TestCase
{
@@ -54,19 +53,19 @@ public function testConstructorWithWrongRecipients()
public function testSenderFromHeaders()
{
$headers = new Headers();
$headers->addPathHeader('Return-Path', 'return@symfony.com');
$headers->addPathHeader('Return-Path', new NamedAddress('return@symfony.com', 'return'));
$headers->addMailboxListHeader('To', ['from@symfony.com']);
$e = SmtpEnvelope::create(new Message($headers));
$this->assertEquals('return@symfony.com', $e->getSender()->getAddress());
$headers = new Headers();
$headers->addMailboxHeader('Sender', 'sender@symfony.com');
$headers->addMailboxHeader('Sender', new NamedAddress('sender@symfony.com', 'sender'));
$headers->addMailboxListHeader('To', ['from@symfony.com']);
$e = SmtpEnvelope::create(new Message($headers));
$this->assertEquals('sender@symfony.com', $e->getSender()->getAddress());
$headers = new Headers();
$headers->addMailboxListHeader('From', ['from@symfony.com', 'some@symfony.com']);
$headers->addMailboxListHeader('From', [new NamedAddress('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());
@@ -77,17 +76,17 @@ public function testSenderFromHeadersWithoutFrom()
$headers = new Headers();
$headers->addMailboxListHeader('To', ['from@symfony.com']);
$e = SmtpEnvelope::create($message = new Message($headers));
$message->getHeaders()->addMailboxListHeader('From', ['from@symfony.com']);
$message->getHeaders()->addMailboxListHeader('From', [new NamedAddress('from@symfony.com', 'from')]);
$this->assertEquals('from@symfony.com', $e->getSender()->getAddress());
}
public function testRecipientsFromHeaders()
{
$headers = new Headers();
$headers->addPathHeader('Return-Path', 'return@symfony.com');
$headers->addMailboxListHeader('To', ['to@symfony.com']);
$headers->addMailboxListHeader('Cc', ['cc@symfony.com']);
$headers->addMailboxListHeader('Bcc', ['bcc@symfony.com']);
$headers->addMailboxListHeader('To', [new NamedAddress('to@symfony.com', 'to')]);
$headers->addMailboxListHeader('Cc', [new NamedAddress('cc@symfony.com', 'cc')]);
$headers->addMailboxListHeader('Bcc', [new NamedAddress('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());
}

0 comments on commit 1c1d6d9

Please sign in to comment.
You can’t perform that action at this time.