From 38c4b4e26e0ed5d86bd01128462f29111988a370 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Wed, 15 Feb 2023 23:04:23 +0100 Subject: [PATCH] Resolve #969 --- .../snappymail/lib/Util/SnappyMailHelper.php | 17 ++++++++++++----- .../app/libraries/MailSo/Net/NetClient.php | 2 +- .../app/libraries/RainLoop/Actions/User.php | 7 ++++++- .../app/libraries/RainLoop/Actions/UserAuth.php | 16 ++++------------ 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php b/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php index de34d71e75..f5ffd278c5 100644 --- a/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php +++ b/integrations/nextcloud/snappymail/lib/Util/SnappyMailHelper.php @@ -73,11 +73,18 @@ public static function startApp(bool $handle = false) : void } */ if ($doLogin && $aCredentials[1] && $aCredentials[2]) { - $oActions->Logger()->AddSecret($aCredentials[2]); - $oAccount = $oActions->LoginProcess($aCredentials[1], $aCredentials[2], false); - if ($oAccount) { - $oActions->Plugins()->RunHook('login.success', array($oAccount)); - $oActions->SetAuthToken($oAccount); + try { + $oActions->Logger()->AddSecret($aCredentials[2]); + $oAccount = $oActions->LoginProcess($aCredentials[1], $aCredentials[2], false); + if ($oAccount) { + $oActions->Plugins()->RunHook('login.success', array($oAccount)); + $oActions->SetAuthToken($oAccount); + } + } catch (\Throwable $e) { + // Login failure, reset password to prevent more attempts + $sUID = \OC::$server->getUserSession()->getUser()->getUID(); + \OC::$server->getSession()['snappymail-password'] = ''; + \OC::$server->getConfig()->setUserValue($sUID, 'snappymail', 'snappymail-password', ''); } } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php b/snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php index 53afe8c8e5..f857a2dd1f 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php @@ -93,7 +93,7 @@ public function Connect(ConnectSettings $oSettings) : void if ($this->IsConnected()) { $this->writeLogException(new Exceptions\SocketAlreadyConnectedException, \LOG_ERR, false); - return; + $this->Disconnect(); } $this->Settings = $oSettings; 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 64f291d8b7..35127a7d70 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 @@ -40,7 +40,12 @@ public function DoLogin() : array $this->Logger()->AddSecret($sPassword); - $oAccount = $this->LoginProcess($sEmail, $sPassword, $bSignMe); + try { + $oAccount = $this->LoginProcess($sEmail, $sPassword, $bSignMe); + } catch (\Throwable $oException) { + $this->loginErrorDelay(); + throw $oException; + } $this->SetAuthToken($oAccount); 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 f1a2b7bde6..7d7282e600 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 @@ -121,7 +121,6 @@ public function LoginProcess(string &$sEmail, string &$sPassword, bool $bSignMe $this->resolveLoginCredentials($sEmail, $sPassword, $sLogin); if (!\str_contains($sEmail, '@') || !\strlen($sPassword)) { - $this->loginErrorDelay(); throw new ClientException(Notifications::InvalidInputArgument); } @@ -135,20 +134,13 @@ public function LoginProcess(string &$sEmail, string &$sPassword, bool $bSignMe } } catch (\Throwable $oException) { $this->LoggerAuthHelper($oAccount, $this->getAdditionalLogParamsByUserLogin($sInputEmail)); - $this->loginErrorDelay(); throw $oException; } - try { - $this->imapConnect($oAccount, true); - if ($bMainAccount) { - $bSignMe && $this->SetSignMeToken($oAccount); - $this->StorageProvider()->Put($oAccount, StorageType::SESSION, Utils::GetSessionToken(), 'true'); - } - } catch (\Throwable $oException) { - $this->loginErrorDelay(); - - throw $oException; + $this->imapConnect($oAccount, true); + if ($bMainAccount) { + $bSignMe && $this->SetSignMeToken($oAccount); + $this->StorageProvider()->Put($oAccount, StorageType::SESSION, Utils::GetSessionToken(), 'true'); } return $oAccount;