Fix BodyStructure encoding name

This commit is contained in:
the-djmaze 2024-03-10 18:25:05 +01:00
parent 913ed54668
commit 7459813646
4 changed files with 34 additions and 42 deletions

View file

@ -196,10 +196,10 @@ abstract class Utils
return \round($iSize, $iRound).$aSizes[$iIndex]; return \round($iSize, $iRound).$aSizes[$iIndex];
} }
public static function DecodeEncodingValue(string $sEncodedValue, string $sEncodeingType) : string public static function DecodeEncodingValue(string $sEncodedValue, string $sEncodingType) : string
{ {
$sResult = $sEncodedValue; $sResult = $sEncodedValue;
switch (\strtolower($sEncodeingType)) switch (\strtolower($sEncodingType))
{ {
case 'q': case 'q':
case 'quoted_printable': case 'quoted_printable':

View file

@ -19,38 +19,40 @@ use MailSo\Mime\Enumerations\ContentType;
*/ */
class BodyStructure implements \JsonSerializable class BodyStructure implements \JsonSerializable
{ {
private string $sContentType;
private array $aContentTypeParams; private array $aContentTypeParams;
private string $sCharset; private string
$sCharset = '',
$sContentID = '',
$sContentTransferEncoding = '',
$sContentType = '',
$sDescription = '',
$sDisposition = '',
$sFileName = '',
$sLanguage = '',
$sLocation = '',
$sPartID = '';
private string $sContentID; private int $iSize = 0;
private string $sDescription;
private string $sMailEncodingName;
private string $sDisposition;
private string $sFileName;
private string $sLanguage = '';
private string $sLocation = '';
private int $iSize;
private string $sPartID;
/** /**
* \MailSo\Imap\BodyStructure[] * \MailSo\Imap\BodyStructure[]
*/ */
private array $aSubParts; private array $aSubParts;
public function MailEncodingName() : string public function Charset() : string
{ {
return $this->sMailEncodingName; return $this->sCharset;
}
public function ContentTransferEncoding() : string
{
return $this->sContentTransferEncoding;
}
public function ContentType() : string
{
return $this->sContentType;
} }
public function PartID() : string public function PartID() : string
@ -88,15 +90,10 @@ class BodyStructure implements \JsonSerializable
return ($this->isInline() ? 'inline' : 'part' ) . $sIdx; return ($this->isInline() ? 'inline' : 'part' ) . $sIdx;
} }
public function ContentType() : string
{
return $this->sContentType;
}
public function EstimatedSize() : int public function EstimatedSize() : int
{ {
$fCoefficient = 1; $fCoefficient = 1;
switch ($this->sMailEncodingName) switch ($this->sContentTransferEncoding)
{ {
case 'base64': case 'base64':
$fCoefficient = 0.75; $fCoefficient = 0.75;
@ -109,11 +106,6 @@ class BodyStructure implements \JsonSerializable
return (int) ($this->iSize * $fCoefficient); return (int) ($this->iSize * $fCoefficient);
} }
public function Charset() : string
{
return $this->sCharset;
}
public function SubParts() : array public function SubParts() : array
{ {
return $this->aSubParts; return $this->aSubParts;
@ -192,7 +184,7 @@ class BodyStructure implements \JsonSerializable
{ {
return !empty($this->aContentTypeParams['format']) return !empty($this->aContentTypeParams['format'])
&& 'flowed' === \strtolower(\trim($this->aContentTypeParams['format'])) && 'flowed' === \strtolower(\trim($this->aContentTypeParams['format']))
&& !\in_array($this->sMailEncodingName, array('base64', 'quoted-printable')); && !\in_array($this->sContentTransferEncoding, array('base64', 'quoted-printable'));
} }
public function GetHtmlAndPlainParts() : array public function GetHtmlAndPlainParts() : array
@ -367,7 +359,7 @@ class BodyStructure implements \JsonSerializable
$sCharset = ''; // \MailSo\Base\Enumerations\Charset::UTF_8 ? $sCharset = ''; // \MailSo\Base\Enumerations\Charset::UTF_8 ?
$sContentID = ''; $sContentID = '';
$sDescription = ''; $sDescription = '';
$sMailEncodingName = ''; $sContentTransferEncoding = '';
$iSize = 0; $iSize = 0;
$iExtraItemPos = 0; // list index of items which have no well-established position (such as 0, 1, 5, etc). $iExtraItemPos = 0; // list index of items which have no well-established position (such as 0, 1, 5, etc).
@ -463,10 +455,10 @@ class BodyStructure implements \JsonSerializable
if (!\is_string($aBodyStructure[5])) { if (!\is_string($aBodyStructure[5])) {
return null; return null;
} }
$sMailEncodingName = $aBodyStructure[5]; $sContentTransferEncoding = $aBodyStructure[5];
} }
$iSize = \is_numeric($aBodyStructure[6]) ? (int) $aBodyStructure[6] : -1; $iSize = \is_numeric($aBodyStructure[6]) ? (int) $aBodyStructure[6] : 0;
if (!\strlen($sPartID) || '.' === $sPartID[\strlen($sPartID) - 1]) { if (!\strlen($sPartID) || '.' === $sPartID[\strlen($sPartID) - 1]) {
// This is the only sub-part of the message (otherwise, it would be // This is the only sub-part of the message (otherwise, it would be
@ -519,7 +511,7 @@ class BodyStructure implements \JsonSerializable
$oStructure->sCharset = $sCharset; $oStructure->sCharset = $sCharset;
$oStructure->sContentID = \trim($sContentID); $oStructure->sContentID = \trim($sContentID);
$oStructure->sDescription = $sDescription; $oStructure->sDescription = $sDescription;
$oStructure->sMailEncodingName = \strtolower($sMailEncodingName); $oStructure->sContentTransferEncoding = \strtolower($sContentTransferEncoding);
$oStructure->sDisposition = \strtolower($sDisposition); $oStructure->sDisposition = \strtolower($sDisposition);
$oStructure->sFileName = \MailSo\Base\Utils::Utf8Clear($sFileName); $oStructure->sFileName = \MailSo\Base\Utils::Utf8Clear($sFileName);
$oStructure->iSize = $iSize; $oStructure->iSize = $iSize;

View file

@ -397,7 +397,7 @@ class Message implements \JsonSerializable
} }
if (\is_string($sText) && \strlen($sText)) { if (\is_string($sText) && \strlen($sText)) {
$sText = Utils::DecodeEncodingValue($sText, $oPart->MailEncodingName()); $sText = Utils::DecodeEncodingValue($sText, $oPart->ContentTransferEncoding());
$sText = Utils::ConvertEncoding($sText, $sText = Utils::ConvertEncoding($sText,
Utils::NormalizeCharset($oPart->Charset() ?: $sCharset, true), Utils::NormalizeCharset($oPart->Charset() ?: $sCharset, true),
\MailSo\Base\Enumerations\Charset::UTF_8 \MailSo\Base\Enumerations\Charset::UTF_8

View file

@ -60,7 +60,7 @@ class Part
Enumerations\Header::CONTENT_TYPE, Enumerations\Header::CONTENT_TYPE,
Enumerations\Parameter::FORMAT))); Enumerations\Parameter::FORMAT)));
if ($bResult && \in_array($this->MailEncodingName(), array('base64', 'quoted-printable'))) { if ($bResult && \in_array($this->ContentTransferEncoding(), array('base64', 'quoted-printable'))) {
$bResult = false; $bResult = false;
} }