diff --git a/Normalizer/MimeMessageNormalizer.php b/Normalizer/MimeMessageNormalizer.php index 4883e9a6..07a170d6 100644 --- a/Normalizer/MimeMessageNormalizer.php +++ b/Normalizer/MimeMessageNormalizer.php @@ -17,6 +17,7 @@ use Symfony\Component\Mime\Header\UnstructuredHeader; use Symfony\Component\Mime\Message; use Symfony\Component\Mime\Part\AbstractPart; +use Symfony\Component\Mime\RawMessage; use Symfony\Component\Serializer\Exception\LogicException; use Symfony\Component\Serializer\SerializerAwareInterface; use Symfony\Component\Serializer\SerializerInterface; @@ -74,15 +75,18 @@ public function normalize(mixed $object, ?string $format = null, array $context return $ret; } + $ret = $this->normalizer->normalize($object, $format, $context); + if ($object instanceof AbstractPart) { - $ret = $this->normalizer->normalize($object, $format, $context); $ret['class'] = $object::class; unset($ret['seekable'], $ret['cid'], $ret['handle']); + } - return $ret; + if ($object instanceof RawMessage && \array_key_exists('message', $ret) && null === $ret['message']) { + unset($ret['message']); } - return $this->normalizer->normalize($object, $format, $context); + return $ret; } public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed