Skip to content

Commit

Permalink
🐛 N°2274 EmailLaminas.php: Keep charset with part header in multipart…
Browse files Browse the repository at this point in the history
… email
  • Loading branch information
vlk-charles authored Oct 21, 2024
1 parent 88756a4 commit 1da59a5
Showing 1 changed file with 5 additions and 43 deletions.
48 changes: 5 additions & 43 deletions sources/Core/Email/EmailLaminas.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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();
}
Expand All @@ -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)
Expand Down

0 comments on commit 1da59a5

Please sign in to comment.