Skip to content
Permalink
Browse files

bug #30445 [Mime] Fix generate message id with named address (Jibbarth)

This PR was squashed before being merged into the 4.3-dev branch (closes #30445).

Discussion
----------

[Mime] Fix generate message id with named address

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | yes
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #...   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        |

When using a NamedAddress in from(), the generated MessageId don't pass the validation.
In effect, the email passed to generateMessageId look like this `Fabien <fabien@symfony.com>` and the strstr transform email in this `4641b2b294b53fe983a05b1a@symfony.com>`
By passing the address only instead of toString, it's fixed.

<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
 - Bug fixes must be submitted against the lowest 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 the master branch.
-->

Commits
-------

375ac92 [Mime] Fix generate message id with named address
  • Loading branch information...
fabpot committed Mar 4, 2019
2 parents a75dd9f + 375ac92 commit 11f1660b9306521a177561c712326491b4322cc7
Showing with 11 additions and 1 deletion.
  1. +1 −1 src/Symfony/Component/Mime/Message.php
  2. +10 −0 src/Symfony/Component/Mime/Tests/MessageTest.php
@@ -97,7 +97,7 @@ public function getPreparedHeaders(): Headers
}
if (!$headers->has('Message-ID')) {
$headers->addIdHeader('Message-ID', $this->generateMessageId($sender->toString()));
$headers->addIdHeader('Message-ID', $this->generateMessageId($sender->getAddress()));
}
// remove the Bcc field which should NOT be part of the sent message
@@ -17,6 +17,7 @@
use Symfony\Component\Mime\Header\MailboxListHeader;
use Symfony\Component\Mime\Header\UnstructuredHeader;
use Symfony\Component\Mime\Message;
use Symfony\Component\Mime\NamedAddress;
use Symfony\Component\Mime\Part\TextPart;
class MessageTest extends TestCase
@@ -90,6 +91,15 @@ public function testGetPreparedHeadersWithNoFrom()
(new Message())->getPreparedHeaders();
}
public function testGetPreparedHeadersWithNamedFrom()
{
$message = new Message();
$message->getHeaders()->addMailboxListHeader('From', [new NamedAddress('fabien@symfony.com', 'Fabien')]);
$h = $message->getPreparedHeaders();
$this->assertEquals(new MailboxListHeader('From', [new NamedAddress('fabien@symfony.com', 'Fabien')]), $h->get('From'));
$this->assertTrue($h->has('Message-Id'));
}
public function testGetPreparedHeadersHasSenderWhenNeeded()
{
$message = new Message();

0 comments on commit 11f1660

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