Skip to content

Commit

Permalink
[BUGFIX] - Correct mail redirect for symfonyMailMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
mschwehr committed Jun 17, 2021
1 parent ec7fa58 commit 9add72b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 24 deletions.
64 changes: 42 additions & 22 deletions Classes/Xclass/Mail/SymfonyMailMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Mail\Mailer;
use Symfony\Component\Mime\Part\AbstractPart;
use Symfony\Component\Mime\Part\Multipart\MixedPart;
use Symfony\Component\Mime\Part\TextPart;
use Symfony\Component\Mime\Address;

/*
Expand Down Expand Up @@ -141,30 +143,22 @@ public function getBody(): AbstractPart
{
if($this->isRedirectEnabled())
{
$textPart = parent::getBody();
$bodyText = $textPart->bodyToString();
$bodyText .= '<br /><hr /><br />This mail must be sent';
$bodyText .= '<br/>as TO: ' . $this->parseSymfonyAddressesToString($this->originalRecipient);
$bodyText .= '<br/>as CC: ' . $this->parseSymfonyAddressesToString($this->originalCc);
$bodyText .= '<br/>as BCC: ' . $this->parseSymfonyAddressesToString($this->originalBcc);

$charset = 'utf-8';
if($textPart->getPreparedHeaders()->has('content-type'))
{
if(array_key_exists('charset', $textPart->getPreparedHeaders()->get('content-type')->getParameters()))
{
$charset = $textPart->getPreparedHeaders()->get('content-type')->getParameters()['charset'];
$abstractPart = parent::getBody();
if(get_class($abstractPart) == 'Symfony\Component\Mime\Part\TextPart') {
$abstractPart = $this->updateTextPart($abstractPart);
} else if(get_class($abstractPart) == 'Symfony\Component\Mime\Part\Multipart\MixedPart') {
$parts = $abstractPart->getParts();
$newParts = [];
foreach($parts as $part) {
if(get_class($part) == 'Symfony\Component\Mime\Part\TextPart') {
$newParts[] = $this->updateTextPart($part);
} else {
$newParts[] = $part;
}
}
$abstractPart = GeneralUtility::makeInstance(MixedPart::class, ...$newParts);
}
$encoding = null;
if($textPart->getPreparedHeaders()->has('content-transfer-encoding'))
{
$encoding = $textPart->getPreparedHeaders()->get('content-transfer-encoding')->getValue();
}

$newTextPart = GeneralUtility::makeInstance(\Symfony\Component\Mime\Part\TextPart::class, $bodyText, $charset, $textPart->getMediaSubtype(), $encoding);

return $newTextPart;
return $abstractPart;
}
else
{
Expand All @@ -189,6 +183,32 @@ public function updateSubject(): void
parent::setSubject($subject);
}

private function updateTextPart(TextPart $part): TextPart
{
$bodyText = $part->getBody();
$bodyText .= '<br /><hr /><br />This mail must be sent';
$bodyText .= '<br/>as TO: ' . $this->parseSymfonyAddressesToString($this->originalRecipient);
$bodyText .= '<br/>as CC: ' . $this->parseSymfonyAddressesToString($this->originalCc);
$bodyText .= '<br/>as BCC: ' . $this->parseSymfonyAddressesToString($this->originalBcc);

$charset = 'utf-8';

if($part->getPreparedHeaders()->has('content-type'))
{
if(array_key_exists('charset', $part->getPreparedHeaders()->get('content-type')->getParameters()))
{
$charset = $part->getPreparedHeaders()->get('content-type')->getParameters()['charset'];
}
}
$encoding = null;
if($part->getPreparedHeaders()->has('content-transfer-encoding'))
{
$encoding = $part->getPreparedHeaders()->get('content-transfer-encoding')->getValue();
}

return GeneralUtility::makeInstance(TextPart::class, $bodyText, $charset, $part->getMediaSubtype(), $encoding);
}

/**
* Parse symfony addresses to a human readable text
*
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
"Ameos\\AmeosMailredirect\\": "Classes"
}
},
"version": "1.2.0"
"version": "1.2.1"
}
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'clearCacheOnLoad' => 0,
'lockType' => '',
'author_company' => 'Ameos',
'version' => '1.2.0',
'version' => '1.2.1',
'constraints' => [
'depends' => [
'typo3' => '8.7.0-10.4.99',
Expand Down

0 comments on commit 9add72b

Please sign in to comment.