mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-05 23:47:03 +03:00
Added MainAccount class for better distinguishing it from the additional ones
This commit is contained in:
parent
42bf782c6a
commit
0de87e334c
9 changed files with 48 additions and 57 deletions
|
|
@ -1420,7 +1420,7 @@ class Actions
|
||||||
$sFolderFullNameRaw = $this->GetActionParam('Folder', '');
|
$sFolderFullNameRaw = $this->GetActionParam('Folder', '');
|
||||||
|
|
||||||
$_FILES = isset($_FILES) ? $_FILES : null;
|
$_FILES = isset($_FILES) ? $_FILES : null;
|
||||||
if ($oAccount instanceof Model\Account &&
|
if ($oAccount &&
|
||||||
$this->Config()->Get('labs', 'allow_message_append', false) &&
|
$this->Config()->Get('labs', 'allow_message_append', false) &&
|
||||||
isset($_FILES, $_FILES['AppendFile'], $_FILES['AppendFile']['name'],
|
isset($_FILES, $_FILES['AppendFile'], $_FILES['AppendFile']['name'],
|
||||||
$_FILES['AppendFile']['tmp_name'], $_FILES['AppendFile']['size'])) {
|
$_FILES['AppendFile']['tmp_name'], $_FILES['AppendFile']['size'])) {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace RainLoop\Actions;
|
||||||
use RainLoop\Enumerations\Capa;
|
use RainLoop\Enumerations\Capa;
|
||||||
use RainLoop\Exceptions\ClientException;
|
use RainLoop\Exceptions\ClientException;
|
||||||
use RainLoop\Model\Account;
|
use RainLoop\Model\Account;
|
||||||
|
use RainLoop\Model\MainAccount;
|
||||||
use RainLoop\Model\AdditionalAccount;
|
use RainLoop\Model\AdditionalAccount;
|
||||||
use RainLoop\Model\Identity;
|
use RainLoop\Model\Identity;
|
||||||
use RainLoop\Notifications;
|
use RainLoop\Notifications;
|
||||||
|
|
@ -19,11 +20,8 @@ trait Accounts
|
||||||
return $oAccount instanceof AdditionalAccount ? $oAccount->ParentEmail() : $oAccount->Email();
|
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)) {
|
if ($this->GetCapa(false, Capa::ADDITIONAL_ACCOUNTS, $oAccount)) {
|
||||||
$sAccounts = $this->StorageProvider()->Get($oAccount,
|
$sAccounts = $this->StorageProvider()->Get($oAccount,
|
||||||
StorageType::CONFIG,
|
StorageType::CONFIG,
|
||||||
|
|
@ -41,7 +39,7 @@ trait Accounts
|
||||||
/**
|
/**
|
||||||
* Attempt to convert the old less secure data into better secured data
|
* 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');
|
$sAccounts = $this->StorageProvider()->Get($oMainAccount, StorageType::CONFIG, 'accounts');
|
||||||
if (!$sAccounts || '{' !== $sAccounts[0]) {
|
if (!$sAccounts || '{' !== $sAccounts[0]) {
|
||||||
|
|
@ -113,11 +111,8 @@ trait Accounts
|
||||||
return $aNewAccounts;
|
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();
|
$sParentEmail = $oAccount->Email();
|
||||||
if ($aAccounts) {
|
if ($aAccounts) {
|
||||||
$this->StorageProvider()->Put(
|
$this->StorageProvider()->Put(
|
||||||
|
|
@ -303,10 +298,9 @@ trait Accounts
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Account $oAccount
|
|
||||||
* @return Identity[]
|
* @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
|
// A custom name for a single identity is also stored in this system
|
||||||
$allowMultipleIdentities = $this->GetCapa(false, Capa::IDENTITIES, $oAccount);
|
$allowMultipleIdentities = $this->GetCapa(false, Capa::IDENTITIES, $oAccount);
|
||||||
|
|
|
||||||
|
|
@ -323,7 +323,7 @@ trait Contacts
|
||||||
$this->AddressBookProvider($oAccount)->Export($this->GetMainEmail($oAccount), 'csv') : false;
|
$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;
|
$iCount = 0;
|
||||||
if ($oAccount && \is_resource($rFile)) {
|
if ($oAccount && \is_resource($rFile)) {
|
||||||
|
|
|
||||||
|
|
@ -201,15 +201,13 @@ trait User
|
||||||
public function DoLogout() : array
|
public function DoLogout() : array
|
||||||
{
|
{
|
||||||
$oAccount = $this->getAccountFromToken(false);
|
$oAccount = $this->getAccountFromToken(false);
|
||||||
if ($oAccount)
|
if ($oAccount) {
|
||||||
{
|
if ($oAccount instanceof \RainLoop\Model\MainAccount) {
|
||||||
if (!\is_subclass_of($oAccount, 'RainLoop\\Model\\Account'))
|
|
||||||
{
|
|
||||||
$this->ClearSignMeData();
|
$this->ClearSignMeData();
|
||||||
Utils::ClearCookie(self::AUTH_SPEC_TOKEN_KEY);
|
Utils::ClearCookie(self::AUTH_SPEC_TOKEN_KEY);
|
||||||
}
|
}
|
||||||
|
Utils::ClearCookie(self::AUTH_ADDITIONAL_TOKEN_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->TrueResponse(__FUNCTION__);
|
return $this->TrueResponse(__FUNCTION__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace RainLoop\Actions;
|
||||||
use RainLoop\Notifications;
|
use RainLoop\Notifications;
|
||||||
use RainLoop\Utils;
|
use RainLoop\Utils;
|
||||||
use RainLoop\Model\Account;
|
use RainLoop\Model\Account;
|
||||||
|
use RainLoop\Model\MainAccount;
|
||||||
use RainLoop\Model\AdditionalAccount;
|
use RainLoop\Model\AdditionalAccount;
|
||||||
use RainLoop\Providers\Storage\Enumerations\StorageType;
|
use RainLoop\Providers\Storage\Enumerations\StorageType;
|
||||||
use RainLoop\Exceptions\ClientException;
|
use RainLoop\Exceptions\ClientException;
|
||||||
|
|
@ -119,7 +120,7 @@ trait UserAuth
|
||||||
$oAccount->SetParentEmail($oMainAccount->Email());
|
$oAccount->SetParentEmail($oMainAccount->Email());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$oAccount = Account::NewInstanceByLogin($this, $sEmail, $sLogin, $sPassword, $sClientCert, true);
|
$oAccount = MainAccount::NewInstanceByLogin($this, $sEmail, $sLogin, $sPassword, $sClientCert, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$oAccount) {
|
if (!$oAccount) {
|
||||||
|
|
@ -197,11 +198,9 @@ trait UserAuth
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns RainLoop\Model\Account when it exists, else null
|
|
||||||
*
|
|
||||||
* @throws \RainLoop\Exceptions\ClientException
|
* @throws \RainLoop\Exceptions\ClientException
|
||||||
*/
|
*/
|
||||||
public function getMainAccountFromToken(bool $bThrowExceptionOnFalse = true): ?Account
|
public function getMainAccountFromToken(bool $bThrowExceptionOnFalse = true): ?MainAccount
|
||||||
{
|
{
|
||||||
if (!$this->oMainAuthAccount) {
|
if (!$this->oMainAuthAccount) {
|
||||||
if (isset($_COOKIE[self::AUTH_SPEC_LOGOUT_TOKEN_KEY])) {
|
if (isset($_COOKIE[self::AUTH_SPEC_LOGOUT_TOKEN_KEY])) {
|
||||||
|
|
@ -213,7 +212,7 @@ trait UserAuth
|
||||||
|
|
||||||
$aData = Utils::GetSecureCookie(self::AUTH_SPEC_TOKEN_KEY);
|
$aData = Utils::GetSecureCookie(self::AUTH_SPEC_TOKEN_KEY);
|
||||||
if ($aData) {
|
if ($aData) {
|
||||||
$this->oMainAuthAccount = Account::NewInstanceFromTokenArray(
|
$this->oMainAuthAccount = MainAccount::NewInstanceFromTokenArray(
|
||||||
$this,
|
$this,
|
||||||
$aData,
|
$aData,
|
||||||
$bThrowExceptionOnFalse
|
$bThrowExceptionOnFalse
|
||||||
|
|
@ -233,11 +232,8 @@ trait UserAuth
|
||||||
return $this->oMainAuthAccount;
|
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->oAdditionalAuthAccount = false;
|
||||||
$this->oMainAuthAccount = $oAccount;
|
$this->oMainAuthAccount = $oAccount;
|
||||||
Utils::SetSecureCookie(self::AUTH_SPEC_TOKEN_KEY, $oAccount);
|
Utils::SetSecureCookie(self::AUTH_SPEC_TOKEN_KEY, $oAccount);
|
||||||
|
|
@ -270,7 +266,7 @@ trait UserAuth
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function SetSignMeToken(Account $oAccount): void
|
private function SetSignMeToken(MainAccount $oAccount): void
|
||||||
{
|
{
|
||||||
$this->ClearSignMeData();
|
$this->ClearSignMeData();
|
||||||
|
|
||||||
|
|
@ -295,7 +291,7 @@ trait UserAuth
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetAccountFromSignMeToken(): ?Account
|
public function GetAccountFromSignMeToken(): ?MainAccount
|
||||||
{
|
{
|
||||||
$aTokenData = static::GetSignMeToken();
|
$aTokenData = static::GetSignMeToken();
|
||||||
if ($aTokenData) {
|
if ($aTokenData) {
|
||||||
|
|
@ -314,7 +310,7 @@ trait UserAuth
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$oAccount = \is_array($aAccountHash)
|
$oAccount = \is_array($aAccountHash)
|
||||||
? Account::NewInstanceFromTokenArray($this, $aAccountHash) : null;
|
? MainAccount::NewInstanceFromTokenArray($this, $aAccountHash) : null;
|
||||||
if ($oAccount) {
|
if ($oAccount) {
|
||||||
$this->CheckMailConnection($oAccount);
|
$this->CheckMailConnection($oAccount);
|
||||||
// Update lifetime
|
// Update lifetime
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ namespace RainLoop\Model;
|
||||||
use RainLoop\Utils;
|
use RainLoop\Utils;
|
||||||
use RainLoop\Exceptions\ClientException;
|
use RainLoop\Exceptions\ClientException;
|
||||||
|
|
||||||
class Account implements \JsonSerializable
|
abstract class Account implements \JsonSerializable
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
|
|
@ -42,11 +42,6 @@ class Account implements \JsonSerializable
|
||||||
*/
|
*/
|
||||||
private $oDomain;
|
private $oDomain;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $sCryptKey;
|
|
||||||
|
|
||||||
public function Email() : string
|
public function Email() : string
|
||||||
{
|
{
|
||||||
return $this->sEmail;
|
return $this->sEmail;
|
||||||
|
|
@ -99,14 +94,6 @@ class Account implements \JsonSerializable
|
||||||
return $this->IncPassword();
|
return $this->IncPassword();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function CryptKey() : string
|
|
||||||
{
|
|
||||||
if (!$this->sCryptKey) {
|
|
||||||
$this->SetCryptKey($this->IncPassword() ?: APP_SALT);
|
|
||||||
}
|
|
||||||
return $this->sCryptKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ClientCert() : string
|
public function ClientCert() : string
|
||||||
{
|
{
|
||||||
return $this->sClientCert;
|
return $this->sClientCert;
|
||||||
|
|
@ -132,11 +119,6 @@ class Account implements \JsonSerializable
|
||||||
$this->sPassword = $sPassword;
|
$this->sPassword = $sPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SetCryptKey(string $sKey) : void
|
|
||||||
{
|
|
||||||
$this->sCryptKey = \sha1($sKey, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function SetProxyAuthUser(string $sProxyAuthUser) : void
|
public function SetProxyAuthUser(string $sProxyAuthUser) : void
|
||||||
{
|
{
|
||||||
$this->sProxyAuthUser = $sProxyAuthUser;
|
$this->sProxyAuthUser = $sProxyAuthUser;
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,6 @@ class AdditionalAccount extends Account
|
||||||
$this->sParentEmail = \trim(\MailSo\Base\Utils::IdnToAscii($sParentEmail, true));
|
$this->sParentEmail = \trim(\MailSo\Base\Utils::IdnToAscii($sParentEmail, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function CryptKey() : string
|
|
||||||
{
|
|
||||||
throw new \LogicException('Not allowed on AdditionalAccount');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function Hash() : string
|
public function Hash() : string
|
||||||
{
|
{
|
||||||
return \md5(parent::Hash() . $this->sParentEmail);
|
return \md5(parent::Hash() . $this->sParentEmail);
|
||||||
|
|
@ -39,7 +34,7 @@ class AdditionalAccount extends Account
|
||||||
return $aData;
|
return $aData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function asTokenArray(Account $oMainAccount) : array
|
public function asTokenArray(MainAccount $oMainAccount) : array
|
||||||
{
|
{
|
||||||
$sHash = $oMainAccount->CryptKey();
|
$sHash = $oMainAccount->CryptKey();
|
||||||
$aData = $this->jsonSerialize();
|
$aData = $this->jsonSerialize();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace RainLoop\Model;
|
||||||
|
|
||||||
|
use RainLoop\Utils;
|
||||||
|
use RainLoop\Exceptions\ClientException;
|
||||||
|
|
||||||
|
class MainAccount extends Account
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $sCryptKey;
|
||||||
|
|
||||||
|
public function CryptKey() : string
|
||||||
|
{
|
||||||
|
if (!$this->sCryptKey) {
|
||||||
|
$this->SetCryptKey($this->IncPassword() ?: APP_SALT);
|
||||||
|
}
|
||||||
|
return $this->sCryptKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function SetCryptKey(string $sKey) : void
|
||||||
|
{
|
||||||
|
$this->sCryptKey = \sha1($sKey, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -27,8 +27,7 @@ class Suggestions extends \RainLoop\Providers\AbstractProvider
|
||||||
public function Process(\RainLoop\Model\Account $oAccount, string $sQuery, int $iLimit = 20) : array
|
public function Process(\RainLoop\Model\Account $oAccount, string $sQuery, int $iLimit = 20) : array
|
||||||
{
|
{
|
||||||
$aSuggestions = array();
|
$aSuggestions = array();
|
||||||
if ($oAccount instanceof \RainLoop\Model\Account &&
|
if ($this->IsActive() && \is_array($this->aDrivers) && 0 < \strlen($sQuery))
|
||||||
$this->IsActive() && \is_array($this->aDrivers) && 0 < \strlen($sQuery))
|
|
||||||
{
|
{
|
||||||
foreach ($this->aDrivers as $oDriver)
|
foreach ($this->aDrivers as $oDriver)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue