From 15631427b058c246605eb442dad4d85b38567cd3 Mon Sep 17 00:00:00 2001 From: djmaze Date: Wed, 10 Feb 2021 15:47:22 +0100 Subject: [PATCH] Use PharData to create Zip when ZipArchive is not available --- dev/View/User/MailBox/MessageView.js | 4 +- .../0.0.0/app/libraries/RainLoop/Actions.php | 2 +- .../app/libraries/RainLoop/Actions/User.php | 48 ++++++++++++------- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/dev/View/User/MailBox/MessageView.js b/dev/View/User/MailBox/MessageView.js index 2f9a2d8b3..bcd795d77 100644 --- a/dev/View/User/MailBox/MessageView.js +++ b/dev/View/User/MailBox/MessageView.js @@ -717,8 +717,8 @@ class MessageViewMailBoxUserView extends AbstractViewRight { if (hashes.length) { Remote.attachmentsActions('Zip', hashes, this.downloadAsZipLoading) .then((result) => { - if (result && result.Result && result.Result.Files && result.Result.Files[0] && result.Result.Files[0].Hash) { - rl.app.download(attachmentDownload(result.Result.Files[0].Hash)); + if (result && result.Result && result.Result.FileHash) { + rl.app.download(attachmentDownload(result.Result.FileHash)); } else { this.downloadAsZipError(true); } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php index 8c7fc1f84..5d3e4d5c4 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -989,7 +989,7 @@ class Actions $aAttachmentsActions = array(); if ($this->GetCapa(false, $bMobile, Enumerations\Capa::ATTACHMENTS_ACTIONS)) { - if (\class_exists('ZipArchive')) { + if (\class_exists('PharData') || \class_exists('ZipArchive')) { $aAttachmentsActions[] = 'zip'; } } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/User.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/User.php index ff165096e..e28efb9a6 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/User.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/User.php @@ -131,13 +131,11 @@ trait User { case 'zip': - if (\class_exists('ZipArchive')) - { - $sZipHash = \MailSo\Base\Utils::Md5Rand(); - $sZipFileName = $oFilesProvider->GenerateLocalFullFileName($oAccount, $sZipHash); + $sZipHash = \MailSo\Base\Utils::Md5Rand(); + $sZipFileName = $oFilesProvider->GenerateLocalFullFileName($oAccount, $sZipHash); - if (!empty($sZipFileName)) - { + if (!empty($sZipFileName)) { + if (\class_exists('ZipArchive')) { $oZip = new \ZipArchive(); $oZip->open($sZipFileName, \ZIPARCHIVE::CREATE | \ZIPARCHIVE::OVERWRITE); $oZip->setArchiveComment('SnappyMail/'.APP_VERSION); @@ -165,12 +163,33 @@ trait User { $oZip->close(); } + } else { + @\unlink($sZipFileName); + $oZip = new \PharData($sZipFileName . '.zip', 0, null, \Phar::ZIP); + $oZip->compressFiles(\Phar::GZ); + + foreach ($aData as $aItem) + { + $sFileName = (isset($aItem['FileName']) ? (string) $aItem['FileName'] : 'file.dat'); + $sFileHash = (isset($aItem['FileHash']) ? (string) $aItem['FileHash'] : ''); + + if ($sFileHash) + { + $sFullFileNameHash = $oFilesProvider->GetFileName($oAccount, $sFileHash); + $oZip->addFile($sFullFileNameHash, $sFileName); + } + } + + $oZip->compressFiles(\Phar::GZ); + + unset($oZip); + \rename($sZipFileName . '.zip', $sZipFileName); } foreach ($aData as $aItem) { - $sFileHash = (string) (isset($aItem['FileHash']) ? $aItem['FileHash'] : ''); - if (!empty($sFileHash)) + $sFileHash = (isset($aItem['FileHash']) ? (string) $aItem['FileHash'] : ''); + if ($sFileHash) { $oFilesProvider->Clear($oAccount, $sFileHash); } @@ -179,15 +198,12 @@ trait User if (!$bError) { $mResult = array( - 'Files' => array(array( + 'FileHash' => Utils::EncodeKeyValuesQ(array( + 'V' => APP_VERSION, + 'Account' => $oAccount ? \md5($oAccount->Hash()) : '', 'FileName' => 'attachments.zip', - 'Hash' => Utils::EncodeKeyValuesQ(array( - 'V' => APP_VERSION, - 'Account' => $oAccount ? \md5($oAccount->Hash()) : '', - 'FileName' => 'attachments.zip', - 'MimeType' => 'application/zip', - 'FileHash' => $sZipHash - )) + 'MimeType' => 'application/zip', + 'FileHash' => $sZipHash )) ); }