From 353fdda3e5f5fea8545e1315206c31a822e885ed Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Wed, 15 Feb 2023 12:03:51 +0100 Subject: [PATCH] Move some message checks to MailSo\Mime\Message --- .../app/libraries/MailSo/Mime/Message.php | 33 +++++++++++-------- .../libraries/RainLoop/Actions/Messages.php | 33 ++++--------------- 2 files changed, 26 insertions(+), 40 deletions(-) diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mime/Message.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mime/Message.php index 2c37663ab..e13ddb553 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mime/Message.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mime/Message.php @@ -179,16 +179,19 @@ class Message extends Part public function SetInReplyTo(string $sInReplyTo) : self { - $this->aHeadersValue[Enumerations\Header::IN_REPLY_TO] = $sInReplyTo; - + $sInReplyTo = \trim($sInReplyTo); + if (\strlen($sInReplyTo)) { + $this->aHeadersValue[Enumerations\Header::IN_REPLY_TO] = $sInReplyTo; + } return $this; } public function SetReferences(string $sReferences) : self { - $this->aHeadersValue[Enumerations\Header::REFERENCES] = - \MailSo\Base\Utils::StripSpaces($sReferences); - + $sReferences = \MailSo\Base\Utils::StripSpaces($sReferences); + if (\strlen($sReferences)) { + $this->aHeadersValue[Enumerations\Header::REFERENCES] = $sReferences; + } return $this; } @@ -239,8 +242,9 @@ class Message extends Part public function SetTo(EmailCollection $oEmails) : self { - $this->aHeadersValue[Enumerations\Header::TO_] = $oEmails; - + if ($oEmails->count()) { + $this->aHeadersValue[Enumerations\Header::TO_] = $oEmails; + } return $this; } @@ -253,22 +257,25 @@ class Message extends Part public function SetReplyTo(EmailCollection $oEmails) : self { - $this->aHeadersValue[Enumerations\Header::REPLY_TO] = $oEmails; - + if ($oEmails->count()) { + $this->aHeadersValue[Enumerations\Header::REPLY_TO] = $oEmails; + } return $this; } public function SetCc(EmailCollection $oEmails) : self { - $this->aHeadersValue[Enumerations\Header::CC] = $oEmails; - + if ($oEmails->count()) { + $this->aHeadersValue[Enumerations\Header::CC] = $oEmails; + } return $this; } public function SetBcc(EmailCollection $oEmails) : self { - $this->aHeadersValue[Enumerations\Header::BCC] = $oEmails; - + if ($oEmails->count()) { + $this->aHeadersValue[Enumerations\Header::BCC] = $oEmails; + } return $this; } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php index 303b6f645..4128692f6 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php @@ -989,10 +989,7 @@ trait Messages $oFrom = $oMessage->GetFrom(); $oMessage->RegenerateMessageId($oFrom ? $oFrom->GetDomain() : ''); - $oReplyTo = new \MailSo\Mime\EmailCollection($this->GetActionParam('replyTo', '')); - if ($oReplyTo->count()) { - $oMessage->SetReplyTo($oReplyTo); - } + $oMessage->SetReplyTo(new \MailSo\Mime\EmailCollection($this->GetActionParam('replyTo', ''))); if (!empty($this->GetActionParam('readReceiptRequest', 0))) { // Read Receipts Reference Main Account Email, Not Identities #147 @@ -1010,35 +1007,17 @@ trait Messages $oMessage->SetSubject($this->GetActionParam('subject', '')); - $oToEmails = new \MailSo\Mime\EmailCollection($this->GetActionParam('to', '')); - if ($oToEmails->count()) { - $oMessage->SetTo($oToEmails); - } - - $oCcEmails = new \MailSo\Mime\EmailCollection($this->GetActionParam('cc', '')); - if ($oCcEmails->count()) { - $oMessage->SetCc($oCcEmails); - } - - $oBccEmails = new \MailSo\Mime\EmailCollection($this->GetActionParam('bcc', '')); - if ($oBccEmails->count()) { - $oMessage->SetBcc($oBccEmails); - } + $oMessage->SetTo(new \MailSo\Mime\EmailCollection($this->GetActionParam('to', ''))); + $oMessage->SetCc(new \MailSo\Mime\EmailCollection($this->GetActionParam('cc', ''))); + $oMessage->SetBcc(new \MailSo\Mime\EmailCollection($this->GetActionParam('bcc', ''))); $aDraftInfo = $this->GetActionParam('draftInfo', null); if ($bWithDraftInfo && \is_array($aDraftInfo) && !empty($aDraftInfo[0]) && !empty($aDraftInfo[1]) && !empty($aDraftInfo[2])) { $oMessage->SetDraftInfo($aDraftInfo[0], $aDraftInfo[1], $aDraftInfo[2]); } - $sInReplyTo = $this->GetActionParam('inReplyTo', ''); - if (\strlen($sInReplyTo)) { - $oMessage->SetInReplyTo($sInReplyTo); - } - - $sReferences = $this->GetActionParam('references', ''); - if (\strlen($sReferences)) { - $oMessage->SetReferences($sReferences); - } + $oMessage->SetInReplyTo($this->GetActionParam('inReplyTo', '')); + $oMessage->SetReferences($this->GetActionParam('references', '')); $aFoundCids = array(); $aFoundDataURL = array();