mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Merge quota requests into folders request
This commit is contained in:
parent
20eb01de08
commit
8d3bcdc2f2
9 changed files with 45 additions and 51 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import 'External/User/ko';
|
import 'External/User/ko';
|
||||||
|
|
||||||
import { isArray, arrayLength, pInt, pString, forEachObjectValue } from 'Common/Utils';
|
import { isArray, arrayLength, pString, forEachObjectValue } from 'Common/Utils';
|
||||||
import { isPosNumeric, delegateRunOnDestroy, mailToHelper } from 'Common/UtilsUser';
|
import { delegateRunOnDestroy, mailToHelper } from 'Common/UtilsUser';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Capa,
|
Capa,
|
||||||
|
|
@ -54,7 +54,6 @@ import { IdentityUserStore } from 'Stores/User/Identity';
|
||||||
import { FolderUserStore } from 'Stores/User/Folder';
|
import { FolderUserStore } from 'Stores/User/Folder';
|
||||||
import { PgpUserStore } from 'Stores/User/Pgp';
|
import { PgpUserStore } from 'Stores/User/Pgp';
|
||||||
import { MessageUserStore } from 'Stores/User/Message';
|
import { MessageUserStore } from 'Stores/User/Message';
|
||||||
import { QuotaUserStore } from 'Stores/User/Quota';
|
|
||||||
import { ThemeStore } from 'Stores/Theme';
|
import { ThemeStore } from 'Stores/Theme';
|
||||||
|
|
||||||
import * as Local from 'Storage/Client';
|
import * as Local from 'Storage/Client';
|
||||||
|
|
@ -89,7 +88,6 @@ class AppUser extends AbstractApp {
|
||||||
|
|
||||||
this.moveCache = {};
|
this.moveCache = {};
|
||||||
|
|
||||||
this.quotaDebounce = this.quota.debounce(30000);
|
|
||||||
this.moveOrDeleteResponseHelper = this.moveOrDeleteResponseHelper.bind(this);
|
this.moveOrDeleteResponseHelper = this.moveOrDeleteResponseHelper.bind(this);
|
||||||
|
|
||||||
this.messagesMoveTrigger = this.messagesMoveTrigger.debounce(500);
|
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 {string} folder
|
||||||
* @param {Array=} list = []
|
* @param {Array=} list = []
|
||||||
|
|
@ -844,7 +829,7 @@ class AppUser extends AbstractApp {
|
||||||
}, refreshFolders);
|
}, refreshFolders);
|
||||||
|
|
||||||
// Every 15 minutes
|
// Every 15 minutes
|
||||||
setInterval(()=>this.quota() | this.foldersReload(), 900000);
|
setInterval(()=>this.foldersReload(), 900000);
|
||||||
|
|
||||||
ContactUserStore.init();
|
ContactUserStore.init();
|
||||||
|
|
||||||
|
|
@ -855,7 +840,6 @@ class AppUser extends AbstractApp {
|
||||||
if (getFolderInboxName() !== cF) {
|
if (getFolderInboxName() !== cF) {
|
||||||
this.folderInformation(cF);
|
this.folderInformation(cF);
|
||||||
}
|
}
|
||||||
this.quota();
|
|
||||||
FolderUserStore.listStatusSupported() || this.folderInformationMultiply(true);
|
FolderUserStore.listStatusSupported() || this.folderInformationMultiply(true);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,8 @@ export class FolderCollectionModel extends AbstractCollectionModel
|
||||||
FolderUserStore.sortSupported(!!this.IsSortSupported);
|
FolderUserStore.sortSupported(!!this.IsSortSupported);
|
||||||
FolderUserStore.metadataSupported(!!this.IsMetadataSupported);
|
FolderUserStore.metadataSupported(!!this.IsMetadataSupported);
|
||||||
FolderUserStore.listStatusSupported(!!this.IsListStatusSupported);
|
FolderUserStore.listStatusSupported(!!this.IsListStatusSupported);
|
||||||
|
FolderUserStore.quotaUsage(this.quotaUsage);
|
||||||
|
FolderUserStore.quotaLimit(this.quotaLimit);
|
||||||
|
|
||||||
FolderUserStore.sentFolder(normalizeFolder(SettingsGet('SentFolder')));
|
FolderUserStore.sentFolder(normalizeFolder(SettingsGet('SentFolder')));
|
||||||
FolderUserStore.draftFolder(normalizeFolder(SettingsGet('DraftFolder')));
|
FolderUserStore.draftFolder(normalizeFolder(SettingsGet('DraftFolder')));
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,9 @@ export const FolderUserStore = new class {
|
||||||
listStatusSupported: false,
|
listStatusSupported: false,
|
||||||
// sortMode: '',
|
// sortMode: '',
|
||||||
|
|
||||||
|
quotaLimit: 0,
|
||||||
|
quotaUsage: 0,
|
||||||
|
|
||||||
sentFolder: '',
|
sentFolder: '',
|
||||||
draftFolder: '',
|
draftFolder: '',
|
||||||
spamFolder: '',
|
spamFolder: '',
|
||||||
|
|
@ -103,6 +106,11 @@ export const FolderUserStore = new class {
|
||||||
trashFolder: fSetSystemFolderType(FolderType.Trash),
|
trashFolder: fSetSystemFolderType(FolderType.Trash),
|
||||||
archiveFolder: fSetSystemFolderType(FolderType.Archive)
|
archiveFolder: fSetSystemFolderType(FolderType.Archive)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.quotaPercentage = ko.computed(() => {
|
||||||
|
const quota = this.quotaLimit(), usage = this.quotaUsage();
|
||||||
|
return 0 < quota ? Math.ceil((usage / quota) * 100) : 0;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -31,7 +31,6 @@ import {
|
||||||
} from 'Common/Cache';
|
} from 'Common/Cache';
|
||||||
|
|
||||||
import { AppUserStore } from 'Stores/User/App';
|
import { AppUserStore } from 'Stores/User/App';
|
||||||
import { QuotaUserStore } from 'Stores/User/Quota';
|
|
||||||
import { SettingsUserStore } from 'Stores/User/Settings';
|
import { SettingsUserStore } from 'Stores/User/Settings';
|
||||||
import { FolderUserStore } from 'Stores/User/Folder';
|
import { FolderUserStore } from 'Stores/User/Folder';
|
||||||
import { MessageUserStore } from 'Stores/User/Message';
|
import { MessageUserStore } from 'Stores/User/Message';
|
||||||
|
|
@ -84,7 +83,7 @@ export class MailMessageList extends AbstractViewRight {
|
||||||
|
|
||||||
initOnStartOrLangChange(() => this.emptySubjectValue = i18n('MESSAGE_LIST/EMPTY_SUBJECT_TEXT'));
|
initOnStartOrLangChange(() => this.emptySubjectValue = i18n('MESSAGE_LIST/EMPTY_SUBJECT_TEXT'));
|
||||||
|
|
||||||
this.userUsageProc = QuotaUserStore.percentage;
|
this.userUsageProc = FolderUserStore.quotaPercentage;
|
||||||
|
|
||||||
this.addObservables({
|
this.addObservables({
|
||||||
moveDropdownTrigger: false,
|
moveDropdownTrigger: false,
|
||||||
|
|
@ -908,9 +907,9 @@ export class MailMessageList extends AbstractViewRight {
|
||||||
|
|
||||||
quotaTooltip() {
|
quotaTooltip() {
|
||||||
return i18n('MESSAGE_LIST/QUOTA_SIZE', {
|
return i18n('MESSAGE_LIST/QUOTA_SIZE', {
|
||||||
SIZE: FileInfo.friendlySize(QuotaUserStore.usage()),
|
SIZE: FileInfo.friendlySize(FolderUserStore.quotaUsage()),
|
||||||
PROC: QuotaUserStore.percentage(),
|
PROC: FolderUserStore.quotaPercentage(),
|
||||||
LIMIT: FileInfo.friendlySize(QuotaUserStore.quota())
|
LIMIT: FileInfo.friendlySize(FolderUserStore.quotaLimit())
|
||||||
}).replace(/<[^>]+>/g, '');
|
}).replace(/<[^>]+>/g, '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -743,7 +743,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
||||||
*
|
*
|
||||||
* @throws \MailSo\Net\Exceptions\Exception
|
* @throws \MailSo\Net\Exceptions\Exception
|
||||||
* @throws \MailSo\Imap\Exceptions\Exception
|
* @throws \MailSo\Imap\Exceptions\Exception
|
||||||
* /
|
*/
|
||||||
public function Quota(string $sRootName = '') : ?array
|
public function Quota(string $sRootName = '') : ?array
|
||||||
{
|
{
|
||||||
if ($this->IsSupported('QUOTA'))
|
if ($this->IsSupported('QUOTA'))
|
||||||
|
|
@ -753,7 +753,6 @@ class ImapClient extends \MailSo\Net\NetClient
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://datatracker.ietf.org/doc/html/rfc2087#section-4.3
|
* https://datatracker.ietf.org/doc/html/rfc2087#section-4.3
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,9 @@ class FolderCollection extends \MailSo\Base\Collection
|
||||||
*/
|
*/
|
||||||
public $SystemFolders = array();
|
public $SystemFolders = array();
|
||||||
|
|
||||||
|
public $quotaUsage = 0;
|
||||||
|
public $quotaLimit = 0;
|
||||||
|
|
||||||
public function append($oFolder, bool $bToTop = false) : void
|
public function append($oFolder, bool $bToTop = false) : void
|
||||||
{
|
{
|
||||||
assert($oFolder instanceof Folder);
|
assert($oFolder instanceof Folder);
|
||||||
|
|
@ -149,6 +152,8 @@ class FolderCollection extends \MailSo\Base\Collection
|
||||||
'IsThreadsSupported' => $this->IsThreadsSupported,
|
'IsThreadsSupported' => $this->IsThreadsSupported,
|
||||||
'IsSortSupported' => $this->IsSortSupported,
|
'IsSortSupported' => $this->IsSortSupported,
|
||||||
'IsListStatusSupported' => $this->IsListStatusSupported,
|
'IsListStatusSupported' => $this->IsListStatusSupported,
|
||||||
|
'quotaUsage' => $this->quotaUsage,
|
||||||
|
'quotaLimit' => $this->quotaLimit,
|
||||||
'Optimized' => $this->Optimized,
|
'Optimized' => $this->Optimized,
|
||||||
'CountRec' => $this->CountRec(),
|
'CountRec' => $this->CountRec(),
|
||||||
'SystemFolders' => empty($this->SystemFolders) ? null : $this->SystemFolders
|
'SystemFolders' => empty($this->SystemFolders) ? null : $this->SystemFolders
|
||||||
|
|
|
||||||
|
|
@ -1771,6 +1771,11 @@ class MailClient
|
||||||
return $oMessageCollection;
|
return $oMessageCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function Quota(string $sRootName = '') : ?array
|
||||||
|
{
|
||||||
|
return $this->oImapClient->Quota($sRootName);
|
||||||
|
}
|
||||||
|
|
||||||
public function QuotaRoot(string $sFolderName = 'INBOX') : ?array
|
public function QuotaRoot(string $sFolderName = 'INBOX') : ?array
|
||||||
{
|
{
|
||||||
return $this->oImapClient->QuotaRoot($sFolderName);
|
return $this->oImapClient->QuotaRoot($sFolderName);
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,27 @@ trait Folders
|
||||||
|
|
||||||
private function getFolderCollection(bool $HideUnsubscribed) : ?\MailSo\Mail\FolderCollection
|
private function getFolderCollection(bool $HideUnsubscribed) : ?\MailSo\Mail\FolderCollection
|
||||||
{
|
{
|
||||||
return $this->MailClient()->Folders('', '*',
|
$oFolderCollection = $this->MailClient()->Folders('', '*',
|
||||||
$HideUnsubscribed,
|
$HideUnsubscribed,
|
||||||
(int) $this->Config()->Get('labs', 'imap_folder_list_limit', 200),
|
(int) $this->Config()->Get('labs', 'imap_folder_list_limit', 200),
|
||||||
(bool) $this->Config()->Get('labs', 'imap_use_list_status', true)
|
(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
|
public function DoFolders() : array
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue