diff --git a/src/Symfony/Component/Mime/CHANGELOG.md b/src/Symfony/Component/Mime/CHANGELOG.md index 796cfdd155..0b252bd1d3 100644 --- a/src/Symfony/Component/Mime/CHANGELOG.md +++ b/src/Symfony/Component/Mime/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +4.4.0 +----- + + * Added `AbstractPart::asDebugString()` + 4.3.3 ----- diff --git a/src/Symfony/Component/Mime/Part/AbstractMultipartPart.php b/src/Symfony/Component/Mime/Part/AbstractMultipartPart.php index 76f58128c1..48b8620232 100644 --- a/src/Symfony/Component/Mime/Part/AbstractMultipartPart.php +++ b/src/Symfony/Component/Mime/Part/AbstractMultipartPart.php @@ -74,6 +74,20 @@ abstract class AbstractMultipartPart extends AbstractPart yield '--'.$this->getBoundary()."--\r\n"; } + public function asDebugString(): string + { + $str = parent::asDebugString(); + foreach ($this->getParts() as $part) { + $lines = explode("\n", $part->asDebugString()); + $str .= "\n └ ".array_shift($lines); + foreach ($lines as $line) { + $str .= "\n |".$line; + } + } + + return $str; + } + private function getBoundary(): string { if (null === $this->boundary) { diff --git a/src/Symfony/Component/Mime/Part/AbstractPart.php b/src/Symfony/Component/Mime/Part/AbstractPart.php index c9df1050a3..93892d9df6 100644 --- a/src/Symfony/Component/Mime/Part/AbstractPart.php +++ b/src/Symfony/Component/Mime/Part/AbstractPart.php @@ -50,6 +50,11 @@ abstract class AbstractPart yield from $this->bodyToIterable(); } + public function asDebugString(): string + { + return $this->getMediaType().'/'.$this->getMediaSubtype(); + } + abstract public function bodyToString(): string; abstract public function bodyToIterable(): iterable; diff --git a/src/Symfony/Component/Mime/Part/DataPart.php b/src/Symfony/Component/Mime/Part/DataPart.php index e8436712ca..128c53eb62 100644 --- a/src/Symfony/Component/Mime/Part/DataPart.php +++ b/src/Symfony/Component/Mime/Part/DataPart.php @@ -103,6 +103,16 @@ class DataPart extends TextPart return $headers; } + public function asDebugString(): string + { + $str = parent::asDebugString(); + if (null !== $this->filename) { + $str .= ' filename: '.$this->filename; + } + + return $str; + } + private function generateContentId(): string { return bin2hex(random_bytes(16)).'@symfony'; diff --git a/src/Symfony/Component/Mime/Part/TextPart.php b/src/Symfony/Component/Mime/Part/TextPart.php index 10aa94f154..77ab980219 100644 --- a/src/Symfony/Component/Mime/Part/TextPart.php +++ b/src/Symfony/Component/Mime/Part/TextPart.php @@ -144,6 +144,19 @@ class TextPart extends AbstractPart return $headers; } + public function asDebugString(): string + { + $str = parent::asDebugString(); + if (null !== $this->charset) { + $str .= ' charset: '.$this->charset; + } + if (null !== $this->disposition) { + $str .= ' disposition: '.$this->disposition; + } + + return $str; + } + private function getEncoder(): ContentEncoderInterface { if ('8bit' === $this->encoding) {