8000 [Mailer] [Sendgrid] Use DataPart::getContentId() when DataPart::setCo… · symfony/symfony@1211fbe · GitHub
[go: up one dir, main page]

Skip to content

Commit 1211fbe

Browse files
[Mailer] [Sendgrid] Use DataPart::getContentId() when DataPart::setContentId() is used.
1 parent 202199b commit 1211fbe

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

+41
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

+1-1
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