Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Symfony/Component/Mime/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.3
---

* Support detection of related parts if `Content-Id` is used instead of the name

6.2
---

Expand Down
6 changes: 4 additions & 2 deletions src/Symfony/Component/Mime/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,14 +492,16 @@ private function prepareParts(): ?array
$otherParts = $relatedParts = [];
foreach ($this->attachments as $part) {
foreach ($names as $name) {
if ($name !== $part->getName()) {
if ($name !== $part->getName() && (!$part->hasContentId() || $name !== $part->getContentId())) {
continue;
}
if (isset($relatedParts[$name])) {
continue 2;
}

$html = str_replace('cid:'.$name, 'cid:'.$part->getContentId(), $html, $count);
if ($name !== $part->getContentId()) {
$html = str_replace('cid:'.$name, 'cid:'.$part->getContentId(), $html, $count);
}
$relatedParts[$name] = $part;
$part->setName($part->getContentId())->asInline();

Expand Down
18 changes: 18 additions & 0 deletions src/Symfony/Component/Mime/Tests/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,24 @@ public function testGenerateBodyWithTextAndHtmlAndAttachedFileAndAttachedImageRe
$this->assertStringContainsString('cid:'.$parts[1]->getContentId(), $generatedHtml->getBody());
}

public function testGenerateBodyWithTextAndHtmlAndAttachedFileAndAttachedImageReferencedViaCidAndContentId()
{
[$text, $html, $filePart, $file, $imagePart, $image] = $this->generateSomeParts();
$e = (new Email())->from('me@example.com')->to('you@example.com');
$e->text('text content');
$e->addPart(new DataPart($file));
$img = new DataPart($image, 'test.gif');
$e->addPart($img);
$e->html($content = 'html content <img src="cid:'.$img->getContentId().'">');
$body = $e->getBody();
$this->assertInstanceOf(MixedPart::class, $body);
$this->assertCount(2, $related = $body->getParts());
$this->assertInstanceOf(RelatedPart::class, $related[0]);
$this->assertEquals($filePart, $related[1]);
$this->assertCount(2, $parts = $related[0]->getParts());
$this->assertInstanceOf(AlternativePart::class, $parts[0]);
}

public function testGenerateBodyWithHtmlAndInlinedImageTwiceReferencedViaCid()
{
// inline image (twice) referenced in the HTML content
Expand Down