From 15311dabbe20b509ce83caf6605d3f9ba42ac0aa Mon Sep 17 00:00:00 2001 From: Alexander Kras'ko <0m3r.mail@gmail.com> Date: Mon, 17 Jan 2022 09:23:48 +0200 Subject: [PATCH] Fix copy/paste (add fixBodyParts) --- Mail/Message/Convertor.php | 24 +++++++++++++++++++++++- Mail/Transport/Mandrill.php | 13 +------------ Mail/Transport/Ses.php | 13 +------------ 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Mail/Message/Convertor.php b/Mail/Message/Convertor.php index abad494..99effe2 100644 --- a/Mail/Message/Convertor.php +++ b/Mail/Message/Convertor.php @@ -225,7 +225,7 @@ public static function fromZendMail1(\Zend_Mail $zend1MailMessage) * @param \Magento\Framework\Mail\MimePart $part * @return \Laminas\Mime\Part */ - public static function convertMimePart(\Magento\Framework\Mail\MimePart $part): \Laminas\Mime\Part + public static function toMimePart(\Magento\Framework\Mail\MimePart $part): \Laminas\Mime\Part { // $propertyName = 'mimePart'; // $reflectionClass = new \ReflectionClass($part); @@ -274,4 +274,26 @@ public static function convertMimePart(\Magento\Framework\Mail\MimePart $part): return $mimePart; } + + /** + * @param $message + * @return mixed + */ + public static function fixBodyParts($message) + { + $body = $message->getBody(); + if ($body instanceof \Laminas\Mime\Message) { + $parts = []; + foreach ($body->getParts() as $part) { + if ($part instanceof \Magento\Framework\Mail\MimePart) { + $parts[] = self::toMimePart($part); + } elseif ($part instanceof \Laminas\Mime\Part) { + $parts[] = $part; + } + } + $body->setParts($parts); + } + + return $message; + } } diff --git a/Mail/Transport/Mandrill.php b/Mail/Transport/Mandrill.php index 7a15da8..1990bbb 100644 --- a/Mail/Transport/Mandrill.php +++ b/Mail/Transport/Mandrill.php @@ -48,19 +48,8 @@ public function sendMessage() try { $message = $this->message; $message = Convertor::fromMessage($message); + $message = Convertor::fixBodyParts($message); - $body = $message->getBody(); - if ($body instanceof \Laminas\Mime\Message) { - $parts = []; - foreach ($body->getParts() as $part) { - if ($part instanceof \Magento\Framework\Mail\MimePart) { - $parts[] = Convertor::convertMimePart($part); - } elseif ($part instanceof \Laminas\Mime\Part) { - $parts[] = $part; - } - } - $body->setParts($parts); - } $this->transport->send($message); } catch (\Exception $e) { $phrase = new \Magento\Framework\Phrase($e->getMessage()); diff --git a/Mail/Transport/Ses.php b/Mail/Transport/Ses.php index 993b2c1..5e256a3 100644 --- a/Mail/Transport/Ses.php +++ b/Mail/Transport/Ses.php @@ -60,19 +60,8 @@ public function sendMessage() try { $message = $this->message; $message = Convertor::fromMessage($message); + $message = Convertor::fixBodyParts($message); - $body = $message->getBody(); - if ($body instanceof \Laminas\Mime\Message) { - $parts = []; - foreach ($body->getParts() as $part) { - if ($part instanceof \Magento\Framework\Mail\MimePart) { - $parts[] = Convertor::convertMimePart($part); - } elseif ($part instanceof \Laminas\Mime\Part) { - $parts[] = $part; - } - } - $body->setParts($parts); - } $this->transport->send($message); } catch (\Exception $e) { $phrase = new \Magento\Framework\Phrase($e->getMessage());