From 1670ca0db17cc882e1d28ebcf87882bb493eca0e Mon Sep 17 00:00:00 2001 From: djmaze Date: Fri, 13 Nov 2020 09:56:40 +0100 Subject: [PATCH] Checked merge https://github.com/the-djmaze/snappymail/pull/40 Some small formatting changes for ldap identities FWest98 accidentally removed `case 'suggestions': $mResult = [];` in fabrica? --- plugins/ldap-identities/LdapIdentities.php | 4 +-- .../0.0.0/app/libraries/RainLoop/Actions.php | 29 ++++++++++--------- .../libraries/RainLoop/Actions/Accounts.php | 16 +++++----- .../RainLoop/Providers/Identities.php | 10 +++---- .../Providers/Identities/FileIdentities.php | 20 +++++++------ .../Providers/Identities/IIdentities.php | 4 +-- .../Providers/Identities/TestIdentities.php | 4 +-- 7 files changed, 46 insertions(+), 41 deletions(-) diff --git a/plugins/ldap-identities/LdapIdentities.php b/plugins/ldap-identities/LdapIdentities.php index 86a37d946..da162d1a3 100644 --- a/plugins/ldap-identities/LdapIdentities.php +++ b/plugins/ldap-identities/LdapIdentities.php @@ -132,7 +132,7 @@ class LdapIdentities implements IIdentities * @inheritDoc * @throws \RainLoop\Exceptions\Exception */ - public function SetIdentities(Account $account, array $identities) + public function SetIdentities(Account $account, array $identities): void { throw new \RainLoop\Exceptions\Exception("Ldap identities provider does not support storage"); } @@ -307,4 +307,4 @@ class LdapResult /** @var string[] */ public $emails; -} \ No newline at end of file +} 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 42b36f604..56c08cc79 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -279,7 +279,11 @@ class Actions $mResult = new Providers\AddressBook\PdoAddressBook($sDsn, $sUser, $sPassword, $sDsnType); } break; + case 'identities': + $mResult = []; + break; case 'suggestions': + $mResult = []; break; case 'two-factor-auth': // Providers\TwoFactorAuth\TwoFactorAuthInterface @@ -289,8 +293,7 @@ class Actions } // Always give the file provider as last for identities, it is the override - if ($sName === 'identities') { - if ($mResult === null) $mResult = []; + if ('identities' === $sName) { $mResult[] = new Providers\Identities\FileIdentities($this->StorageProvider(true)); } @@ -921,8 +924,8 @@ class Actions empty($aAccountHash[5]) ? '' : $aAccountHash[5], empty($aAccountHash[11]) ? '' : $aAccountHash[11], $bThrowExceptionOnFalse); if ($oAccount) { - if (!empty($aAccountHash[8]) && !empty($aAccountHash[9])) // init proxy user/password - { + // init proxy user/password + if (!empty($aAccountHash[8]) && !empty($aAccountHash[9])) { $oAccount->SetProxyAuthUser($aAccountHash[8]); $oAccount->SetProxyAuthPassword($aAccountHash[9]); } @@ -1075,15 +1078,15 @@ class Actions 'Plugins' => array(), 'System' => $this->AppDataSystem($bAdmin, $bMobile, $bMobileDevice) /* - 'LoginLogo' => $oConfig->Get('branding', 'login_logo', ''), - 'LoginBackground' => $oConfig->Get('branding', 'login_background', ''), - 'LoginCss' => $oConfig->Get('branding', 'login_css', ''), - 'LoginDescription' => $oConfig->Get('branding', 'login_desc', ''), - 'UserLogo' => $oConfig->Get('branding', 'user_logo', ''), - 'UserLogoTitle' => $oConfig->Get('branding', 'user_logo_title', ''), - 'UserLogoMessage' => $oConfig->Get('branding', 'user_logo_message', ''), - 'UserIframeMessage' => $oConfig->Get('branding', 'user_iframe_message', ''), - 'UserCss' => $oConfig->Get('branding', 'user_css', ''), + 'LoginLogo' => $oConfig->Get('branding', 'login_logo', ''), + 'LoginBackground' => $oConfig->Get('branding', 'login_background', ''), + 'LoginCss' => $oConfig->Get('branding', 'login_css', ''), + 'LoginDescription' => $oConfig->Get('branding', 'login_desc', ''), + 'UserLogo' => $oConfig->Get('branding', 'user_logo', ''), + 'UserLogoTitle' => $oConfig->Get('branding', 'user_logo_title', ''), + 'UserLogoMessage' => $oConfig->Get('branding', 'user_logo_message', ''), + 'UserIframeMessage' => $oConfig->Get('branding', 'user_iframe_message', ''), + 'UserCss' => $oConfig->Get('branding', 'user_css', ''), */ ); 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 ab8f80863..682ab9499 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 @@ -175,8 +175,6 @@ trait Accounts */ public function GetIdentities(Account $account): array { - if (!$account) return []; - // A custom name for a single identity is also stored in this system $allowMultipleIdentities = $this->GetCapa(false, false, Capa::IDENTITIES, $account); @@ -185,15 +183,17 @@ trait Accounts // Sort identities $orderString = $this->StorageProvider()->Get($account, StorageType::CONFIG, 'accounts_identities_order'); - $order = json_decode($orderString, true) ?? []; - if (isset($order['Identities']) && is_array($order['Identities']) && count($order['Identities']) > 1) { - $list = array_map(function ($item) { - if ('' === $item) $item = '---'; + $order = \json_decode($orderString, true) ?? []; + if (isset($order['Identities']) && \is_array($order['Identities']) && \count($order['Identities']) > 1) { + $list = \array_map(function ($item) { + if ('' === $item) { + $item = '---'; + } return $item; }, $order['Identities']); - usort($identities, function ($a, $b) use ($list) { - return array_search($a->Id(true), $list) < array_search($b->Id(true), $list) ? -1 : 1; + \usort($identities, function ($a, $b) use ($list) { + return \array_search($a->Id(true), $list) < \array_search($b->Id(true), $list) ? -1 : 1; }); } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Identities.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Identities.php index 1d9c78bc2..885e8be42 100755 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Identities.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Identities.php @@ -22,7 +22,7 @@ class Identities extends AbstractProvider { if ($drivers === null) $drivers = []; - $this->drivers = array_filter($drivers, function ($driver) { + $this->drivers = \array_filter($drivers, function ($driver) { return $driver instanceof IIdentities; }); } @@ -38,7 +38,7 @@ class Identities extends AbstractProvider $identities = $this->MergeIdentitiesPerDriver($this->GetIdentiesPerDriver($account)); // Find the primary identity - $primaryIdentity = current(array_filter($identities, function ($identity) { + $primaryIdentity = \current(\array_filter($identities, function ($identity) { return $identity->IsAccountIdentities(); })); @@ -73,7 +73,7 @@ class Identities extends AbstractProvider // If it is a new identity we add it to any storage driver if ($isNew) { // Pick any storage driver to store the result, typically only file storage - $storageDriver = current(array_filter($this->drivers, function ($driver) { + $storageDriver = \current(\array_filter($this->drivers, function ($driver) { return $driver->SupportsStore(); })); @@ -134,6 +134,6 @@ class Identities extends AbstractProvider $identities[$identity->Id(true)] = $identity; } - return array_values($identities); + return \array_values($identities); } -} \ No newline at end of file +} diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Identities/FileIdentities.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Identities/FileIdentities.php index ce6289439..389586dd6 100755 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Identities/FileIdentities.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Identities/FileIdentities.php @@ -27,18 +27,20 @@ class FileIdentities implements IIdentities */ public function GetIdentities(Account $account): array { - if (!$account) return []; - $data = $this->localStorageProvider->Get($account, Storage\Enumerations\StorageType::CONFIG, 'identities'); - $subIdentities = json_decode($data, true) ?? []; + $subIdentities = \json_decode($data, true) ?? []; $result = []; foreach ($subIdentities as $subIdentity) { $identity = new Identity(); $identity->FromJSON($subIdentity); - if (!$identity->Validate()) continue; - if ($identity->IsAccountIdentities()) $identity->SetEmail($account->Email()); + if (!$identity->Validate()) { + continue; + } + if ($identity->IsAccountIdentities()) { + $identity->SetEmail($account->Email()); + } $result[] = $identity; } @@ -48,12 +50,12 @@ class FileIdentities implements IIdentities /** * @inheritDoc */ - public function SetIdentities(Account $account, array $identities) + public function SetIdentities(Account $account, array $identities): void { - $jsons = array_map(function ($identity) { + $jsons = \array_map(function ($identity) { return $identity->ToSimpleJSON(); }, $identities); - $this->localStorageProvider->Put($account, Storage\Enumerations\StorageType::CONFIG, 'identities', json_encode($jsons)); + $this->localStorageProvider->Put($account, Storage\Enumerations\StorageType::CONFIG, 'identities', \json_encode($jsons)); } /** @@ -68,4 +70,4 @@ class FileIdentities implements IIdentities { return "File"; } -} \ No newline at end of file +} diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Identities/IIdentities.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Identities/IIdentities.php index a25e34854..6e0fc6ab2 100755 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Identities/IIdentities.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Identities/IIdentities.php @@ -20,7 +20,7 @@ interface IIdentities * * @return void */ - public function SetIdentities(Account $account, array $identities); + public function SetIdentities(Account $account, array $identities): void; /** * @return bool @@ -31,4 +31,4 @@ interface IIdentities * @return string */ public function Name(): string; -} \ No newline at end of file +} diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Identities/TestIdentities.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Identities/TestIdentities.php index abb1dbf03..a6cf734ea 100755 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Identities/TestIdentities.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Identities/TestIdentities.php @@ -27,7 +27,7 @@ class TestIdentities implements IIdentities * @return void * @throws Exception */ - public function SetIdentities(Account $account, array $identities) + public function SetIdentities(Account $account, array $identities): void { throw new Exception("Not implemented"); } @@ -44,4 +44,4 @@ class TestIdentities implements IIdentities { return "Test"; } -} \ No newline at end of file +}