8000 Fix email attachment unserialization · symfony/symfony@c9408c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit c9408c1

Browse files
committed
Fix email attachment unserialization
1 parent 7c87798 commit c9408c1

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/Symfony/Component/Mime/Part/DataPart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function __wakeup()
156156
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
157157
}
158158
foreach (['body', 'charset', 'subtype', 'disposition', 'name', 'encoding'] as $name) {
159-
if (null !== $this->_parent[$name] && !\is_string($this->_parent[$name])) {
159+
if (null !== $this->_parent[$name] && !\is_string($this->_parent[$name]) && !$this->_parent[$name] instanceof File) {
160160
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
161161
}
162162
$r = new \ReflectionProperty(TextPart::class, $name);

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,16 +662,30 @@ public function testBodyCache()
662662
public function testAttachmentBodyIsPartOfTheSerializationEmailPayloadWhenUsingAttachMethod()
663663
{
664664
$email = new Email();
665-
$email->attach(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'foo_attachment.txt') ?: '');
665+
$email->attach(file_get_contents(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'foo_attachment.txt') ?: '');
666666

667667
$this->assertTrue(str_contains(serialize($email), 'foo_bar_xyz_123'));
668668
}
669669

670670
public function testAttachmentBodyIsNotPartOfTheSerializationEmailPayloadWhenUsingAttachFromPathMethod()
671671
{
672672
$email = new Email();
673-
$email->attachFromPath(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'foo_attachment.txt');
673+
$email->attachFromPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'foo_attachment.txt');
674674

675675
$this->assertFalse(str_contains(serialize($email), 'foo_bar_xyz_123'));
676676
}
677+
678+
public function testEmailsWithAttachmentsWhichAreAFileInstanceCanBeUnserialized()
679+
{
680+
$email = new Email();
681+
$email->attachFromPath(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'foo_attachment.txt');
682+
683+
$email = unserialize(serialize($email));
684+
$this->assertInstanceOf(Email::class, $email);
685+
686+
$attachments = $email->getAttachments();
687+
688+
$this->assertCount(1, $attachments);
689+
$this->assertStringContainsString('foo_bar_xyz_123', $attachments[0]->getBody());
690+
}
677691
}

0 commit comments

Comments
 (0)
0