diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php b/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php index bea06f027..8b4d14cad 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php @@ -1068,7 +1068,7 @@ abstract class Utils public static function MultipleStreamWriter($rRead, array $aWrite, int $iBufferLen = 8192, bool $bResetTimeLimit = true, bool $bFixCrLf = false, bool $bRewindOnComplete = false) : int { $mResult = false; - if ($rRead && \count($aWrite)) + if (\is_resource($rRead) && \count($aWrite)) { $mResult = 0; while (!\feof($rRead)) @@ -1080,7 +1080,7 @@ abstract class Utils break; } - if (0 === $iBufferLen || '' === $sBuffer) + if ('' === $sBuffer) { break; } 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 9417b0799..59ddff35b 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 @@ -511,71 +511,6 @@ class Message return $oAlternativePart; } - private function createNewMessageSimpleOrAlternativeBody() : Part - { - $oResultPart = null; - if (1 < \count($this->aAlternativeParts)) - { - $oResultPart = new Part; - - $oResultPart->Headers->append( - new Header(Enumerations\Header::CONTENT_TYPE, - Enumerations\MimeType::MULTIPART_ALTERNATIVE.'; '. - (new ParameterCollection)->Add( - new Parameter( - Enumerations\Parameter::BOUNDARY, - $this->generateNewBoundary()) - )->ToString() - ) - ); - - foreach ($this->aAlternativeParts as $aAlternativeData) - { - $oAlternativePart = $this->createNewMessageAlternativePartBody($aAlternativeData); - if ($oAlternativePart) - { - $oResultPart->SubParts->append($oAlternativePart); - } - - unset($oAlternativePart); - } - - } - else if (1 === \count($this->aAlternativeParts)) - { - $oAlternativePart = $this->createNewMessageAlternativePartBody($this->aAlternativeParts[0]); - if ($oAlternativePart) - { - $oResultPart = $oAlternativePart; - } - } - - if (!$oResultPart) - { - if ($this->bAddEmptyTextPart) - { - $oResultPart = $this->createNewMessageAlternativePartBody(array( - Enumerations\MimeType::TEXT_PLAIN, null - )); - } - else - { - $aAttachments = $this->oAttachmentCollection->getArrayCopy(); - if (1 === \count($aAttachments) && isset($aAttachments[0])) - { - $this->oAttachmentCollection->Clear(); - - $oResultPart = $this->createNewMessageAlternativePartBody(array( - $aAttachments[0]->ContentType(), $aAttachments[0]->Resource(), - '', $aAttachments[0]->CustomContentTypeParams() - )); - } - } - } - - return $oResultPart; - } - private function createNewMessageRelatedBody(Part $oIncPart) : Part { $oResultPart = null; @@ -672,26 +607,80 @@ class Message return $oIncPart; } - public function ToPart(bool $bWithoutBcc = false) : Part - { - $oPart = $this->createNewMessageSimpleOrAlternativeBody(); - $oPart = $this->createNewMessageRelatedBody($oPart); - $oPart = $this->createNewMessageMixedBody($oPart); - $oPart = $this->setDefaultHeaders($oPart, $bWithoutBcc); - - return $oPart; - } - /** * @return resource */ public function ToStream(bool $bWithoutBcc = false) { - return $this->ToPart($bWithoutBcc)->ToStream(); - } + $oPart = null; + if (1 < \count($this->aAlternativeParts)) + { + $oPart = new Part; + $oPart->Headers->append( + new Header(Enumerations\Header::CONTENT_TYPE, + Enumerations\MimeType::MULTIPART_ALTERNATIVE.'; '. + (new ParameterCollection)->Add( + new Parameter( + Enumerations\Parameter::BOUNDARY, + $this->generateNewBoundary()) + )->ToString() + ) + ); + + foreach ($this->aAlternativeParts as $aAlternativeData) + { + $oAlternativePart = $this->createNewMessageAlternativePartBody($aAlternativeData); + if ($oAlternativePart) + { + $oPart->SubParts->append($oAlternativePart); + } + + unset($oAlternativePart); + } + + } + else if (1 === \count($this->aAlternativeParts)) + { + $oAlternativePart = $this->createNewMessageAlternativePartBody($this->aAlternativeParts[0]); + if ($oAlternativePart) + { + $oPart = $oAlternativePart; + } + } + + if (!$oPart) + { + if ($this->bAddEmptyTextPart) + { + $oPart = $this->createNewMessageAlternativePartBody(array( + Enumerations\MimeType::TEXT_PLAIN, null + )); + } + else + { + $aAttachments = $this->oAttachmentCollection->getArrayCopy(); + if (1 === \count($aAttachments) && isset($aAttachments[0])) + { + $this->oAttachmentCollection->Clear(); + + $oPart = $this->createNewMessageAlternativePartBody(array( + $aAttachments[0]->ContentType(), $aAttachments[0]->Resource(), + '', $aAttachments[0]->CustomContentTypeParams() + )); + } + } + } + + $oPart = $this->createNewMessageRelatedBody($oPart); + $oPart = $this->createNewMessageMixedBody($oPart); + $oPart = $this->setDefaultHeaders($oPart, $bWithoutBcc); + return $oPart->ToStream(); + } +/* public function ToString(bool $bWithoutBcc = false) : string { return \stream_get_contents($this->ToStream($bWithoutBcc)); } +*/ } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mime/Part.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mime/Part.php index a78f856ba..bf9d2f682 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mime/Part.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mime/Part.php @@ -63,11 +63,6 @@ class Part $this->SubParts = new PartCollection; } - function __destruct() - { - \MailSo\Base\ResourceRegistry::CloseMemoryResource($this->Body); - } - public function Boundary() : string { return $this->sBoundary; @@ -532,7 +527,7 @@ class Part if ($this->Body && \is_resource($this->Body)) { $aMeta = \stream_get_meta_data($this->Body); - if (isset($aMeta['seekable']) && $aMeta['seekable']) + if (!empty($aMeta['seekable'])) { \rewind($this->Body); }