From 1da59a591bbacd938eca27ace64ce2e5782ba198 Mon Sep 17 00:00:00 2001 From: Karel Vlk Date: Tue, 22 Oct 2024 00:58:29 +0200 Subject: [PATCH] =?UTF-8?q?:bug:=20N=C2=B02274=20EmailLaminas.php:=20Keep?= =?UTF-8?q?=20charset=20with=20part=20header=20in=20multipart=20email?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sources/Core/Email/EmailLaminas.php | 48 +++-------------------------- 1 file changed, 5 insertions(+), 43 deletions(-) diff --git a/sources/Core/Email/EmailLaminas.php b/sources/Core/Email/EmailLaminas.php index fe900010c8..4580663b30 100644 --- a/sources/Core/Email/EmailLaminas.php +++ b/sources/Core/Email/EmailLaminas.php @@ -7,7 +7,6 @@ */ use Combodo\iTop\Core\Authentication\Client\OAuth\OAuthClientProviderFactory; -use Laminas\Mail\Header\ContentType; use Laminas\Mail\Message; use Laminas\Mail\Protocol\Smtp\Auth\Oauth; use Laminas\Mail\Transport\File; @@ -398,19 +397,6 @@ public function SetBody($sBody, $sMimeType = Mime::TYPE_HTML, $sCustomStyles = n $oBody->addPart($oAdditionalPart); } - if ($oBody->isMultiPart()) { - $oContentTypeHeader = $this->m_oMessage->getHeaders(); - foreach ($oContentTypeHeader as $oHeader) { - if (!$oHeader instanceof ContentType) { - continue; - } - - $oHeader->setType(Mime::MULTIPART_MIXED); - $oHeader->addParameter('boundary', $oBody->getMime()->boundary()); - break; - } - } - $this->m_oMessage->setBody($oBody); } @@ -431,22 +417,13 @@ public function AddPart($sText, $sMimeType = Mime::TYPE_HTML) $oNewPart = new Part($sText); $oNewPart->encoding = Mime::ENCODING_8BIT; $oNewPart->type = $sMimeType; - $this->m_oMessage->getBody()->addPart($oNewPart); + + // setBody called only to refresh Content-Type to multipart/mixed + $this->m_oMessage->setBody($this->m_oMessage->getBody()->addPart($oNewPart)); } public function AddAttachment($data, $sFileName, $sMimeType) { - $oBody = $this->m_oMessage->getBody(); - - if (!$oBody->isMultiPart()) { - $multipart_content = new Part($oBody->generateMessage()); - $multipart_content->setType($oBody->getParts()[0]->getType()); - $multipart_content->setBoundary($oBody->getMime()->boundary()); - - $oBody = new Laminas\Mime\Message(); - $oBody->addPart($multipart_content); - } - if (!array_key_exists('attachments', $this->m_aData)) { $this->m_aData['attachments'] = array(); } @@ -457,23 +434,8 @@ public function AddAttachment($data, $sFileName, $sMimeType) $oNewAttachment->disposition = Mime::DISPOSITION_ATTACHMENT; $oNewAttachment->encoding = Mime::ENCODING_BASE64; - - $oBody->addPart($oNewAttachment); - - if ($oBody->isMultiPart()) { - $oContentTypeHeader = $this->m_oMessage->getHeaders(); - foreach ($oContentTypeHeader as $oHeader) { - if (!$oHeader instanceof ContentType) { - continue; - } - - $oHeader->setType(Mime::MULTIPART_MIXED); - $oHeader->addParameter('boundary', $oBody->getMime()->boundary()); - break; - } - } - - $this->m_oMessage->setBody($oBody); + // setBody called only to refresh Content-Type to multipart/mixed + $this->m_oMessage->setBody($this->m_oMessage->getBody()->addPart($oNewAttachment)); } public function SetSubject($sSubject)