Skip to content

Commit

Permalink
Merge pull request #21 from sandstein/fix-issue-20
Browse files Browse the repository at this point in the history
Uses correctly encoded Laminas\Mail\Message instead of reparsing
  • Loading branch information
0m3r authored Apr 12, 2021
2 parents ab93bcb + 368edea commit 12fcaa6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
27 changes: 27 additions & 0 deletions Mail/EmailMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* @author Wilfried Wolf <[email protected]>
*/

namespace Swissup\Email\Mail;

use Laminas\Mail\Message;
use Magento\Framework\Mail\EmailMessage as FrameworkEmailMessage;
use Magento\Framework\Mail\EmailMessageInterface;

/**
* Class EmailMessage
* @package Swissup\Email\Mail
*/
class EmailMessage extends FrameworkEmailMessage implements EmailMessageInterface
{
/**
* @return Message
*/
public function getZendMessage(): Message
{
return $this->zendMessage;
}

}
11 changes: 7 additions & 4 deletions Mail/Message/Convertor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ class Convertor
*/
public static function fromMessage($message)
{
$isRemoveDublicateHeaders = true;
$isRemoveDuplicateHeaders = true;
if ($message instanceof \Zend_Mail) {
$message = self::fromZendMail1($message);
} elseif ($message instanceof \Zend\Mail\Message) {
$message = $message;
$isRemoveDublicateHeaders = false;
$isRemoveDuplicateHeaders = false;
} elseif ($message instanceof \Laminas\Mail\Message) {
$message = $message;
$isRemoveDublicateHeaders = false;
$isRemoveDuplicateHeaders = false;
} else if ($message instanceof \Swissup\Email\Mail\EmailMessage) {
$message = $message->getZendMessage();
$isRemoveDuplicateHeaders = false;
} elseif ($message instanceof \Magento\Framework\Mail\EmailMessageInterface) {
//fix for desposition https://github.com/magento/magento2/commit/6976aabdfdab91a9d06e412c2ed619538ed034b6
$message = \Zend\Mail\Message::fromString($message->toString());
Expand All @@ -44,7 +47,7 @@ public static function fromMessage($message)
}
}, ['to', 'reply-to', 'from']);

if ($isRemoveDublicateHeaders || $hasInvalidHeader) {
if ($isRemoveDuplicateHeaders || $hasInvalidHeader) {
//Ignore encoding exceptions in headers
$ignoreException = false;
try {
Expand Down
4 changes: 3 additions & 1 deletion etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

<preference for="Magento\Framework\Mail\Transport" type="Swissup\Email\Mail\Transport"/>
<preference for="Magento\Framework\Mail\TransportInterface" type="Swissup\Email\Mail\Transport"/>

<preference for="Magento\Framework\Mail\EmailMessageInterface" type="Swissup\Email\Mail\EmailMessage"/>
<!--
<type name="Magento\Framework\Mail\TransportInterface">
<plugin name="swissup_email_transport" type="Swissup\Email\Mail\TransportPlugin" sortOrder="1" disabled="false"/>
Expand Down Expand Up @@ -42,4 +44,4 @@
<argument name="filterPool" xsi:type="object" shared="false">SwissupEmailServiceGridFilterPool</argument>
</arguments>
</virtualType>
</config>
</config>

0 comments on commit 12fcaa6

Please sign in to comment.