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 465735f3a..5416d1d5f 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -1420,7 +1420,7 @@ class Actions $sFolderFullNameRaw = $this->GetActionParam('Folder', ''); $_FILES = isset($_FILES) ? $_FILES : null; - if ($oAccount instanceof Model\Account && + if ($oAccount && $this->Config()->Get('labs', 'allow_message_append', false) && isset($_FILES, $_FILES['AppendFile'], $_FILES['AppendFile']['name'], $_FILES['AppendFile']['tmp_name'], $_FILES['AppendFile']['size'])) { 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 acd150dd6..2a786339c 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 @@ -5,6 +5,7 @@ namespace RainLoop\Actions; use RainLoop\Enumerations\Capa; use RainLoop\Exceptions\ClientException; use RainLoop\Model\Account; +use RainLoop\Model\MainAccount; use RainLoop\Model\AdditionalAccount; use RainLoop\Model\Identity; use RainLoop\Notifications; @@ -19,11 +20,8 @@ trait Accounts return $oAccount instanceof AdditionalAccount ? $oAccount->ParentEmail() : $oAccount->Email(); } - public function GetAccounts(Account $oAccount): array + public function GetAccounts(MainAccount $oAccount): array { - if (\is_subclass_of($oAccount, 'RainLoop\\Model\\Account')) { - throw new \LogicException('Only main account can have sub accounts'); - } if ($this->GetCapa(false, Capa::ADDITIONAL_ACCOUNTS, $oAccount)) { $sAccounts = $this->StorageProvider()->Get($oAccount, StorageType::CONFIG, @@ -41,7 +39,7 @@ trait Accounts /** * Attempt to convert the old less secure data into better secured data */ - protected function ConvertInsecureAccounts(Account $oMainAccount) : array + protected function ConvertInsecureAccounts(MainAccount $oMainAccount) : array { $sAccounts = $this->StorageProvider()->Get($oMainAccount, StorageType::CONFIG, 'accounts'); if (!$sAccounts || '{' !== $sAccounts[0]) { @@ -113,11 +111,8 @@ trait Accounts return $aNewAccounts; } - protected function SetAccounts(Account $oAccount, array $aAccounts = array()): void + protected function SetAccounts(MainAccount $oAccount, array $aAccounts = array()): void { - if (\is_subclass_of($oAccount, 'RainLoop\\Model\\Account')) { - throw new \LogicException('Only main account can have sub accounts'); - } $sParentEmail = $oAccount->Email(); if ($aAccounts) { $this->StorageProvider()->Put( @@ -303,10 +298,9 @@ trait Accounts } /** - * @param Account $oAccount * @return Identity[] */ - public function GetIdentities(Account $oAccount): array + public function GetIdentities(MainAccount $oAccount): array { // A custom name for a single identity is also stored in this system $allowMultipleIdentities = $this->GetCapa(false, Capa::IDENTITIES, $oAccount); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Contacts.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Contacts.php index da56604cf..0065d8efd 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Contacts.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Contacts.php @@ -323,7 +323,7 @@ trait Contacts $this->AddressBookProvider($oAccount)->Export($this->GetMainEmail($oAccount), 'csv') : false; } - private function importContactsFromVcfFile(Model\Account $oAccount, /*resource*/ $rFile): int + private function importContactsFromVcfFile(\RainLoop\Model\Account $oAccount, /*resource*/ $rFile): int { $iCount = 0; if ($oAccount && \is_resource($rFile)) { 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 ee5740f81..2a2241642 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 @@ -201,15 +201,13 @@ trait User public function DoLogout() : array { $oAccount = $this->getAccountFromToken(false); - if ($oAccount) - { - if (!\is_subclass_of($oAccount, 'RainLoop\\Model\\Account')) - { + if ($oAccount) { + if ($oAccount instanceof \RainLoop\Model\MainAccount) { $this->ClearSignMeData(); Utils::ClearCookie(self::AUTH_SPEC_TOKEN_KEY); } + Utils::ClearCookie(self::AUTH_ADDITIONAL_TOKEN_KEY); } - return $this->TrueResponse(__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 3eef857af..1b93ccc2e 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 @@ -5,6 +5,7 @@ namespace RainLoop\Actions; use RainLoop\Notifications; use RainLoop\Utils; use RainLoop\Model\Account; +use RainLoop\Model\MainAccount; use RainLoop\Model\AdditionalAccount; use RainLoop\Providers\Storage\Enumerations\StorageType; use RainLoop\Exceptions\ClientException; @@ -119,7 +120,7 @@ trait UserAuth $oAccount->SetParentEmail($oMainAccount->Email()); } } else { - $oAccount = Account::NewInstanceByLogin($this, $sEmail, $sLogin, $sPassword, $sClientCert, true); + $oAccount = MainAccount::NewInstanceByLogin($this, $sEmail, $sLogin, $sPassword, $sClientCert, true); } if (!$oAccount) { @@ -197,11 +198,9 @@ trait UserAuth } /** - * Returns RainLoop\Model\Account when it exists, else null - * * @throws \RainLoop\Exceptions\ClientException */ - public function getMainAccountFromToken(bool $bThrowExceptionOnFalse = true): ?Account + public function getMainAccountFromToken(bool $bThrowExceptionOnFalse = true): ?MainAccount { if (!$this->oMainAuthAccount) { if (isset($_COOKIE[self::AUTH_SPEC_LOGOUT_TOKEN_KEY])) { @@ -213,7 +212,7 @@ trait UserAuth $aData = Utils::GetSecureCookie(self::AUTH_SPEC_TOKEN_KEY); if ($aData) { - $this->oMainAuthAccount = Account::NewInstanceFromTokenArray( + $this->oMainAuthAccount = MainAccount::NewInstanceFromTokenArray( $this, $aData, $bThrowExceptionOnFalse @@ -233,11 +232,8 @@ trait UserAuth return $this->oMainAuthAccount; } - public function SetAuthToken(Account $oAccount): void + public function SetAuthToken(MainAccount $oAccount): void { - if (\is_subclass_of($oAccount, 'RainLoop\\Model\\Account')) { - throw new \LogicException('Only main Account can be set as AuthToken'); - } $this->oAdditionalAuthAccount = false; $this->oMainAuthAccount = $oAccount; Utils::SetSecureCookie(self::AUTH_SPEC_TOKEN_KEY, $oAccount); @@ -270,7 +266,7 @@ trait UserAuth return null; } - private function SetSignMeToken(Account $oAccount): void + private function SetSignMeToken(MainAccount $oAccount): void { $this->ClearSignMeData(); @@ -295,7 +291,7 @@ trait UserAuth ); } - public function GetAccountFromSignMeToken(): ?Account + public function GetAccountFromSignMeToken(): ?MainAccount { $aTokenData = static::GetSignMeToken(); if ($aTokenData) { @@ -314,7 +310,7 @@ trait UserAuth ]); $oAccount = \is_array($aAccountHash) - ? Account::NewInstanceFromTokenArray($this, $aAccountHash) : null; + ? MainAccount::NewInstanceFromTokenArray($this, $aAccountHash) : null; if ($oAccount) { $this->CheckMailConnection($oAccount); // Update lifetime diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Account.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Account.php index 1110080ee..ea97bf915 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Account.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Account.php @@ -5,7 +5,7 @@ namespace RainLoop\Model; use RainLoop\Utils; use RainLoop\Exceptions\ClientException; -class Account implements \JsonSerializable +abstract class Account implements \JsonSerializable { /** * @var string @@ -42,11 +42,6 @@ class Account implements \JsonSerializable */ private $oDomain; - /** - * @var string - */ - private $sCryptKey; - public function Email() : string { return $this->sEmail; @@ -99,14 +94,6 @@ class Account implements \JsonSerializable return $this->IncPassword(); } - public function CryptKey() : string - { - if (!$this->sCryptKey) { - $this->SetCryptKey($this->IncPassword() ?: APP_SALT); - } - return $this->sCryptKey; - } - public function ClientCert() : string { return $this->sClientCert; @@ -132,11 +119,6 @@ class Account implements \JsonSerializable $this->sPassword = $sPassword; } - public function SetCryptKey(string $sKey) : void - { - $this->sCryptKey = \sha1($sKey, true); - } - public function SetProxyAuthUser(string $sProxyAuthUser) : void { $this->sProxyAuthUser = $sProxyAuthUser; diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/AdditionalAccount.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/AdditionalAccount.php index 9cab33f68..a1063473e 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/AdditionalAccount.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/AdditionalAccount.php @@ -22,11 +22,6 @@ class AdditionalAccount extends Account $this->sParentEmail = \trim(\MailSo\Base\Utils::IdnToAscii($sParentEmail, true)); } - public function CryptKey() : string - { - throw new \LogicException('Not allowed on AdditionalAccount'); - } - public function Hash() : string { return \md5(parent::Hash() . $this->sParentEmail); @@ -39,7 +34,7 @@ class AdditionalAccount extends Account return $aData; } - public function asTokenArray(Account $oMainAccount) : array + public function asTokenArray(MainAccount $oMainAccount) : array { $sHash = $oMainAccount->CryptKey(); $aData = $this->jsonSerialize(); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/MainAccount.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/MainAccount.php new file mode 100644 index 000000000..3fa06a90f --- /dev/null +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/MainAccount.php @@ -0,0 +1,27 @@ +sCryptKey) { + $this->SetCryptKey($this->IncPassword() ?: APP_SALT); + } + return $this->sCryptKey; + } + + public function SetCryptKey(string $sKey) : void + { + $this->sCryptKey = \sha1($sKey, true); + } +} diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Suggestions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Suggestions.php index 798ca5dc6..1c9f50b8b 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Suggestions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Suggestions.php @@ -27,8 +27,7 @@ class Suggestions extends \RainLoop\Providers\AbstractProvider public function Process(\RainLoop\Model\Account $oAccount, string $sQuery, int $iLimit = 20) : array { $aSuggestions = array(); - if ($oAccount instanceof \RainLoop\Model\Account && - $this->IsActive() && \is_array($this->aDrivers) && 0 < \strlen($sQuery)) + if ($this->IsActive() && \is_array($this->aDrivers) && 0 < \strlen($sQuery)) { foreach ($this->aDrivers as $oDriver) {