From 6df9aaae435af00621af9977780c0085c4c29b1b Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Thu, 3 Feb 2022 23:04:55 +0100 Subject: [PATCH] Don't load Capa at login page and cleanup/speedup GetCapa --- .../0.0.0/app/libraries/RainLoop/Actions.php | 29 ++++++++++--------- .../libraries/RainLoop/Actions/Accounts.php | 10 +++---- .../libraries/RainLoop/Actions/Filters.php | 8 ++--- .../libraries/RainLoop/Actions/Folders.php | 2 +- .../libraries/RainLoop/Actions/Response.php | 4 +-- .../app/libraries/RainLoop/Actions/Themes.php | 2 +- .../app/libraries/RainLoop/Actions/User.php | 8 ++--- .../libraries/RainLoop/Actions/UserAuth.php | 2 +- 8 files changed, 34 insertions(+), 31 deletions(-) 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 33285d47d..91f682d64 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -509,7 +509,7 @@ class Actions { if (null === $this->oAddressBookProvider) { $oDriver = null; - if ($this->GetCapa(false, Enumerations\Capa::CONTACTS, $oAccount)) { + if ($this->GetCapa(Enumerations\Capa::CONTACTS)) { if ($this->oConfig->Get('contacts', 'enable', false) || $bForceEnable) { $oDriver = $this->fabrica('address-book', $oAccount); } @@ -643,7 +643,7 @@ class Actions $oConfig = $this->oConfig; $aAttachmentsActions = array(); - if ($this->GetCapa(false, Enumerations\Capa::ATTACHMENTS_ACTIONS)) { + if ($this->GetCapa(Enumerations\Capa::ATTACHMENTS_ACTIONS)) { if (\class_exists('PharData') || \class_exists('ZipArchive')) { $aAttachmentsActions[] = 'zip'; } @@ -784,7 +784,6 @@ class Actions $aResult['WeakPassword'] = \is_file($passfile); } - $aResult['Capa'] = $this->Capa(true); $aResult['LanguageAdmin'] = $this->ValidateLanguage($oConfig->Get('webmail', 'language_admin', 'en'), '', true); $aResult['UserLanguageAdmin'] = $this->ValidateLanguage($UserLanguageRaw, '', true, true); } else { @@ -867,11 +866,11 @@ class Actions $aResult['AutoLogout'] = (int)$oSettings->GetConf('AutoLogout', $aResult['AutoLogout']); $aResult['Layout'] = (int)$oSettings->GetConf('Layout', $aResult['Layout']); - if (!$this->GetCapa(false, Enumerations\Capa::AUTOLOGOUT, $oAccount)) { + if (!$this->GetCapa(Enumerations\Capa::AUTOLOGOUT)) { $aResult['AutoLogout'] = 0; } - if ($this->GetCapa(false, Enumerations\Capa::USER_BACKGROUND, $oAccount)) { + if ($this->GetCapa(Enumerations\Capa::USER_BACKGROUND)) { $aResult['UserBackgroundName'] = (string)$oSettings->GetConf('UserBackgroundName', $aResult['UserBackgroundName']); $aResult['UserBackgroundHash'] = (string)$oSettings->GetConf('UserBackgroundHash', $aResult['UserBackgroundHash']); } @@ -894,11 +893,10 @@ class Actions $aResult['AdditionalLoginError'] = $this->GetSpecLogoutCustomMgsWithDeletion(); } } - - $aResult['Capa'] = $this->Capa(false, $oAccount); } if ($aResult['Auth']) { + $aResult['Capa'] = $this->Capa($bAdmin, $oAccount); $aResult['PhpUploadSizes'] = array( 'upload_max_filesize' => \ini_get('upload_max_filesize'), 'post_max_size' => \ini_get('post_max_size') @@ -1081,7 +1079,7 @@ class Actions { $oAccount = $this->getAccountFromToken(); - if (!$this->GetCapa(false, Enumerations\Capa::USER_BACKGROUND, $oAccount)) { + if (!$this->GetCapa(Enumerations\Capa::USER_BACKGROUND)) { return $this->FalseResponse(__FUNCTION__); } @@ -1160,9 +1158,16 @@ class Actions public function Capa(bool $bAdmin, ?Model\Account $oAccount = null): array { + static $aResult; + if ($aResult && !$oAccount) { + return $aResult; + } + $oConfig = $this->oConfig; - $aResult = array(); + $aResult = array( + Enumerations\Capa::AUTOLOGOUT + ); if ($oConfig->Get('capa', 'dangerous_actions', true)) { $aResult[] = Enumerations\Capa::DANGEROUS_ACTIONS; @@ -1231,14 +1236,12 @@ class Actions $aResult[] = Enumerations\Capa::KOLAB; } - $aResult[] = Enumerations\Capa::AUTOLOGOUT; - return $aResult; } - public function GetCapa(bool $bAdmin, string $sName, ?Model\Account $oAccount = null): bool + public function GetCapa(string $sName, ?Model\Account $oAccount = null): bool { - return \in_array($sName, $this->Capa($bAdmin, $oAccount)); + return \in_array($sName, $this->Capa(false, $oAccount)); } public function etag(string $sKey): string diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Accounts.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Accounts.php index 2a0a1e274..f0369d2a5 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Accounts.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Accounts.php @@ -36,7 +36,7 @@ trait Accounts public function GetAccounts(MainAccount $oAccount): array { - if ($this->GetCapa(false, Capa::ADDITIONAL_ACCOUNTS, $oAccount)) { + if ($this->GetCapa(Capa::ADDITIONAL_ACCOUNTS)) { $sAccounts = $this->StorageProvider()->Get($oAccount, StorageType::CONFIG, 'additionalaccounts' @@ -76,7 +76,7 @@ trait Accounts { $oMainAccount = $this->getMainAccountFromToken(); - if (!$this->GetCapa(false, Capa::ADDITIONAL_ACCOUNTS, $oMainAccount)) { + if (!$this->GetCapa(Capa::ADDITIONAL_ACCOUNTS)) { return $this->FalseResponse(__FUNCTION__); } @@ -108,7 +108,7 @@ trait Accounts { $oMainAccount = $this->getMainAccountFromToken(); - if (!$this->GetCapa(false, Capa::ADDITIONAL_ACCOUNTS, $oMainAccount)) { + if (!$this->GetCapa(Capa::ADDITIONAL_ACCOUNTS)) { return $this->FalseResponse(__FUNCTION__); } @@ -190,7 +190,7 @@ trait Accounts { $oAccount = $this->getAccountFromToken(); - if (!$this->GetCapa(false, Capa::IDENTITIES, $oAccount)) { + if (!$this->GetCapa(Capa::IDENTITIES)) { return $this->FalseResponse(__FUNCTION__); } @@ -254,7 +254,7 @@ trait Accounts public function GetIdentities(Account $oAccount): array { // A custom name for a single identity is also stored in this system - $allowMultipleIdentities = $this->GetCapa(false, Capa::IDENTITIES, $oAccount); + $allowMultipleIdentities = $this->GetCapa(Capa::IDENTITIES); // Get all identities $identities = $this->IdentitiesProvider()->GetIdentities($oAccount, $allowMultipleIdentities); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Filters.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Filters.php index 22267110f..8bd635a80 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Filters.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Filters.php @@ -18,7 +18,7 @@ trait Filters { $oAccount = $this->getAccountFromToken(); - if (!$this->GetCapa(false, Capa::SIEVE, $oAccount)) + if (!$this->GetCapa(Capa::SIEVE, $oAccount)) { return $this->FalseResponse(__FUNCTION__); } @@ -33,7 +33,7 @@ trait Filters { $oAccount = $this->getAccountFromToken(); - if (!$this->GetCapa(false, Capa::SIEVE, $oAccount)) { + if (!$this->GetCapa(Capa::SIEVE, $oAccount)) { return $this->FalseResponse(__FUNCTION__); } @@ -68,7 +68,7 @@ trait Filters { $oAccount = $this->getAccountFromToken(); - if (!$this->GetCapa(false, Capa::SIEVE, $oAccount)) { + if (!$this->GetCapa(Capa::SIEVE, $oAccount)) { return $this->FalseResponse(__FUNCTION__); } @@ -84,7 +84,7 @@ trait Filters { $oAccount = $this->getAccountFromToken(); - if (!$this->GetCapa(false, Capa::SIEVE, $oAccount)) { + if (!$this->GetCapa(Capa::SIEVE, $oAccount)) { return $this->FalseResponse(__FUNCTION__); } 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 2f31bb89c..59889fdc3 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 @@ -177,7 +177,7 @@ trait Folders $this->Plugins()->RunHook('filter.folders-complete', array($oAccount, $oFolderCollection)); $aQuota = null; - if ($this->GetCapa(false, Capa::QUOTA, $this->getAccountFromToken())) { + if ($this->GetCapa(Capa::QUOTA)) { try { // $aQuota = $this->MailClient()->Quota(); $aQuota = $this->MailClient()->QuotaRoot(); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Response.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Response.php index e1b15f240..cc414cbb9 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Response.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Response.php @@ -210,7 +210,7 @@ trait Response $mResult['Html'] = $mResponse->Html(); $mResult['Plain'] = $mResponse->Plain(); -// $this->GetCapa(false, Capa::OPEN_PGP) || $this->GetCapa(false, Capa::GNUPG) +// $this->GetCapa(Capa::OPEN_PGP) || $this->GetCapa(Capa::GNUPG) $mResult['isPgpEncrypted'] = $mResponse->isPgpEncrypted(); $mResult['PgpSigned'] = $mResponse->PgpSigned(); $mResult['PgpEncrypted'] = $mResponse->PgpEncrypted(); @@ -248,7 +248,7 @@ trait Response { $mResult = $mResponse->jsonSerialize(); $mResult['Framed'] = $this->isFileHasFramedPreview($mResult['FileName']); - $mResult['IsThumbnail'] = $this->GetCapa(false, Capa::ATTACHMENT_THUMBNAILS) && $this->isFileHasThumbnail($mResult['FileName']); + $mResult['IsThumbnail'] = $this->GetCapa(Capa::ATTACHMENT_THUMBNAILS) && $this->isFileHasThumbnail($mResult['FileName']); $mResult['Download'] = Utils::EncodeKeyValuesQ(array( 'V' => APP_VERSION, 'Account' => $this->getAccountFromToken()->Hash(), diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Themes.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Themes.php index 2953f0296..bd1ee1473 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Themes.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Themes.php @@ -11,7 +11,7 @@ trait Themes $sTheme = $this->Config()->Get('webmail', 'theme', 'Default'); if (!$bAdmin && ($oAccount = $this->getAccountFromToken(false)) - && $this->GetCapa(false, \RainLoop\Enumerations\Capa::THEMES, $oAccount) + && $this->GetCapa(\RainLoop\Enumerations\Capa::THEMES) && ($oSettingsLocal = $this->SettingsProvider(true)->Load($oAccount))) { $sTheme = (string) $oSettingsLocal->GetConf('Theme', $sTheme); } 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 0dd07a20b..6704d72ea 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 @@ -87,7 +87,7 @@ trait User */ public function DoAttachmentsActions() : array { - if (!$this->GetCapa(false, Capa::ATTACHMENTS_ACTIONS)) + if (!$this->GetCapa(Capa::ATTACHMENTS_ACTIONS)) { return $this->FalseResponse(__FUNCTION__); } @@ -320,7 +320,7 @@ trait User $oSettings->SetConf('Language', $this->ValidateLanguage($oConfig->Get('webmail', 'language', 'en'))); } - if ($this->GetCapa(false, Capa::THEMES, $oAccount)) + if ($this->GetCapa(Capa::THEMES)) { $this->setSettingsFromParams($oSettingsLocal, 'Theme', 'string', function ($sTheme) use ($self) { return $self->ValidateTheme($sTheme); @@ -367,7 +367,7 @@ trait User { $oAccount = $this->initMailClientConnection(); - if (!$this->GetCapa(false, Capa::QUOTA, $oAccount)) + if (!$this->GetCapa(Capa::QUOTA)) { return $this->DefaultResponse(__FUNCTION__, array(0, 0, 0, 0)); } @@ -463,7 +463,7 @@ trait User { $oAccount = $this->getAccountFromToken(); - if (!$this->GetCapa(false, Capa::USER_BACKGROUND, $oAccount)) + if (!$this->GetCapa(Capa::USER_BACKGROUND)) { return $this->FalseResponse(__FUNCTION__); } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/UserAuth.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/UserAuth.php index c1ed5e0f7..7111f5294 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/UserAuth.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/UserAuth.php @@ -160,7 +160,7 @@ trait UserAuth { $this->Http()->ServerNoCache(); $oMainAccount = $this->getMainAccountFromToken(false); - if ($sEmail && $oMainAccount && $this->GetCapa(false, \RainLoop\Enumerations\Capa::ADDITIONAL_ACCOUNTS, $oMainAccount)) { + if ($sEmail && $oMainAccount && $this->GetCapa(\RainLoop\Enumerations\Capa::ADDITIONAL_ACCOUNTS)) { $oAccount = null; if ($oMainAccount->Email() === $sEmail) { $this->SetAdditionalAuthToken($oAccount);