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

b500f92921 Create mailBody with only attachments part present
This commit is contained in:
Fabien Potencier 2019-08-04 14:19:33 +02:00
commit 8b699ae8a8
2 changed files with 12 additions and 4 deletions

View File

@ -423,12 +423,12 @@ class Email extends Message
*/
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);
@ -442,7 +442,11 @@ class Email extends Message
}
if ($attachmentParts) {
$part = new MixedPart($part, ...$attachmentParts);
if ($part) {
$part = new MixedPart($part, ...$attachmentParts);
} else {
$part = new MixedPart(...$attachmentParts);
}
}
return $part;

View File

@ -284,6 +284,10 @@ class EmailTest extends TestCase
$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');