Check login handling for #969

This commit is contained in:
the-djmaze 2023-02-16 08:40:28 +01:00
parent 90d039b36b
commit 99b73d87f6
4 changed files with 26 additions and 16 deletions

View file

@ -49,24 +49,17 @@ class ImapClient extends \MailSo\Net\NetClient
private bool $bIsLoggined = false;
private string $sLogginedUser = '';
private bool $UTF8 = false;
public function Hash() : string
{
return \md5('ImapClientHash/'.
$this->GetLogginedUser() . '@' .
$this->Settings->Login . '@' .
$this->GetConnectedHost() . ':' .
$this->GetConnectedPort()
);
}
public function GetLogginedUser() : string
{
return $this->sLogginedUser;
}
/**
* @throws \InvalidArgumentException
* @throws \MailSo\RuntimeException
@ -109,23 +102,26 @@ class ImapClient extends \MailSo\Net\NetClient
*/
public function Login(Settings $oSettings) : self
{
if ($this->bIsLoggined) {
return $this;
}
if (!empty($oSettings->ProxyAuthUser) && !empty($oSettings->ProxyAuthPassword)) {
$sLogin = \MailSo\Base\Utils::IdnToAscii(\MailSo\Base\Utils::Trim($oSettings->ProxyAuthUser));
$sLogin = $oSettings->ProxyAuthUser;
$sPassword = $oSettings->ProxyAuthPassword;
$sProxyAuthUser = $oSettings->Login;
} else {
$sLogin = \MailSo\Base\Utils::IdnToAscii(\MailSo\Base\Utils::Trim($oSettings->Login));
$sLogin = $oSettings->Login;
$sPassword = $oSettings->Password;
$sProxyAuthUser = '';
}
if (!\strlen($sLogin) || !\strlen($sPassword))
{
$sLogin = \MailSo\Base\Utils::IdnToAscii(\MailSo\Base\Utils::Trim($sLogin));
if (!\strlen($sLogin) || !\strlen($sPassword)) {
$this->writeLogException(new \InvalidArgumentException, \LOG_ERR);
}
$this->sLogginedUser = $sLogin;
$type = '';
foreach ($oSettings->SASLMechanisms as $sasl_type) {
if ($this->hasCapability("AUTH={$sasl_type}") && \SnappyMail\SASL::isSupported($sasl_type)) {

View file

@ -93,7 +93,8 @@ abstract class NetClient
if ($this->IsConnected()) {
$this->writeLogException(new Exceptions\SocketAlreadyConnectedException, \LOG_ERR, false);
$this->Disconnect();
// $this->Disconnect();
return;
}
$this->Settings = $oSettings;
@ -202,6 +203,7 @@ abstract class NetClient
}
}
// abstract public function Login(ConnectSettings $oSettings) : self;
abstract public function Logout() : void;
public function IsConnected(bool $bThrowExceptionOnFalse = false) : bool

View file

@ -78,6 +78,10 @@ class SieveClient extends \MailSo\Net\NetClient
*/
public function Login(Settings $oSettings) : self
{
if ($this->bIsLoggined) {
return $this;
}
$sLogin = $oSettings->Login;
$sPassword = $oSettings->Password;
$sLoginAuthKey = '';

View file

@ -19,6 +19,8 @@ use MailSo\Net\Enumerations\ConnectionSecurityType;
*/
class SmtpClient extends \MailSo\Net\NetClient
{
private bool $bIsLoggined = false;
private string $sEhlo = '';
private bool $bRcpt = false;
@ -103,11 +105,15 @@ class SmtpClient extends \MailSo\Net\NetClient
/**
* @throws \InvalidArgumentException
* @throws \MailSo\RuntimeException
* @throws \MailSo\Net\*
* @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Smtp\Exceptions\*
*/
public function Login(Settings $oSettings) : self
{
if ($this->bIsLoggined) {
return $this;
}
$sLogin = \MailSo\Base\Utils::IdnToAscii(\MailSo\Base\Utils::Trim($oSettings->Login));
$sPassword = $oSettings->Password;
@ -183,6 +189,8 @@ class SmtpClient extends \MailSo\Net\NetClient
);
}
$this->bIsLoggined = true;
return $this;
}