Skip to content

Commit

Permalink
Resolve #361
Browse files Browse the repository at this point in the history
  • Loading branch information
the-djmaze committed Nov 17, 2022
1 parent 7e1b85d commit ecf53b1
Show file tree
Hide file tree
Showing 40 changed files with 159 additions and 109 deletions.
33 changes: 31 additions & 2 deletions dev/View/User/MailBox/MessageList.js
Expand Up @@ -11,11 +11,11 @@ import { leftPanelDisabled, moveAction,
addShortcut, registerShortcut, formFieldFocused
} from 'Common/Globals';

import { computedPaginatorHelper, showMessageComposer, populateMessageBody } from 'Common/UtilsUser';
import { computedPaginatorHelper, showMessageComposer, populateMessageBody, download } from 'Common/UtilsUser';
import { FileInfo } from 'Common/File';
import { isFullscreen, toggleFullscreen } from 'Common/Fullscreen';

import { mailBox } from 'Common/Links';
import { mailBox, attachmentDownload } from 'Common/Links';
import { Selector } from 'Common/Selector';

import { i18n } from 'Common/Translator';
Expand Down Expand Up @@ -258,6 +258,7 @@ export class MailMessageList extends AbstractViewRight {
).throttle(50));

decorateKoCommands(this, {
downloadCommand: canBeMovedHelper,
forwardCommand: canBeMovedHelper,
deleteWithoutMoveCommand: canBeMovedHelper,
deleteCommand: canBeMovedHelper,
Expand Down Expand Up @@ -290,6 +291,34 @@ export class MailMessageList extends AbstractViewRight {
]);
}

downloadCommand() {
let hashes = [];
MessagelistUserStore.forEach(message => {
if (message.checked()) {
message.attachments.forEach(attachment => {
if (!attachment.isLinked() && attachment.download) {
hashes.push(attachment.download);
}
});
}
});
if (hashes.length) {
Remote.post('AttachmentsActions', null, {
Do: 'Zip',
Hashes: hashes
})
.then(result => {
let hash = result?.Result?.FileHash;
if (hash) {
download(attachmentDownload(hash), hash+'.zip');
} else {
alert('Download failed');
}
})
.catch(() => alert('Download failed'));
}
}

deleteWithoutMoveCommand() {
SettingsCapa('DangerousActions')
&& moveMessagesToFolderType(FolderType.Trash, true);
Expand Down
195 changes: 88 additions & 107 deletions snappymail/v/0.0.0/app/libraries/RainLoop/Actions/User.php
Expand Up @@ -73,142 +73,123 @@ public function DoLogin() : array
*/
public function DoAttachmentsActions() : array
{
if (!$this->GetCapa(Capa::ATTACHMENTS_ACTIONS))
{
$sAction = $this->GetActionParam('Do', '');
$aHashes = $this->GetActionParam('Hashes', null);
$oFilesProvider = $this->FilesProvider();
if (empty($sAction) || !$this->GetCapa(Capa::ATTACHMENTS_ACTIONS) || !$oFilesProvider || !$oFilesProvider->IsActive()) {
return $this->FalseResponse(__FUNCTION__);
}

$oAccount = $this->initMailClientConnection();

$sAction = $this->GetActionParam('Do', '');
$aHashes = $this->GetActionParam('Hashes', null);

$mResult = false;
$bError = false;
$aData = false;
$aData = [];
$mUIDs = [];

if (\is_array($aHashes) && \count($aHashes))
{
$aData = array();
foreach ($aHashes as $sZipHash)
{
if (\is_array($aHashes) && \count($aHashes)) {
foreach ($aHashes as $sZipHash) {
$aResult = $this->getMimeFileByHash($oAccount, $sZipHash);
if (!empty($aResult['FileHash']))
{
$aData[] = $aResult;
}
else
{
if (empty($aResult['FileHash'])) {
$bError = true;
break;
}
$aData[] = $aResult;
$mUIDs[$aResult['Uid']] = $aResult['Uid'];
}
}
$mUIDs = 1 < \count($mUIDs);

$oFilesProvider = $this->FilesProvider();
if (!empty($sAction) && !$bError && \is_array($aData) && \count($aData) &&
$oFilesProvider && $oFilesProvider->IsActive())
if ($bError || !\count($aData)) {
return $this->FalseResponse(__FUNCTION__);
}

$mResult = false;
switch (\strtolower($sAction))
{
$bError = false;
switch (\strtolower($sAction))
{
case 'zip':

$sZipHash = \MailSo\Base\Utils::Sha1Rand();
$sZipFileName = $oFilesProvider->GenerateLocalFullFileName($oAccount, $sZipHash);

if (!empty($sZipFileName)) {
if (\class_exists('ZipArchive')) {
$oZip = new \ZipArchive();
$oZip->open($sZipFileName, \ZIPARCHIVE::CREATE | \ZIPARCHIVE::OVERWRITE);
$oZip->setArchiveComment('SnappyMail/'.APP_VERSION);
foreach ($aData as $aItem) {
$sFileName = (string) (isset($aItem['FileName']) ? $aItem['FileName'] : 'file.dat');
$sFileHash = (string) (isset($aItem['FileHash']) ? $aItem['FileHash'] : '');
if (!empty($sFileHash)) {
$sFullFileNameHash = $oFilesProvider->GetFileName($oAccount, $sFileHash);
if (!$oZip->addFile($sFullFileNameHash, $sFileName)) {
$bError = true;
}
}
}
case 'zip':

if (!$bError) {
$bError = !$oZip->close();
} else {
$oZip->close();
}
/*
} else {
@\unlink($sZipFileName);
$oZip = new \SnappyMail\Stream\ZIP($sZipFileName);
// $oZip->setArchiveComment('SnappyMail/'.APP_VERSION);
foreach ($aData as $aItem) {
$sFileName = (string) (isset($aItem['FileName']) ? $aItem['FileName'] : 'file.dat');
$sFileHash = (string) (isset($aItem['FileHash']) ? $aItem['FileHash'] : '');
if (!empty($sFileHash)) {
$sFullFileNameHash = $oFilesProvider->GetFileName($oAccount, $sFileHash);
if (!$oZip->addFile($sFullFileNameHash, $sFileName)) {
$bError = true;
}
}
$sZipHash = \MailSo\Base\Utils::Sha1Rand();
$sZipFileName = $oFilesProvider->GenerateLocalFullFileName($oAccount, $sZipHash);

if (!empty($sZipFileName)) {
if (\class_exists('ZipArchive')) {
$oZip = new \ZipArchive();
$oZip->open($sZipFileName, \ZIPARCHIVE::CREATE | \ZIPARCHIVE::OVERWRITE);
$oZip->setArchiveComment('SnappyMail/'.APP_VERSION);
foreach ($aData as $aItem) {
$sFullFileNameHash = $oFilesProvider->GetFileName($oAccount, $aItem['FileHash']);
$sFileName = ($mUIDs ? "{$aItem['Uid']}/" : '') . ($aItem['FileName'] ?: 'file.dat');
if (!$oZip->addFile($sFullFileNameHash, $sFileName)) {
$bError = true;
}
}

if ($bError) {
$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);
$bError = !$oZip->close();
}

/*
} else {
@\unlink($sZipFileName);
$oZip = new \SnappyMail\Stream\ZIP($sZipFileName);
// $oZip->setArchiveComment('SnappyMail/'.APP_VERSION);
foreach ($aData as $aItem) {
$sFileHash = (isset($aItem['FileHash']) ? (string) $aItem['FileHash'] : '');
if ($sFileHash) {
$oFilesProvider->Clear($oAccount, $sFileHash);
$sFileName = (string) (isset($aItem['FileName']) ? $aItem['FileName'] : 'file.dat');
$sFileHash = (string) (isset($aItem['FileHash']) ? $aItem['FileHash'] : '');
if (!empty($sFileHash)) {
$sFullFileNameHash = $oFilesProvider->GetFileName($oAccount, $sFileHash);
if (!$oZip->addFile($sFullFileNameHash, $sFileName)) {
$bError = true;
}
}
}

if (!$bError) {
$mResult = array(
'FileHash' => Utils::EncodeKeyValuesQ(array(
'Account' => $oAccount ? $oAccount->Hash() : '',
'FileName' => 'attachments.zip',
'MimeType' => 'application/zip',
'FileHash' => $sZipHash
))
$oZip->close();
*/
} else {
@\unlink($sZipFileName);
$oZip = new \PharData($sZipFileName . '.zip', 0, null, \Phar::ZIP);
$oZip->compressFiles(\Phar::GZ);
foreach ($aData as $aItem) {
$oZip->addFile(
$oFilesProvider->GetFileName($oAccount, $aItem['FileHash']),
($mUIDs ? "{$aItem['Uid']}/" : '') . ($aItem['FileName'] ?: 'file.dat')
);
}
$oZip->compressFiles(\Phar::GZ);
unset($oZip);
\rename($sZipFileName . '.zip', $sZipFileName);
}
break;

default:
$data = new \SnappyMail\AttachmentsAction;
$data->action = $sAction;
$data->items = $aData;
$data->filesProvider = $oFilesProvider;
$data->account = $oAccount;
$this->Plugins()->RunHook('json.attachments', array($data));
$mResult = $data->result;
break;
}
}
else
{
$bError = true;
foreach ($aData as $aItem) {
$oFilesProvider->Clear($oAccount, $aItem['FileHash']);
}

if (!$bError) {
$mResult = array(
'FileHash' => Utils::EncodeKeyValuesQ(array(
'Account' => $oAccount ? $oAccount->Hash() : '',
'FileName' => 'attachments.zip',
'MimeType' => 'application/zip',
'FileHash' => $sZipHash
))
);
}
}
break;

default:
$data = new \SnappyMail\AttachmentsAction;
$data->action = $sAction;
$data->items = $aData;
$data->filesProvider = $oFilesProvider;
$data->account = $oAccount;
$this->Plugins()->RunHook('json.attachments', array($data));
$mResult = $data->result;
break;
}

$this->requestSleep();
// $this->requestSleep();
return $this->DefaultResponse(__FUNCTION__, $bError ? false : $mResult);
}

Expand Down
1 change: 1 addition & 0 deletions snappymail/v/0.0.0/app/localization/ar-SA/user.json
Expand Up @@ -98,6 +98,7 @@
"MENU_SELECT_SEEN": "مقروء",
"MENU_SELECT_FLAGGED": "محدد كـ مهم",
"MENU_SELECT_UNFLAGGED": "إزالة الأهمية",
"DOWNLOAD_ALL_ATTACHMENTS": "Download all attachments",
"EMPTY_LIST": "إفراغ القائمة",
"EMPTY_SEARCH_LIST": "ليست هناك أية رسائل تطابق بحثك.",
"SEARCH_RESULT_FOR": "نتيجة البحث لـ \"%SEARCH%\"",
Expand Down
1 change: 1 addition & 0 deletions snappymail/v/0.0.0/app/localization/bg-BG/user.json
Expand Up @@ -98,6 +98,7 @@
"MENU_SELECT_SEEN": "Прочетени",
"MENU_SELECT_FLAGGED": "Маркирани с флаг",
"MENU_SELECT_UNFLAGGED": "С премахнат флаг",
"DOWNLOAD_ALL_ATTACHMENTS": "Download all attachments",
"EMPTY_LIST": "Празен списък.",
"EMPTY_SEARCH_LIST": "Няма съобщения, които да отговарят на търсенето.",
"SEARCH_RESULT_FOR": "Резултати от търсенето за \"%SEARCH%\"",
Expand Down
1 change: 1 addition & 0 deletions snappymail/v/0.0.0/app/localization/cs-CZ/user.json
Expand Up @@ -98,6 +98,7 @@
"MENU_SELECT_SEEN": "Přečtené",
"MENU_SELECT_FLAGGED": "Označené",
"MENU_SELECT_UNFLAGGED": "Neoznačené",
"DOWNLOAD_ALL_ATTACHMENTS": "Download all attachments",
"EMPTY_LIST": "Seznam je prázdný",
"EMPTY_SEARCH_LIST": "Vašemu vyhledávání neodpovídají žádné zprávy.",
"SEARCH_RESULT_FOR": "Výsledky vyhledávání pro \"%SEARCH%\"",
Expand Down
1 change: 1 addition & 0 deletions snappymail/v/0.0.0/app/localization/da-DK/user.json
Expand Up @@ -98,6 +98,7 @@
"MENU_SELECT_SEEN": "Læst",
"MENU_SELECT_FLAGGED": "Markeret med flag",
"MENU_SELECT_UNFLAGGED": "Ikke markeret med flag",
"DOWNLOAD_ALL_ATTACHMENTS": "Download all attachments",
"EMPTY_LIST": "Ingen meddelelser.",
"EMPTY_SEARCH_LIST": "Ingen meddelelser passede på søgningen.",
"SEARCH_RESULT_FOR": "Resultat for søgningen på \"%SEARCH%\"",
Expand Down
1 change: 1 addition & 0 deletions snappymail/v/0.0.0/app/localization/de-DE/user.json
Expand Up @@ -98,6 +98,7 @@
"MENU_SELECT_SEEN": "Gelesen",
"MENU_SELECT_FLAGGED": "Markiert",
"MENU_SELECT_UNFLAGGED": "Nicht markiert",
"DOWNLOAD_ALL_ATTACHMENTS": "Download all attachments",
"EMPTY_LIST": "Liste ist leer.",
"EMPTY_SEARCH_LIST": "Keine Treffer für Ihre Suche.",
"SEARCH_RESULT_FOR": "Suchergebnisse für \"%SEARCH%\"",
Expand Down
1 change: 1 addition & 0 deletions snappymail/v/0.0.0/app/localization/el-GR/user.json
Expand Up @@ -98,6 +98,7 @@
"MENU_SELECT_SEEN": "Διαβασμένο",
"MENU_SELECT_FLAGGED": "Σημαδεμένο",
"MENU_SELECT_UNFLAGGED": "Μη σημαδεμένο",
"DOWNLOAD_ALL_ATTACHMENTS": "Download all attachments",
"EMPTY_LIST": "Άδεια λίστα.",
"EMPTY_SEARCH_LIST": "Δεν υπάρχουν μηνύματα που να ταιριάζουν στην αναζήτηση.",
"SEARCH_RESULT_FOR": "Αποτελέσματα αναζήτησης για \"%SEARCH%\"",
Expand Down
1 change: 1 addition & 0 deletions snappymail/v/0.0.0/app/localization/en-GB/user.json
Expand Up @@ -98,6 +98,7 @@
"MENU_SELECT_SEEN": "Read",
"MENU_SELECT_FLAGGED": "Flagged",
"MENU_SELECT_UNFLAGGED": "Unflagged",
"DOWNLOAD_ALL_ATTACHMENTS": "Download all attachments",
"EMPTY_LIST": "Empty list.",
"EMPTY_SEARCH_LIST": "No messages matched your search.",
"SEARCH_RESULT_FOR": "Search results for \"%SEARCH%\"",
Expand Down
1 change: 1 addition & 0 deletions snappymail/v/0.0.0/app/localization/en/user.json
Expand Up @@ -98,6 +98,7 @@
"MENU_SELECT_SEEN": "Read",
"MENU_SELECT_FLAGGED": "Flagged",
"MENU_SELECT_UNFLAGGED": "Unflagged",
"DOWNLOAD_ALL_ATTACHMENTS": "Download all attachments",
"EMPTY_LIST": "Empty list.",
"EMPTY_SEARCH_LIST": "No messages matched your search.",
"SEARCH_RESULT_FOR": "Search results for \"%SEARCH%\"",
Expand Down
1 change: 1 addition & 0 deletions snappymail/v/0.0.0/app/localization/es-ES/user.json
Expand Up @@ -98,6 +98,7 @@
"MENU_SELECT_SEEN": "Leído",
"MENU_SELECT_FLAGGED": "Destacado",
"MENU_SELECT_UNFLAGGED": "No Destacado",
"DOWNLOAD_ALL_ATTACHMENTS": "Download all attachments",
"EMPTY_LIST": "No hay mensajes.",
"EMPTY_SEARCH_LIST": "La búsqueda no ha producido resultados.",
"SEARCH_RESULT_FOR": "Resultados de búsqueda para \"%SEARCH%\"",
Expand Down
1 change: 1 addition & 0 deletions snappymail/v/0.0.0/app/localization/et-EE/user.json
Expand Up @@ -98,6 +98,7 @@
"MENU_SELECT_SEEN": "Loetud",
"MENU_SELECT_FLAGGED": "Lipuga märgitud",
"MENU_SELECT_UNFLAGGED": "Lipuga märkimata",
"DOWNLOAD_ALL_ATTACHMENTS": "Download all attachments",
"EMPTY_LIST": "Tühi nimekiri",
"EMPTY_SEARCH_LIST": "Otsingule ei vastanud ühtegi kirja",
"SEARCH_RESULT_FOR": "Vasted otsingule \"%SEARCH%\"",
Expand Down
1 change: 1 addition & 0 deletions snappymail/v/0.0.0/app/localization/fa-IR/user.json
Expand Up @@ -98,6 +98,7 @@
"MENU_SELECT_SEEN": "خوانده",
"MENU_SELECT_FLAGGED": "پرچم‌دار کردن",
"MENU_SELECT_UNFLAGGED": "پرچم‌دار نشده",
"DOWNLOAD_ALL_ATTACHMENTS": "Download all attachments",
"EMPTY_LIST": "فهرست خالی",
"EMPTY_SEARCH_LIST": "پیامی مطابق جستجوی شما پیدا نشد",
"SEARCH_RESULT_FOR": "نتایج جستجو مطابق \"%SEARCH%\"",
Expand Down
1 change: 1 addition & 0 deletions snappymail/v/0.0.0/app/localization/fi-FI/user.json
Expand Up @@ -98,6 +98,7 @@
"MENU_SELECT_SEEN": "Luetut",
"MENU_SELECT_FLAGGED": "Merkityt",
"MENU_SELECT_UNFLAGGED": "Merkkaamattomat",
"DOWNLOAD_ALL_ATTACHMENTS": "Download all attachments",
"EMPTY_LIST": "Tyhjä lista",
"EMPTY_SEARCH_LIST": "Yhtään viestiä ei löytynyt ehdoillasi.",
"SEARCH_RESULT_FOR": "Hakutulokset haulle \"%SEARCH%\"",
Expand Down
1 change: 1 addition & 0 deletions snappymail/v/0.0.0/app/localization/fr-FR/user.json
Expand Up @@ -98,6 +98,7 @@
"MENU_SELECT_SEEN": "Lu",
"MENU_SELECT_FLAGGED": "Signalés",
"MENU_SELECT_UNFLAGGED": "Non signalés",
"DOWNLOAD_ALL_ATTACHMENTS": "Download all attachments",
"EMPTY_LIST": "Liste vide.",
"EMPTY_SEARCH_LIST": "Aucun message ne correspond à votre recherche.",
"SEARCH_RESULT_FOR": "Résultats de recherche pour \"%SEARCH%\"",
Expand Down
1 change: 1 addition & 0 deletions snappymail/v/0.0.0/app/localization/hu-HU/user.json
Expand Up @@ -98,6 +98,7 @@
"MENU_SELECT_SEEN": "Olvasott",
"MENU_SELECT_FLAGGED": "Megjelölt",
"MENU_SELECT_UNFLAGGED": "Jelöletlen",
"DOWNLOAD_ALL_ATTACHMENTS": "Download all attachments",
"EMPTY_LIST": "Lista üres.",
"EMPTY_SEARCH_LIST": "Nincs a keresésnek megfelelő levél.",
"SEARCH_RESULT_FOR": "Keresési eredmények ehhez: \"%SEARCH%\"",
Expand Down

0 comments on commit ecf53b1

Please sign in to comment.