From 8d3bcdc2f20f333c3cc4cb9f3b222ade97375bc4 Mon Sep 17 00:00:00 2001 From: djmaze Date: Mon, 1 Nov 2021 16:26:07 +0100 Subject: [PATCH] Merge quota requests into folders request --- dev/App/User.js | 22 +++-------------- dev/Model/FolderCollection.js | 2 ++ dev/Stores/User/Folder.js | 8 +++++++ dev/Stores/User/Quota.js | 24 ------------------- dev/View/User/MailBox/MessageList.js | 9 ++++--- .../app/libraries/MailSo/Imap/ImapClient.php | 3 +-- .../MailSo/Mail/FolderCollection.php | 5 ++++ .../app/libraries/MailSo/Mail/MailClient.php | 5 ++++ .../libraries/RainLoop/Actions/Folders.php | 18 +++++++++++++- 9 files changed, 45 insertions(+), 51 deletions(-) delete mode 100644 dev/Stores/User/Quota.js diff --git a/dev/App/User.js b/dev/App/User.js index 09d15182c..a1b35ea80 100644 --- a/dev/App/User.js +++ b/dev/App/User.js @@ -1,7 +1,7 @@ import 'External/User/ko'; -import { isArray, arrayLength, pInt, pString, forEachObjectValue } from 'Common/Utils'; -import { isPosNumeric, delegateRunOnDestroy, mailToHelper } from 'Common/UtilsUser'; +import { isArray, arrayLength, pString, forEachObjectValue } from 'Common/Utils'; +import { delegateRunOnDestroy, mailToHelper } from 'Common/UtilsUser'; import { Capa, @@ -54,7 +54,6 @@ import { IdentityUserStore } from 'Stores/User/Identity'; import { FolderUserStore } from 'Stores/User/Folder'; import { PgpUserStore } from 'Stores/User/Pgp'; import { MessageUserStore } from 'Stores/User/Message'; -import { QuotaUserStore } from 'Stores/User/Quota'; import { ThemeStore } from 'Stores/Theme'; import * as Local from 'Storage/Client'; @@ -89,7 +88,6 @@ class AppUser extends AbstractApp { this.moveCache = {}; - this.quotaDebounce = this.quota.debounce(30000); this.moveOrDeleteResponseHelper = this.moveOrDeleteResponseHelper.bind(this); this.messagesMoveTrigger = this.messagesMoveTrigger.debounce(500); @@ -468,19 +466,6 @@ class AppUser extends AbstractApp { }); } - quota() { - Remote.quota((iError, data) => { - if ( - !iError && - 1 < arrayLength(data.Result) && - isPosNumeric(data.Result[0]) && - isPosNumeric(data.Result[1]) - ) { - QuotaUserStore.populateData(pInt(data.Result[1]), pInt(data.Result[0])); - } - }); - } - /** * @param {string} folder * @param {Array=} list = [] @@ -844,7 +829,7 @@ class AppUser extends AbstractApp { }, refreshFolders); // Every 15 minutes - setInterval(()=>this.quota() | this.foldersReload(), 900000); + setInterval(()=>this.foldersReload(), 900000); ContactUserStore.init(); @@ -855,7 +840,6 @@ class AppUser extends AbstractApp { if (getFolderInboxName() !== cF) { this.folderInformation(cF); } - this.quota(); FolderUserStore.listStatusSupported() || this.folderInformationMultiply(true); }, 1000); diff --git a/dev/Model/FolderCollection.js b/dev/Model/FolderCollection.js index eeebdf9e2..8542f1686 100644 --- a/dev/Model/FolderCollection.js +++ b/dev/Model/FolderCollection.js @@ -149,6 +149,8 @@ export class FolderCollectionModel extends AbstractCollectionModel FolderUserStore.sortSupported(!!this.IsSortSupported); FolderUserStore.metadataSupported(!!this.IsMetadataSupported); FolderUserStore.listStatusSupported(!!this.IsListStatusSupported); + FolderUserStore.quotaUsage(this.quotaUsage); + FolderUserStore.quotaLimit(this.quotaLimit); FolderUserStore.sentFolder(normalizeFolder(SettingsGet('SentFolder'))); FolderUserStore.draftFolder(normalizeFolder(SettingsGet('DraftFolder'))); diff --git a/dev/Stores/User/Folder.js b/dev/Stores/User/Folder.js index a7d6a4f48..37415632a 100644 --- a/dev/Stores/User/Folder.js +++ b/dev/Stores/User/Folder.js @@ -27,6 +27,9 @@ export const FolderUserStore = new class { listStatusSupported: false, // sortMode: '', + quotaLimit: 0, + quotaUsage: 0, + sentFolder: '', draftFolder: '', spamFolder: '', @@ -103,6 +106,11 @@ export const FolderUserStore = new class { trashFolder: fSetSystemFolderType(FolderType.Trash), archiveFolder: fSetSystemFolderType(FolderType.Archive) }); + + this.quotaPercentage = ko.computed(() => { + const quota = this.quotaLimit(), usage = this.quotaUsage(); + return 0 < quota ? Math.ceil((usage / quota) * 100) : 0; + }); } /** diff --git a/dev/Stores/User/Quota.js b/dev/Stores/User/Quota.js deleted file mode 100644 index c5ba326ce..000000000 --- a/dev/Stores/User/Quota.js +++ /dev/null @@ -1,24 +0,0 @@ -import ko from 'ko'; - -export const QuotaUserStore = new class { - constructor() { - this.quota = ko.observable(0); - this.usage = ko.observable(0); - - this.percentage = ko.computed(() => { - const quota = this.quota(), - usage = this.usage(); - - return 0 < quota ? Math.ceil((usage / quota) * 100) : 0; - }); - } - - /** - * @param {number} quota - * @param {number} usage - */ - populateData(quota, usage) { - this.quota(quota * 1024); - this.usage(usage * 1024); - } -}; diff --git a/dev/View/User/MailBox/MessageList.js b/dev/View/User/MailBox/MessageList.js index e31ea6afa..aee2bf1bf 100644 --- a/dev/View/User/MailBox/MessageList.js +++ b/dev/View/User/MailBox/MessageList.js @@ -31,7 +31,6 @@ import { } from 'Common/Cache'; import { AppUserStore } from 'Stores/User/App'; -import { QuotaUserStore } from 'Stores/User/Quota'; import { SettingsUserStore } from 'Stores/User/Settings'; import { FolderUserStore } from 'Stores/User/Folder'; import { MessageUserStore } from 'Stores/User/Message'; @@ -84,7 +83,7 @@ export class MailMessageList extends AbstractViewRight { initOnStartOrLangChange(() => this.emptySubjectValue = i18n('MESSAGE_LIST/EMPTY_SUBJECT_TEXT')); - this.userUsageProc = QuotaUserStore.percentage; + this.userUsageProc = FolderUserStore.quotaPercentage; this.addObservables({ moveDropdownTrigger: false, @@ -908,9 +907,9 @@ export class MailMessageList extends AbstractViewRight { quotaTooltip() { return i18n('MESSAGE_LIST/QUOTA_SIZE', { - SIZE: FileInfo.friendlySize(QuotaUserStore.usage()), - PROC: QuotaUserStore.percentage(), - LIMIT: FileInfo.friendlySize(QuotaUserStore.quota()) + SIZE: FileInfo.friendlySize(FolderUserStore.quotaUsage()), + PROC: FolderUserStore.quotaPercentage(), + LIMIT: FileInfo.friendlySize(FolderUserStore.quotaLimit()) }).replace(/<[^>]+>/g, ''); } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php index cb01dd3ba..070e8393b 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php @@ -743,7 +743,7 @@ class ImapClient extends \MailSo\Net\NetClient * * @throws \MailSo\Net\Exceptions\Exception * @throws \MailSo\Imap\Exceptions\Exception - * / + */ public function Quota(string $sRootName = '') : ?array { if ($this->IsSupported('QUOTA')) @@ -753,7 +753,6 @@ class ImapClient extends \MailSo\Net\NetClient return null; } -*/ /** * https://datatracker.ietf.org/doc/html/rfc2087#section-4.3 diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/FolderCollection.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/FolderCollection.php index 51ee09065..0980b96b6 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/FolderCollection.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/FolderCollection.php @@ -57,6 +57,9 @@ class FolderCollection extends \MailSo\Base\Collection */ public $SystemFolders = array(); + public $quotaUsage = 0; + public $quotaLimit = 0; + public function append($oFolder, bool $bToTop = false) : void { assert($oFolder instanceof Folder); @@ -149,6 +152,8 @@ class FolderCollection extends \MailSo\Base\Collection 'IsThreadsSupported' => $this->IsThreadsSupported, 'IsSortSupported' => $this->IsSortSupported, 'IsListStatusSupported' => $this->IsListStatusSupported, + 'quotaUsage' => $this->quotaUsage, + 'quotaLimit' => $this->quotaLimit, 'Optimized' => $this->Optimized, 'CountRec' => $this->CountRec(), 'SystemFolders' => empty($this->SystemFolders) ? null : $this->SystemFolders diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php index 062f6bf4f..743d54bad 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php @@ -1771,6 +1771,11 @@ class MailClient return $oMessageCollection; } + public function Quota(string $sRootName = '') : ?array + { + return $this->oImapClient->Quota($sRootName); + } + public function QuotaRoot(string $sFolderName = 'INBOX') : ?array { return $this->oImapClient->QuotaRoot($sFolderName); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Folders.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Folders.php index 1a16bbc4c..5e17a9da0 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Folders.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Folders.php @@ -12,11 +12,27 @@ trait Folders private function getFolderCollection(bool $HideUnsubscribed) : ?\MailSo\Mail\FolderCollection { - return $this->MailClient()->Folders('', '*', + $oFolderCollection = $this->MailClient()->Folders('', '*', $HideUnsubscribed, (int) $this->Config()->Get('labs', 'imap_folder_list_limit', 200), (bool) $this->Config()->Get('labs', 'imap_use_list_status', true) ); + + if ($oFolderCollection) { + $oAccount = $this->getAccountFromToken(); + if ($this->GetCapa(false, Capa::QUOTA, $oAccount)) { + try { + $aQuota = $this->MailClient()->Quota(); +// $aQuota = $this->MailClient()->QuotaRoot(); + $oFolderCollection->quotaUsage = $aQuota[0] * 1024; + $oFolderCollection->quotaLimit = $aQuota[1] * 1024; + } catch (\Throwable $oException) { + // ignore + } + } + } + + return $oFolderCollection; } public function DoFolders() : array