From 3c8532b21af22d687b33b3946a6935bc9bae3626 Mon Sep 17 00:00:00 2001 From: RainLoop Team Date: Thu, 2 Jan 2014 17:12:28 +0400 Subject: [PATCH] Set SMTP AUTH LOGIN as default --- .../app/libraries/MailSo/Smtp/SmtpClient.php | 84 +++++++++++-------- 1 file changed, 50 insertions(+), 34 deletions(-) diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Smtp/SmtpClient.php b/rainloop/v/0.0.0/app/libraries/MailSo/Smtp/SmtpClient.php index 94ca0a9e9..016ff752f 100644 --- a/rainloop/v/0.0.0/app/libraries/MailSo/Smtp/SmtpClient.php +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Smtp/SmtpClient.php @@ -28,11 +28,6 @@ class SmtpClient extends \MailSo\Net\NetClient */ private $bData; - /** - * @var bool - */ - private $bIsStartTSLSupported; - /** * @var array */ @@ -58,6 +53,11 @@ class SmtpClient extends \MailSo\Net\NetClient */ private $aResults; + /** + * @var bool + */ + public $__USE_SINGLE_LINE_AUTH_PLAIN_COMMAND = false; + /** * @access protected */ @@ -65,7 +65,6 @@ class SmtpClient extends \MailSo\Net\NetClient { parent::__construct(); - $this->bIsStartTSLSupported = false; $this->aAuthTypes = array(); $this->iRequestTime = 0; @@ -174,33 +173,7 @@ class SmtpClient extends \MailSo\Net\NetClient */ public function Login($sLogin, $sPassword) { - if ($this->IsAuthSupported('PLAIN')) - { - try - { - $this->sendRequestWithCheck('AUTH', 334, 'PLAIN'); - } - catch (\MailSo\Smtp\Exceptions\NegativeResponseException $oException) - { - $this->writeLogException( - new \MailSo\Smtp\Exceptions\LoginBadMethodException( - $oException->GetResponses(), '', 0, $oException), - \MailSo\Log\Enumerations\Type::NOTICE, true); - } - - try - { - $this->sendRequestWithCheck(base64_encode("\0".$sLogin."\0".$sPassword), 235, '', true); - } - catch (\MailSo\Smtp\Exceptions\NegativeResponseException $oException) - { - $this->writeLogException( - new \MailSo\Smtp\Exceptions\LoginBadCredentialsException( - $oException->GetResponses(), '', 0, $oException), - \MailSo\Log\Enumerations\Type::NOTICE, true); - } - } - else if ($this->IsAuthSupported('LOGIN')) + if ($this->IsAuthSupported('LOGIN')) { try { @@ -227,6 +200,49 @@ class SmtpClient extends \MailSo\Net\NetClient \MailSo\Log\Enumerations\Type::NOTICE, true); } } + else if ($this->IsAuthSupported('PLAIN')) + { + if ($this->__USE_SINGLE_LINE_AUTH_PLAIN_COMMAND) + { + try + { + $this->sendRequestWithCheck('AUTH', 235, 'PLAIN '.\base64_encode("\0".$sLogin."\0".$sPassword), true); + } + catch (\MailSo\Smtp\Exceptions\NegativeResponseException $oException) + { + $this->writeLogException( + new \MailSo\Smtp\Exceptions\LoginBadCredentialsException( + $oException->GetResponses(), '', 0, $oException), + \MailSo\Log\Enumerations\Type::NOTICE, true); + } + } + else + { + try + { + $this->sendRequestWithCheck('AUTH', 334, 'PLAIN'); + } + catch (\MailSo\Smtp\Exceptions\NegativeResponseException $oException) + { + $this->writeLogException( + new \MailSo\Smtp\Exceptions\LoginBadMethodException( + $oException->GetResponses(), '', 0, $oException), + \MailSo\Log\Enumerations\Type::NOTICE, true); + } + + try + { + $this->sendRequestWithCheck(\base64_encode("\0".$sLogin."\0".$sPassword), 235, '', true); + } + catch (\MailSo\Smtp\Exceptions\NegativeResponseException $oException) + { + $this->writeLogException( + new \MailSo\Smtp\Exceptions\LoginBadCredentialsException( + $oException->GetResponses(), '', 0, $oException), + \MailSo\Log\Enumerations\Type::NOTICE, true); + } + } + } else { $this->writeLogException( @@ -502,7 +518,7 @@ class SmtpClient extends \MailSo\Net\NetClient $this->IsSupported('STARTTLS'), $this->iSecurityType, $this->HasSupportedAuth())) { $this->sendRequestWithCheck('STARTTLS', 220); - if (!@stream_socket_enable_crypto($this->rConnect, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) + if (!@\stream_socket_enable_crypto($this->rConnect, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { $this->writeLogException( new \MailSo\Smtp\Exceptions\RuntimeException('Cannot enable STARTTLS'),