diff --git a/dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php b/dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php index 566dfbadedd29..7116953d682b3 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php @@ -769,9 +769,21 @@ public function testConfirmationEmailWithSpecialCharacters(): void $message = $this->transportBuilderMock->getSentMessage(); $rawMessage = $message->getRawMessage(); - $this->assertContains('To: John Smith <' . $email . '>', $rawMessage); + /** @var \Zend\Mime\Part $messageBodyPart */ + $messageBodyParts = $message->getBody()->getParts(); + $messageBodyPart = reset($messageBodyParts); + $messageEncoding = $messageBodyPart->getCharset(); + $name = 'John Smith'; + + if (strtoupper($messageEncoding) !== 'ASCII') { + $name = \Zend\Mail\Header\HeaderWrap::mimeEncodeValue($name, $messageEncoding); + } + + $nameEmail = sprintf('%s <%s>', $name, $email); + + $this->assertContains('To: ' . $nameEmail, $rawMessage); - $content = $message->getBody()->getParts()[0]->getRawContent(); + $content = $messageBodyPart->getRawContent(); $confirmationUrl = $this->getConfirmationUrlFromMessageContent($content); $this->setRequestInfo($confirmationUrl, 'confirm'); $this->clearCookieMessagesList(); diff --git a/lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php b/lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php index 4a8d6572faaf8..b763130c5a2cc 100644 --- a/lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php +++ b/lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php @@ -377,6 +377,7 @@ protected function prepareMessage() { $template = $this->getTemplate(); $content = $template->processTemplate(); + switch ($template->getType()) { case TemplateTypesInterface::TYPE_TEXT: $part['type'] = MimeInterface::TYPE_TEXT; @@ -391,7 +392,10 @@ protected function prepareMessage() new Phrase('Unknown template type') ); } + + /** @var \Magento\Framework\Mail\MimePartInterface $mimePart */ $mimePart = $this->mimePartInterfaceFactory->create(['content' => $content]); + $this->messageData['encoding'] = $mimePart->getCharset(); $this->messageData['body'] = $this->mimeMessageInterfaceFactory->create( ['parts' => [$mimePart]] ); @@ -400,6 +404,7 @@ protected function prepareMessage() (string)$template->getSubject(), ENT_QUOTES ); + $this->message = $this->emailMessageInterfaceFactory->create($this->messageData); return $this;