Skip to content

Commit

Permalink
Create mailBody with only attachments part present
Browse files Browse the repository at this point in the history
  • Loading branch information
srsbiz authored and fabpot committed Aug 4, 2019
1 parent 85827f3 commit b500f92
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Symfony/Component/Mime/Email.php
Expand Up @@ -423,12 +423,12 @@ public function getBody(): AbstractPart
*/
private function generateBody(): AbstractPart
{
if (null === $this->text && null === $this->html) {
throw new LogicException('A message must have a text and/or an HTML part.');
[$htmlPart, $attachmentParts, $inlineParts] = $this->prepareParts();
if (null === $this->text && null === $this->html && !$attachmentParts) {
throw new LogicException('A message must have a text or an HTML part or attachments.');
}

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

if ($attachmentParts) {
$part = new MixedPart($part, ...$attachmentParts);
if ($part) {
$part = new MixedPart($part, ...$attachmentParts);
} else {
$part = new MixedPart(...$attachmentParts);
}
}

return $part;
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Mime/Tests/EmailTest.php
Expand Up @@ -284,6 +284,10 @@ public function testGenerateBody()
$e->html('html content');
$this->assertEquals(new MixedPart($html, $att), $e->getBody());

$e = new Email();
$e->attach($file);
$this->assertEquals(new MixedPart($att), $e->getBody());

$e = new Email();
$e->html('html content');
$e->text('text content');
Expand Down

0 comments on commit b500f92

Please sign in to comment.