You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.2 KiB

3 years ago
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Mime\Part;
  11. use Symfony\Component\Mime\Message;
  12. use Symfony\Component\Mime\RawMessage;
  13. /**
  14. * @final
  15. *
  16. * @author Fabien Potencier <fabien@symfony.com>
  17. */
  18. class MessagePart extends DataPart
  19. {
  20. private $message;
  21. public function __construct(RawMessage $message)
  22. {
  23. if ($message instanceof Message) {
  24. $name = $message->getHeaders()->getHeaderBody('Subject').'.eml';
  25. } else {
  26. $name = 'email.eml';
  27. }
  28. parent::__construct('', $name);
  29. $this->message = $message;
  30. }
  31. public function getMediaType(): string
  32. {
  33. return 'message';
  34. }
  35. public function getMediaSubtype(): string
  36. {
  37. return 'rfc822';
  38. }
  39. public function getBody(): string
  40. {
  41. return $this->message->toString();
  42. }
  43. public function bodyToString(): string
  44. {
  45. return $this->getBody();
  46. }
  47. public function bodyToIterable(): iterable
  48. {
  49. return $this->message->toIterable();
  50. }
  51. }