Skip to content

Commit

Permalink
bug #48313 [Mime] Fix MessagePart serialization
Browse files Browse the repository at this point in the history
Fixes #48313
  • Loading branch information
Amunak authored and nicolas-grekas committed Dec 13, 2022
1 parent 2c24bbc commit 8cb094c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Symfony/Component/Mime/Part/MessagePart.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,17 @@ public function bodyToIterable(): iterable
{
return $this->message->toIterable();
}

/**
* @return array
*/
public function __sleep()
{
return ['message'];
}

public function __wakeup()
{
$this->__construct($this->message);
}
}
10 changes: 10 additions & 0 deletions src/Symfony/Component/Mime/Tests/Part/MessagePartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,14 @@ public function testHeaders()
new ParameterizedHeader('Content-Disposition', 'attachment', ['name' => 'Subject.eml', 'filename' => 'Subject.eml'])
), $p->getPreparedHeaders());
}

public function testSerialize()
{
$email = (new Email())->from('fabien@symfony.com')->to('you@example.com')->text('content');
$email->getHeaders()->addIdHeader('Message-ID', $email->generateMessageId());

$p = new MessagePart($email);
$expected = clone $p;
$this->assertEquals($expected->toString(), unserialize(serialize($p))->toString());
}
}

0 comments on commit 8cb094c

Please sign in to comment.