Skip to content

Commit

Permalink
Check login handling for #969
Browse files Browse the repository at this point in the history
  • Loading branch information
the-djmaze committed Feb 16, 2023
1 parent 90d039b commit 99b73d8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
24 changes: 10 additions & 14 deletions snappymail/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -109,23 +102,26 @@ private function StartTLS() : void
*/
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)) {
Expand Down
4 changes: 3 additions & 1 deletion snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public function Connect(ConnectSettings $oSettings) : void

if ($this->IsConnected()) {
$this->writeLogException(new Exceptions\SocketAlreadyConnectedException, \LOG_ERR, false);
$this->Disconnect();
// $this->Disconnect();
return;
}

$this->Settings = $oSettings;
Expand Down Expand Up @@ -202,6 +203,7 @@ public function Disconnect() : void
}
}

// abstract public function Login(ConnectSettings $oSettings) : self;
abstract public function Logout() : void;

public function IsConnected(bool $bThrowExceptionOnFalse = false) : bool
Expand Down
4 changes: 4 additions & 0 deletions snappymail/v/0.0.0/app/libraries/MailSo/Sieve/SieveClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ private function StartTLS() : void
*/
public function Login(Settings $oSettings) : self
{
if ($this->bIsLoggined) {
return $this;
}

$sLogin = $oSettings->Login;
$sPassword = $oSettings->Password;
$sLoginAuthKey = '';
Expand Down
10 changes: 9 additions & 1 deletion snappymail/v/0.0.0/app/libraries/MailSo/Smtp/SmtpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
class SmtpClient extends \MailSo\Net\NetClient
{
private bool $bIsLoggined = false;

private string $sEhlo = '';

private bool $bRcpt = false;
Expand Down Expand Up @@ -103,11 +105,15 @@ private function StartTLS() : void
/**
* @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;

Expand Down Expand Up @@ -183,6 +189,8 @@ public function Login(Settings $oSettings) : self
);
}

$this->bIsLoggined = true;

return $this;
}

Expand Down

0 comments on commit 99b73d8

Please sign in to comment.