From 41df46dbed55116f23601180506f5a498ad6c522 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Tue, 1 Nov 2022 18:42:18 +0100 Subject: [PATCH] Resolve #600 --- .../MailSo/Base/StreamWrappers/SubStreams.php | 3 ++- .../libraries/RainLoop/Actions/Messages.php | 27 ++++++++++++------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Base/StreamWrappers/SubStreams.php b/snappymail/v/0.0.0/app/libraries/MailSo/Base/StreamWrappers/SubStreams.php index 42ed64f73..be64df4cd 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Base/StreamWrappers/SubStreams.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Base/StreamWrappers/SubStreams.php @@ -15,6 +15,7 @@ namespace MailSo\Base\StreamWrappers; * @category MailSo * @package Base * @subpackage StreamWrappers + * https://www.php.net/streamwrapper */ class SubStreams { @@ -214,4 +215,4 @@ class SubStreams } } -\stream_wrapper_register(SubStreams::STREAM_NAME, '\\MailSo\\Base\\StreamWrappers\\SubStreams'); +\stream_wrapper_register(SubStreams::STREAM_NAME, SubStreams::class); 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 07e6c5dd9..507ef448d 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 @@ -708,6 +708,7 @@ trait Messages } } + // Try by default as OpenPGP.js sets GnuPG to 0 if ($this->GetActionParam('GnuPG', 1)) { $GPG = $this->GnuPG(); if ($GPG) { @@ -722,12 +723,13 @@ trait Messages * https://code.woboq.org/qt5/include/gpg-error.h.html * status: 0 = GPG_ERR_NO_ERROR + 1 = GPG_ERR_GENERAL 9 = GPG_ERR_NO_PUBKEY 117440513 = General error 117440520 = Bad signature */ - $summary = [ + $summary = \defined('GNUPG_SIGSUM_VALID') ? [ GNUPG_SIGSUM_VALID => 'The signature is fully valid.', GNUPG_SIGSUM_GREEN => 'The signature is good but one might want to display some extra information. Check the other bits.', GNUPG_SIGSUM_RED => 'The signature is bad. It might be useful to check other bits and display more information, i.e. a revoked certificate might not render a signature invalid when the message was received prior to the cause for the revocation.', @@ -740,7 +742,7 @@ trait Messages GNUPG_SIGSUM_BAD_POLICY => 'A policy requirement was not met.', GNUPG_SIGSUM_SYS_ERROR => 'A system error occurred.', // GNUPG_SIGSUM_TOFU_CONFLICT = 'A TOFU conflict was detected.', - ]; + ] : []; // Verified, so no need to return $result['text'] and $result['signature'] $result = [ @@ -1280,14 +1282,17 @@ trait Messages $GPG = $this->GnuPG(); $oBody = $oMessage->GetRootPart(); $resource = $oBody->ToStream(); + + \MailSo\Base\StreamFilters\LineEndings::appendTo($resource); + $fp = \fopen('php://temp', 'r+b'); +// \stream_copy_to_stream($resource, $fp); // Fails + while (!\feof($resource)) \fwrite($fp, \fread($resource, 8192)); + $oBody->Body = null; $oBody->SubParts->Clear(); $oMessage->SubParts->Clear(); $oMessage->Attachments()->Clear(); - \MailSo\Base\StreamFilters\LineEndings::appendTo($resource); - $fp = \fopen('php://temp', 'r+b'); - \stream_copy_to_stream($resource, $fp); $GPG->addSignKey($sFingerprint, $sPassphrase); $GPG->setsignmode(GNUPG_SIG_MODE_DETACH); $sSignature = $GPG->signStream($fp); @@ -1317,17 +1322,19 @@ trait Messages if ($aFingerprints) { $GPG = $this->GnuPG(); $oBody = $oMessage->GetRootPart(); - $fp = \fopen('php://temp', 'r+b'); $resource = $oBody->ToStream(); - \stream_copy_to_stream($resource, $fp); + $fp = \fopen('php://temp', 'r+b'); +// \stream_copy_to_stream($resource, $fp); // Fails + while (!\feof($resource)) \fwrite($fp, \fread($resource, 8192)); + + $oMessage->SubParts->Clear(); + $oMessage->Attachments()->Clear(); + foreach ($aFingerprints as $sFingerprint) { $GPG->addEncryptKey($sFingerprint); } $sEncrypted = $GPG->encryptStream($fp); - $oMessage->SubParts->Clear(); - $oMessage->Attachments()->Clear(); - $oPart = new MimePart; $oPart->Headers->AddByName( \MailSo\Mime\Enumerations\Header::CONTENT_TYPE,