Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc09342e

Browse files
committed
bug#59598 [Mime] Fix body validity check inEmail when usingMessage::setBody() (alexandre-daubois)
This PR was merged into the 6.4 branch.Discussion----------[Mime] Fix body validity check in `Email` when using `Message::setBody()`| Q | A| ------------- | ---| Branch? | 6.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Issues |Fix#59582| License | MITCommits-------b983d1b [Mime] Fix body validity check in `Email` when using `Message::setBody()`
2 parentsb6f477c +b983d1b commitc09342e

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

‎src/Symfony/Component/Mime/Email.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ public function ensureValidity()
416416

417417
privatefunctionensureBodyValid():void
418418
{
419-
if (null ===$this->text &&null ===$this->html && !$this->attachments) {
419+
if (null ===$this->text &&null ===$this->html && !$this->attachments &&null ===parent::getBody()) {
420420
thrownewLogicException('A message must have a text or an HTML part or attachments.');
421421
}
422422
}

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,4 +695,60 @@ public function testEmailsWithAttachmentsWhichAreAFileInstanceCanBeUnserialized(
695695
$this->assertCount(1,$attachments);
696696
$this->assertStringContainsString('foo_bar_xyz_123',$attachments[0]->getBody());
697697
}
698+
699+
publicfunctiontestInvalidBodyWithEmptyEmail()
700+
{
701+
$this->expectException(\LogicException::class);
702+
$this->expectExceptionMessage('A message must have a text or an HTML part or attachments.');
703+
704+
(newEmail())->ensureValidity();
705+
}
706+
707+
publicfunctiontestBodyWithTextIsValid()
708+
{
709+
$email =newEmail();
710+
$email->to('test@example.com')
711+
->from('test@example.com')
712+
->text('foo');
713+
714+
$email->ensureValidity();
715+
716+
$this->expectNotToPerformAssertions();
717+
}
718+
719+
publicfunctiontestBodyWithHtmlIsValid()
720+
{
721+
$email =newEmail();
722+
$email->to('test@example.com')
723+
->from('test@example.com')
724+
->html('foo');
725+
726+
$email->ensureValidity();
727+
728+
$this->expectNotToPerformAssertions();
729+
}
730+
731+
publicfunctiontestEmptyBodyWithAttachmentsIsValid()
732+
{
733+
$email =newEmail();
734+
$email->to('test@example.com')
735+
->from('test@example.com')
736+
->addPart(newDataPart('foo'));
737+
738+
$email->ensureValidity();
739+
740+
$this->expectNotToPerformAssertions();
741+
}
742+
743+
publicfunctiontestSetBodyIsValid()
744+
{
745+
$email =newEmail();
746+
$email->to('test@example.com')
747+
->from('test@example.com')
748+
->setBody(newTextPart('foo'));
749+
750+
$email->ensureValidity();
751+
752+
$this->expectNotToPerformAssertions();
753+
}
698754
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp