Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 68ffeba

Browse filesBrowse 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
Copy full SHA for 68ffeba

File tree

2 files changed

+42
-1
lines changed
Filter options

2 files changed

+42
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/Transport/SendgridApiTransportTest.php
+41Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Bridge/Sendgrid/Transport/SendgridApiTransport.php
+1-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.