diff --git a/src/Message.php b/src/Message.php index e5ef56cc..b5069fb9 100644 --- a/src/Message.php +++ b/src/Message.php @@ -403,7 +403,7 @@ public function setBody($body) $parts = $this->body->getParts(); if (!empty($parts)) { $part = array_shift($parts); - $headers->addHeaders($part->getHeadersArray()); + $headers->addHeaders($part->getHeadersArray("\r\n")); } return $this; } diff --git a/test/MessageTest.php b/test/MessageTest.php index 486f9de2..5259f3d3 100644 --- a/test/MessageTest.php +++ b/test/MessageTest.php @@ -745,4 +745,39 @@ public function testDetectsCRLFInjectionViaSubject() $this->assertContains('example', $serializedHeaders); $this->assertNotContains("\r\n", $serializedHeaders); } + + public function testHeaderUnfoldingWorksAsExpectedForMultipartMessages() + { + $text = new MimePart('Test content'); + $text->type = Mime::TYPE_TEXT; + $text->encoding = Mime::ENCODING_QUOTEDPRINTABLE; + $text->disposition = Mime::DISPOSITION_INLINE; + $text->charset = 'UTF-8'; + + $html = new MimePart('Test content'); + $html->type = Mime::TYPE_HTML; + $html->encoding = Mime::ENCODING_QUOTEDPRINTABLE; + $html->disposition = Mime::DISPOSITION_INLINE; + $html->charset = 'UTF-8'; + + $multipartContent = new MimeMessage(); + $multipartContent->addPart($text); + $multipartContent->addPart($html); + + $multipartPart = new MimePart($multipartContent->generateMessage()); + $multipartPart->charset = 'UTF-8'; + $multipartPart->type = 'multipart/alternative'; + $multipartPart->boundary = $multipartContent->getMime()->boundary(); + + $message = new MimeMessage(); + $message->addPart($multipartPart); + + $this->message->getHeaders()->addHeaderLine('Content-Transfer-Encoding', Mime::ENCODING_QUOTEDPRINTABLE); + $this->message->setBody($message); + + $contentType = $this->message->getHeaders()->get('Content-Type'); + $this->assertInstanceOf('Zend\Mail\Header\ContentType', $contentType); + $this->assertContains('multipart/alternative', $contentType->getFieldValue()); + $this->assertContains($multipartContent->getMime()->boundary(), $contentType->getFieldValue()); + } }