Skip to content

Commit 68ffeba

Browse files
committed
bug #54837 [Mailer] [Sendgrid] Use DataPart::getContentId() when DataPart::setContentId() is used (SherinBloemendaal)
This PR was merged into the 6.4 branch. Discussion ---------- [Mailer] [Sendgrid] Use `DataPart::getContentId()` when `DataPart::setContentId()` is used | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | See bellow | License | MIT Fixes the content identifier set via `DataPart::setContentId()` not being respected. Instead the `$filename` of the `DataPart` was being used resulting in unexpected behaviour. To provide backwards compatibility the `DataPart::hasContentId()` is being used to keep the current behaviour. Applied to 6.4 since `DataPart::setContentId()` was introduced in 6.2. Commits ------- 1211fbe [Mailer] [Sendgrid] Use DataPart::getContentId() when DataPart::setContentId() is used.
2 parents 202199b + 1211fbe commit 68ffeba

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/Transport/SendgridApiTransportTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,45 @@ public function testTagAndMetadataHeaders()
245245
$this->assertSame('blue', $payload['personalizations'][0]['custom_args']['Color']);
246246
$this->assertSame('12345', $payload['personalizations'][0]['custom_args']['Client-ID']);
247247
}
248+
249+
public function testInlineWithCustomContentId()
250+
{
251+
$imagePart = (new DataPart('text-contents', 'text.txt'));
252+
$imagePart->asInline();
253+
$imagePart->setContentId('content-identifier@symfony');
254+
255+
$email = new Email();
256+
$email->addPart($imagePart);
257+
$envelope = new Envelope(new Address('alice@system.com'), [new Address('bob@system.com')]);
258+
259+
$transport = new SendgridApiTransport('ACCESS_KEY');
260+
$method = new \ReflectionMethod(SendgridApiTransport::class, 'getPayload');
261+
$payload = $method->invoke($transport, $email, $envelope);
262+
263+
$this->assertArrayHasKey('attachments', $payload);
264+
$this->assertCount(1, $payload['attachments']);
265+
$this->assertArrayHasKey('content_id', $payload['attachments'][0]);
266+
267+
$this->assertSame('content-identifier@symfony', $payload['attachments'][0]['content_id']);
268+
}
269+
270+
public function testInlineWithoutCustomContentId()
271+
{
272+
$imagePart = (new DataPart('text-contents', 'text.txt'));
273+
$imagePart->asInline();
274+
275+
$email = new Email();
276+
$email->addPart($imagePart);
277+
$envelope = new Envelope(new Address('alice@system.com'), [new Address('bob@system.com')]);
278+
279+
$transport = new SendgridApiTransport('ACCESS_KEY');
280+
$method = new \ReflectionMethod(SendgridApiTransport::class, 'getPayload');
281+
$payload = $method->invoke($transport, $email, $envelope);
282+
283+
$this->assertArrayHasKey('attachments', $payload);
284+
$this->assertCount(1, $payload['attachments']);
285+
$this->assertArrayHasKey('content_id', $payload['attachments'][0]);
286+
287+
$this->assertSame('text.txt', $payload['attachments'][0]['content_id']);
288+
}
248289
}

src/Symfony/Component/Mailer/Bridge/Sendgrid/Transport/SendgridApiTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ private function getAttachments(Email $email): array
179179
];
180180

181181
if ('inline' === $disposition) {
182-
$att['content_id'] = $filename;
182+
$att['content_id'] = $attachment->hasContentId() ? $attachment->getContentId() : $filename;
183183
}
184184

185185
$attachments[] = $att;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy