Navigation Menu

Skip to content

Commit

Permalink
bug #32814 Create mailBody with only attachments part present (srsbiz)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fabpot committed Aug 4, 2019
2 parents 69ef436 + b500f92 commit 8b699ae
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 8b699ae

Please sign in to comment.