diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php b/rainloop/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php index 7bc489296..19aa9a51e 100644 --- a/rainloop/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php @@ -186,8 +186,8 @@ class ImapClient extends \MailSo\Net\NetClient * @param string $sLogin * @param string $sPassword * @param string $sProxyAuthUser = '' - * @param bool $bUseAuthPlainIfSupported = false - * @param bool $bUseAuthCramMd5IfSupported = false + * @param bool $bUseAuthPlainIfSupported = true + * @param bool $bUseAuthCramMd5IfSupported = true * * @return \MailSo\Imap\ImapClient * @@ -196,7 +196,7 @@ class ImapClient extends \MailSo\Net\NetClient * @throws \MailSo\Imap\Exceptions\Exception */ public function Login($sLogin, $sPassword, $sProxyAuthUser = '', - $bUseAuthPlainIfSupported = false, $bUseAuthCramMd5IfSupported = false) + $bUseAuthPlainIfSupported = true, $bUseAuthCramMd5IfSupported = true) { if (!\MailSo\Base\Validator::NotEmptyString($sLogin, true) || !\MailSo\Base\Validator::NotEmptyString($sPassword, true)) @@ -233,10 +233,10 @@ class ImapClient extends \MailSo\Net\NetClient if ($oContinuationResponse && !empty($oContinuationResponse->ResponseList[1])) { - $sTiken = @\base64_decode($oContinuationResponse->ResponseList[1]); - $this->oLogger->Write('tiket: '.$sTiken); + $sTicket = @\base64_decode($oContinuationResponse->ResponseList[1]); + $this->oLogger->Write('ticket: '.$sTicket); - $sToken = \base64_encode($sLogin.' '.\MailSo\Base\Utils::Hmac($sPassword, $sTiken)); + $sToken = \base64_encode($sLogin.' '.\MailSo\Base\Utils::Hmac($sTicket, $sPassword)); if ($this->oLogger) { diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php b/rainloop/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php index a1143c56b..125da70fe 100644 --- a/rainloop/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php @@ -77,8 +77,8 @@ class MailClient * @param string $sLogin * @param string $sPassword * @param string $sProxyAuthUser = '' - * @param bool $bUseAuthPlainIfSupported = false - * @param bool $bUseAuthCramMd5IfSupported = false + * @param bool $bUseAuthPlainIfSupported = true + * @param bool $bUseAuthCramMd5IfSupported = true * * @return \MailSo\Mail\MailClient * @@ -87,7 +87,7 @@ class MailClient * @throws \MailSo\Imap\Exceptions\LoginException */ public function Login($sLogin, $sPassword, $sProxyAuthUser = '', - $bUseAuthPlainIfSupported = false, $bUseAuthCramMd5IfSupported = false) + $bUseAuthPlainIfSupported = true, $bUseAuthCramMd5IfSupported = true) { $this->oImapClient->Login($sLogin, $sPassword, $sProxyAuthUser, $bUseAuthPlainIfSupported, $bUseAuthCramMd5IfSupported); return $this; 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 cb1334304..fb071ffdb 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 @@ -177,6 +177,8 @@ class SmtpClient extends \MailSo\Net\NetClient /** * @param string $sLogin * @param string $sPassword + * @param boolean $bUseAuthPlainIfSupported = true + * @param boolean $bUseAuthCramMd5IfSupported = true * * @return \MailSo\Smtp\SmtpClient * @@ -184,15 +186,15 @@ class SmtpClient extends \MailSo\Net\NetClient * @throws \MailSo\Net\Exceptions\Exception * @throws \MailSo\Smtp\Exceptions\Exception */ - public function Login($sLogin, $sPassword) + public function Login($sLogin, $sPassword, $bUseAuthPlainIfSupported = true, $bUseAuthCramMd5IfSupported = true) { $sLogin = \MailSo\Base\Utils::IdnToAscii(\MailSo\Base\Utils::Trim($sLogin)); - if ($this->IsAuthSupported('LOGIN')) + if ($bUseAuthCramMd5IfSupported && $this->IsAuthSupported('CRAM-MD5')) { try { - $this->sendRequestWithCheck('AUTH', 334, 'LOGIN'); + $this->sendRequestWithCheck('AUTH', 334, 'CRAM-MD5'); } catch (\MailSo\Smtp\Exceptions\NegativeResponseException $oException) { @@ -202,10 +204,26 @@ class SmtpClient extends \MailSo\Net\NetClient \MailSo\Log\Enumerations\Type::NOTICE, true); } + $sTicket = ''; + + $sContinuationResponse = !empty($this->aResults[0]) ? \trim($this->aResults[0]) : ''; + if ($sContinuationResponse && '334 ' === \substr($sContinuationResponse, 0, 4) && 0 < \strlen(\substr($sContinuationResponse, 4))) + { + $sTicket = @\base64_decode(\substr($sContinuationResponse, 4)); + $this->writeLogWithCrlf('ticket: '.$sTicket); + } + + if (empty($sTicket)) + { + $this->writeLogException( + new \MailSo\Smtp\Exceptions\NegativeResponseException(), + \MailSo\Log\Enumerations\Type::NOTICE, true + ); + } + try { - $this->sendRequestWithCheck(\base64_encode($sLogin), 334, ''); - $this->sendRequestWithCheck(\base64_encode($sPassword), 235, '', true); + $this->sendRequestWithCheck(\base64_encode($sLogin.' '.\MailSo\Base\Utils::Hmac($sTicket, $sPassword)), 235, '', true); } catch (\MailSo\Smtp\Exceptions\NegativeResponseException $oException) { @@ -215,7 +233,7 @@ class SmtpClient extends \MailSo\Net\NetClient \MailSo\Log\Enumerations\Type::NOTICE, true); } } - else if ($this->IsAuthSupported('PLAIN')) + else if ($bUseAuthPlainIfSupported && $this->IsAuthSupported('PLAIN')) { if ($this->__USE_SINGLE_LINE_AUTH_PLAIN_COMMAND) { @@ -258,6 +276,33 @@ class SmtpClient extends \MailSo\Net\NetClient } } } + else if ($this->IsAuthSupported('LOGIN')) + { + try + { + $this->sendRequestWithCheck('AUTH', 334, 'LOGIN'); + } + catch (\MailSo\Smtp\Exceptions\NegativeResponseException $oException) + { + $this->writeLogException( + new \MailSo\Smtp\Exceptions\LoginBadMethodException( + $oException->GetResponses(), $oException->getMessage(), 0, $oException), + \MailSo\Log\Enumerations\Type::NOTICE, true); + } + + try + { + $this->sendRequestWithCheck(\base64_encode($sLogin), 334, ''); + $this->sendRequestWithCheck(\base64_encode($sPassword), 235, '', true); + } + catch (\MailSo\Smtp\Exceptions\NegativeResponseException $oException) + { + $this->writeLogException( + new \MailSo\Smtp\Exceptions\LoginBadCredentialsException( + $oException->GetResponses(), $oException->getMessage(), 0, $oException), + \MailSo\Log\Enumerations\Type::NOTICE, true); + } + } else { $this->writeLogException( diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Config/Application.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Config/Application.php index 36915d018..84533d06c 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Config/Application.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Config/Application.php @@ -396,8 +396,6 @@ Enables caching in the system'), 'use_imap_list_subscribe' => array(true), 'use_imap_thread' => array(true), 'use_imap_move' => array(false), - 'use_imap_auth_plain' => array(false), - 'use_imap_auth_cram_md5' => array(false), 'use_imap_expunge_all_on_delete' => array(false), 'imap_forwarded_flag' => array('$Forwarded'), 'imap_read_receipt_flag' => array('$ReadReceipt'), @@ -410,7 +408,11 @@ Enables caching in the system'), 'imap_large_thread_limit' => array(50), 'imap_folder_list_limit' => array(200), 'imap_show_login_alert' => array(true), + 'imap_use_auth_plain' => array(true), + 'imap_use_auth_cram_md5' => array(true), 'smtp_show_server_errors' => array(false), + 'smtp_use_auth_plain' => array(true), + 'smtp_use_auth_cram_md5' => array(true), 'sieve_allow_raw_script' => array(false), 'sieve_utf8_folder_name' => array(true), 'imap_timeout' => array(300), diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Model/Account.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Model/Account.php index 48d939309..7c30a4724 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Model/Account.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Model/Account.php @@ -409,8 +409,8 @@ class Account extends \RainLoop\Account // for backward compatibility 'ProxyAuthPassword' => $this->ProxyAuthPassword(), 'VerifySsl' => !!$oConfig->Get('ssl', 'verify_certificate', false), 'AllowSelfSigned' => !!$oConfig->Get('ssl', 'allow_self_signed', true), - 'UseAuthPlainIfSupported' => !!$oConfig->Get('labs', 'use_imap_auth_plain'), - 'UseAuthCramMd5IfSupported' => !!$oConfig->Get('labs', 'use_imap_auth_cram_md5') + 'UseAuthPlainIfSupported' => !!$oConfig->Get('labs', 'imap_use_auth_plain', true), + 'UseAuthCramMd5IfSupported' => !!$oConfig->Get('labs', 'imap_use_auth_cram_md5', true) ); $oPlugins->RunHook('filter.imap-credentials', array($this, &$aImapCredentials)); @@ -485,7 +485,9 @@ class Account extends \RainLoop\Account // for backward compatibility 'ProxyAuthUser' => $this->ProxyAuthUser(), 'ProxyAuthPassword' => $this->ProxyAuthPassword(), 'VerifySsl' => !!$oConfig->Get('ssl', 'verify_certificate', false), - 'AllowSelfSigned' => !!$oConfig->Get('ssl', 'allow_self_signed', true) + 'AllowSelfSigned' => !!$oConfig->Get('ssl', 'allow_self_signed', true), + 'UseAuthPlainIfSupported' => !!$oConfig->Get('labs', 'smtp_use_auth_plain', true), + 'UseAuthCramMd5IfSupported' => !!$oConfig->Get('labs', 'smtp_use_auth_cram_md5', true) ); $oPlugins->RunHook('filter.smtp-credentials', array($this, &$aSmtpCredentials)); @@ -515,7 +517,8 @@ class Account extends \RainLoop\Account // for backward compatibility } else { - $oSmtpClient->Login($aSmtpCredentials['Login'], $aSmtpCredentials['Password']); + $oSmtpClient->Login($aSmtpCredentials['Login'], $aSmtpCredentials['Password'], + $aSmtpCredentials['UseAuthPlainIfSupported'], $aSmtpCredentials['UseAuthCramMd5IfSupported']); } $bLogin = true;