mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 10:09:20 +03:00
Add CRAM-MD5 support (#1016)
This commit is contained in:
parent
c0ab236440
commit
4f2a8b5b9b
5 changed files with 71 additions and 21 deletions
|
|
@ -186,8 +186,8 @@ class ImapClient extends \MailSo\Net\NetClient
|
||||||
* @param string $sLogin
|
* @param string $sLogin
|
||||||
* @param string $sPassword
|
* @param string $sPassword
|
||||||
* @param string $sProxyAuthUser = ''
|
* @param string $sProxyAuthUser = ''
|
||||||
* @param bool $bUseAuthPlainIfSupported = false
|
* @param bool $bUseAuthPlainIfSupported = true
|
||||||
* @param bool $bUseAuthCramMd5IfSupported = false
|
* @param bool $bUseAuthCramMd5IfSupported = true
|
||||||
*
|
*
|
||||||
* @return \MailSo\Imap\ImapClient
|
* @return \MailSo\Imap\ImapClient
|
||||||
*
|
*
|
||||||
|
|
@ -196,7 +196,7 @@ class ImapClient extends \MailSo\Net\NetClient
|
||||||
* @throws \MailSo\Imap\Exceptions\Exception
|
* @throws \MailSo\Imap\Exceptions\Exception
|
||||||
*/
|
*/
|
||||||
public function Login($sLogin, $sPassword, $sProxyAuthUser = '',
|
public function Login($sLogin, $sPassword, $sProxyAuthUser = '',
|
||||||
$bUseAuthPlainIfSupported = false, $bUseAuthCramMd5IfSupported = false)
|
$bUseAuthPlainIfSupported = true, $bUseAuthCramMd5IfSupported = true)
|
||||||
{
|
{
|
||||||
if (!\MailSo\Base\Validator::NotEmptyString($sLogin, true) ||
|
if (!\MailSo\Base\Validator::NotEmptyString($sLogin, true) ||
|
||||||
!\MailSo\Base\Validator::NotEmptyString($sPassword, true))
|
!\MailSo\Base\Validator::NotEmptyString($sPassword, true))
|
||||||
|
|
@ -233,10 +233,10 @@ class ImapClient extends \MailSo\Net\NetClient
|
||||||
|
|
||||||
if ($oContinuationResponse && !empty($oContinuationResponse->ResponseList[1]))
|
if ($oContinuationResponse && !empty($oContinuationResponse->ResponseList[1]))
|
||||||
{
|
{
|
||||||
$sTiken = @\base64_decode($oContinuationResponse->ResponseList[1]);
|
$sTicket = @\base64_decode($oContinuationResponse->ResponseList[1]);
|
||||||
$this->oLogger->Write('tiket: '.$sTiken);
|
$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)
|
if ($this->oLogger)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -77,8 +77,8 @@ class MailClient
|
||||||
* @param string $sLogin
|
* @param string $sLogin
|
||||||
* @param string $sPassword
|
* @param string $sPassword
|
||||||
* @param string $sProxyAuthUser = ''
|
* @param string $sProxyAuthUser = ''
|
||||||
* @param bool $bUseAuthPlainIfSupported = false
|
* @param bool $bUseAuthPlainIfSupported = true
|
||||||
* @param bool $bUseAuthCramMd5IfSupported = false
|
* @param bool $bUseAuthCramMd5IfSupported = true
|
||||||
*
|
*
|
||||||
* @return \MailSo\Mail\MailClient
|
* @return \MailSo\Mail\MailClient
|
||||||
*
|
*
|
||||||
|
|
@ -87,7 +87,7 @@ class MailClient
|
||||||
* @throws \MailSo\Imap\Exceptions\LoginException
|
* @throws \MailSo\Imap\Exceptions\LoginException
|
||||||
*/
|
*/
|
||||||
public function Login($sLogin, $sPassword, $sProxyAuthUser = '',
|
public function Login($sLogin, $sPassword, $sProxyAuthUser = '',
|
||||||
$bUseAuthPlainIfSupported = false, $bUseAuthCramMd5IfSupported = false)
|
$bUseAuthPlainIfSupported = true, $bUseAuthCramMd5IfSupported = true)
|
||||||
{
|
{
|
||||||
$this->oImapClient->Login($sLogin, $sPassword, $sProxyAuthUser, $bUseAuthPlainIfSupported, $bUseAuthCramMd5IfSupported);
|
$this->oImapClient->Login($sLogin, $sPassword, $sProxyAuthUser, $bUseAuthPlainIfSupported, $bUseAuthCramMd5IfSupported);
|
||||||
return $this;
|
return $this;
|
||||||
|
|
|
||||||
|
|
@ -177,6 +177,8 @@ class SmtpClient extends \MailSo\Net\NetClient
|
||||||
/**
|
/**
|
||||||
* @param string $sLogin
|
* @param string $sLogin
|
||||||
* @param string $sPassword
|
* @param string $sPassword
|
||||||
|
* @param boolean $bUseAuthPlainIfSupported = true
|
||||||
|
* @param boolean $bUseAuthCramMd5IfSupported = true
|
||||||
*
|
*
|
||||||
* @return \MailSo\Smtp\SmtpClient
|
* @return \MailSo\Smtp\SmtpClient
|
||||||
*
|
*
|
||||||
|
|
@ -184,15 +186,15 @@ class SmtpClient extends \MailSo\Net\NetClient
|
||||||
* @throws \MailSo\Net\Exceptions\Exception
|
* @throws \MailSo\Net\Exceptions\Exception
|
||||||
* @throws \MailSo\Smtp\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));
|
$sLogin = \MailSo\Base\Utils::IdnToAscii(\MailSo\Base\Utils::Trim($sLogin));
|
||||||
|
|
||||||
if ($this->IsAuthSupported('LOGIN'))
|
if ($bUseAuthCramMd5IfSupported && $this->IsAuthSupported('CRAM-MD5'))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$this->sendRequestWithCheck('AUTH', 334, 'LOGIN');
|
$this->sendRequestWithCheck('AUTH', 334, 'CRAM-MD5');
|
||||||
}
|
}
|
||||||
catch (\MailSo\Smtp\Exceptions\NegativeResponseException $oException)
|
catch (\MailSo\Smtp\Exceptions\NegativeResponseException $oException)
|
||||||
{
|
{
|
||||||
|
|
@ -202,10 +204,26 @@ class SmtpClient extends \MailSo\Net\NetClient
|
||||||
\MailSo\Log\Enumerations\Type::NOTICE, true);
|
\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
|
try
|
||||||
{
|
{
|
||||||
$this->sendRequestWithCheck(\base64_encode($sLogin), 334, '');
|
$this->sendRequestWithCheck(\base64_encode($sLogin.' '.\MailSo\Base\Utils::Hmac($sTicket, $sPassword)), 235, '', true);
|
||||||
$this->sendRequestWithCheck(\base64_encode($sPassword), 235, '', true);
|
|
||||||
}
|
}
|
||||||
catch (\MailSo\Smtp\Exceptions\NegativeResponseException $oException)
|
catch (\MailSo\Smtp\Exceptions\NegativeResponseException $oException)
|
||||||
{
|
{
|
||||||
|
|
@ -215,7 +233,7 @@ class SmtpClient extends \MailSo\Net\NetClient
|
||||||
\MailSo\Log\Enumerations\Type::NOTICE, true);
|
\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)
|
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
|
else
|
||||||
{
|
{
|
||||||
$this->writeLogException(
|
$this->writeLogException(
|
||||||
|
|
|
||||||
|
|
@ -396,8 +396,6 @@ Enables caching in the system'),
|
||||||
'use_imap_list_subscribe' => array(true),
|
'use_imap_list_subscribe' => array(true),
|
||||||
'use_imap_thread' => array(true),
|
'use_imap_thread' => array(true),
|
||||||
'use_imap_move' => array(false),
|
'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),
|
'use_imap_expunge_all_on_delete' => array(false),
|
||||||
'imap_forwarded_flag' => array('$Forwarded'),
|
'imap_forwarded_flag' => array('$Forwarded'),
|
||||||
'imap_read_receipt_flag' => array('$ReadReceipt'),
|
'imap_read_receipt_flag' => array('$ReadReceipt'),
|
||||||
|
|
@ -410,7 +408,11 @@ Enables caching in the system'),
|
||||||
'imap_large_thread_limit' => array(50),
|
'imap_large_thread_limit' => array(50),
|
||||||
'imap_folder_list_limit' => array(200),
|
'imap_folder_list_limit' => array(200),
|
||||||
'imap_show_login_alert' => array(true),
|
'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_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_allow_raw_script' => array(false),
|
||||||
'sieve_utf8_folder_name' => array(true),
|
'sieve_utf8_folder_name' => array(true),
|
||||||
'imap_timeout' => array(300),
|
'imap_timeout' => array(300),
|
||||||
|
|
|
||||||
|
|
@ -409,8 +409,8 @@ class Account extends \RainLoop\Account // for backward compatibility
|
||||||
'ProxyAuthPassword' => $this->ProxyAuthPassword(),
|
'ProxyAuthPassword' => $this->ProxyAuthPassword(),
|
||||||
'VerifySsl' => !!$oConfig->Get('ssl', 'verify_certificate', false),
|
'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', 'use_imap_auth_plain'),
|
'UseAuthPlainIfSupported' => !!$oConfig->Get('labs', 'imap_use_auth_plain', true),
|
||||||
'UseAuthCramMd5IfSupported' => !!$oConfig->Get('labs', 'use_imap_auth_cram_md5')
|
'UseAuthCramMd5IfSupported' => !!$oConfig->Get('labs', 'imap_use_auth_cram_md5', true)
|
||||||
);
|
);
|
||||||
|
|
||||||
$oPlugins->RunHook('filter.imap-credentials', array($this, &$aImapCredentials));
|
$oPlugins->RunHook('filter.imap-credentials', array($this, &$aImapCredentials));
|
||||||
|
|
@ -485,7 +485,9 @@ class Account extends \RainLoop\Account // for backward compatibility
|
||||||
'ProxyAuthUser' => $this->ProxyAuthUser(),
|
'ProxyAuthUser' => $this->ProxyAuthUser(),
|
||||||
'ProxyAuthPassword' => $this->ProxyAuthPassword(),
|
'ProxyAuthPassword' => $this->ProxyAuthPassword(),
|
||||||
'VerifySsl' => !!$oConfig->Get('ssl', 'verify_certificate', false),
|
'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));
|
$oPlugins->RunHook('filter.smtp-credentials', array($this, &$aSmtpCredentials));
|
||||||
|
|
@ -515,7 +517,8 @@ class Account extends \RainLoop\Account // for backward compatibility
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$oSmtpClient->Login($aSmtpCredentials['Login'], $aSmtpCredentials['Password']);
|
$oSmtpClient->Login($aSmtpCredentials['Login'], $aSmtpCredentials['Password'],
|
||||||
|
$aSmtpCredentials['UseAuthPlainIfSupported'], $aSmtpCredentials['UseAuthCramMd5IfSupported']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$bLogin = true;
|
$bLogin = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue