8000 bug #32814 Create mailBody with only attachments part present (srsbiz) · symfony/symfony@8b699ae · GitHub
[go: up one dir, main page]

Skip to content

Commit 8b699ae

Browse files
committed
bug #32814 Create mailBody with only attachments part present (srsbiz)
This PR was squashed before being merged into the 4.3 branch (closes #32814). Discussion ---------- Create mailBody with only attachments part present | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32811 | License | MIT Commits ------- b500f92 Create mailBody with only attachments part present
2 parents 69ef436 + b500f92 commit 8b699ae

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/Symfony/Component/Mime/Email.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,12 @@ public function getBody(): AbstractPart
423423
*/
424424
private function generateBody(): AbstractPart
425425
{
426-
if (null === $this->text && null === $this->html) {
427-
throw new LogicException('A message must have a text and/or an HTML part.');
426+
[$htmlPart, $attachmentParts, $inlineParts] = $this->prepareParts();
427+
if (null === $this->text && null === $this->html && !$attachmentParts) {
428+
throw new LogicException('A message must have a text or an HTML part or attachments.');
428429
}
429430

430431
$part = null === $this->text ? null : new TextPart($this->text, $this->textCharset);
431-
[$htmlPart, $attachmentParts, $inlineParts] = $this->prepareParts();
432432
if (null !== $htmlPart) {
433433
if (null !== $part) {
434434
$part = new AlternativePart($part, $htmlPart);
@@ -442,7 +442,11 @@ private function generateBody(): AbstractPart
442442
}
443443

444444
if ($attachmentParts) {
445-
$part = new MixedPart($part, ...$attachmentParts);
445+
if ($part) {
446+
$part = new MixedPart($part, ...$attachmentParts);
447+
} else {
448+
$part = new MixedPart(...$attachmentParts);
449+
}
446450
}
447451

448452
return $part;

src/Symfony/Component/Mime/Tests/EmailTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ public function testGenerateBody()
284284
$e->html('html content');
285285
$this->assertEquals(new MixedPart($html, $att), $e->getBody());
286286

287+
$e = new Email();
288+
$e->attach($file);
289+
$this->assertEquals(new MixedPart($att), $e->getBody());
290+
287291
$e = new Email();
288292
$e->html('html content');
289293
$e->text('text content');

0 commit comments

Comments
 (0)
0