From 4d9fb41d73dcc8698f7c94729809ba638e9777fc Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Mon, 22 Jan 2024 09:03:34 +0100 Subject: [PATCH] Cleanup mime header parameter handling --- .../app/libraries/MailSo/Mime/Parameter.php | 29 +++++-------------- .../MailSo/Mime/ParameterCollection.php | 2 +- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mime/Parameter.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mime/Parameter.php index 2e20ffe09..7a1bddc2f 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mime/Parameter.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mime/Parameter.php @@ -27,18 +27,17 @@ class Parameter implements \JsonSerializable $this->sValue = $sValue; } - public static function CreateFromParameterLine(string $sRawParam) : self + public static function FromString(string $sRawParam) : self { $oParameter = new self('', ''); - return $oParameter->Parse($sRawParam); - } - public function Reset() : self - { - $this->sName = ''; - $this->sValue = ''; + $aParts = \explode('=', $sRawParam, 2); + $oParameter->sName = \trim(\trim($aParts[0]), '"\''); + if (2 === \count($aParts)) { + $oParameter->sValue = \trim(\trim($aParts[1]), '"\''); + } - return $this; + return $oParameter; } public function Name() : string @@ -56,20 +55,6 @@ class Parameter implements \JsonSerializable $this->sValue = $sValue; } - public function Parse(string $sRawParam, string $sSeparator = '=') : self - { - $this->Reset(); - - $aParts = \explode($sSeparator, $sRawParam, 2); - - $this->sName = \trim(\trim($aParts[0]), '"\''); - if (2 === \count($aParts)) { - $this->sValue = \trim(\trim($aParts[1]), '"\''); - } - - return $this; - } - public function ToString(bool $bConvertSpecialsName = false) : string { if (!\strlen($this->sName)) { diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mime/ParameterCollection.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mime/ParameterCollection.php index af34acb40..ee898be01 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mime/ParameterCollection.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mime/ParameterCollection.php @@ -64,7 +64,7 @@ class ParameterCollection extends \MailSo\Base\Collection $aDataToParse = \explode(';', $sRawParams); foreach ($aDataToParse as $sParam) { - $this->append(Parameter::CreateFromParameterLine($sParam)); + $this->append(Parameter::FromString($sParam)); } $this->reParseParameters();