New solution for #423 due to #774

This commit is contained in:
the-djmaze 2022-12-14 16:39:03 +01:00
parent 439ad5596f
commit 21d7e91493
6 changed files with 22 additions and 29 deletions

View file

@ -119,13 +119,17 @@ class ImapClient extends \MailSo\Net\NetClient
$this->sLogginedUser = $sLogin;
$type = $this->IsSupported('LOGINDISABLED') ? '' : 'LOGIN'; // RFC3501 6.2.3
$type = '';
foreach ($oSettings->SASLMechanisms as $sasl_type) {
if ($this->IsSupported("AUTH={$sasl_type}") && \SnappyMail\SASL::isSupported($sasl_type)) {
$type = $sasl_type;
break;
}
}
// RFC3501 6.2.3
if ('LOGIN' === $type && $this->IsSupported('LOGINDISABLED')) {
$type = '';
}
if (!$type) {
if (!$this->Encrypted() && $this->IsSupported('STARTTLS')) {
$this->StartTLS();

View file

@ -35,7 +35,16 @@ class ConnectSettings implements \JsonSerializable
// Authentication settings use by all child classes
public bool $useAuth = true;
public bool $shortLogin = false;
public array $SASLMechanisms = [];
public array $SASLMechanisms = [
// https://github.com/the-djmaze/snappymail/issues/182
'SCRAM-SHA3-512',
'SCRAM-SHA-512',
'SCRAM-SHA-256',
'SCRAM-SHA-1',
// 'CRAM-MD5',
'PLAIN',
'LOGIN'
];
public string $Login = '';
public string $Password = '';
public string $ProxyAuthUser = '';
@ -62,6 +71,9 @@ class ConnectSettings implements \JsonSerializable
}
$object->shortLogin = !empty($aSettings['shortLogin']);
$object->ssl = SSLContext::fromArray($aSettings['ssl'] ?? []);
if (isset($aSettings['sasl'])) {
$object->SASLMechanisms = $aSettings['sasl'];
}
return $object;
}
@ -75,6 +87,7 @@ class ConnectSettings implements \JsonSerializable
'type' => $this->type,
'timeout' => $this->timeout,
'shortLogin' => $this->shortLogin,
'sasl' => $this->SASLMechanisms,
'ssl' => $this->ssl
);
}

View file

@ -113,14 +113,12 @@ class SieveClient extends \MailSo\Net\NetClient
}
$type = '';
\array_push($oSettings->SASLMechanisms, 'PLAIN', 'LOGIN');
foreach ($oSettings->SASLMechanisms as $sasl_type) {
if ($this->IsAuthSupported($sasl_type) && \SnappyMail\SASL::isSupported($sasl_type)) {
$type = $sasl_type;
break;
}
}
if (!$type) {
if (!$this->Encrypted() && $this->IsSupported('STARTTLS')) {
$this->StartTLS();

View file

@ -143,14 +143,12 @@ class SmtpClient extends \MailSo\Net\NetClient
$sPassword = $oSettings->Password;
$type = '';
$oSettings->SASLMechanisms[] = 'LOGIN';
foreach ($oSettings->SASLMechanisms as $sasl_type) {
if ($this->IsAuthSupported($sasl_type) && \SnappyMail\SASL::isSupported($sasl_type)) {
$type = $sasl_type;
break;
}
}
if (!$type) {
if (!$this->Encrypted() && $this->IsSupported('STARTTLS')) {
$this->StartTLS();

View file

@ -382,9 +382,6 @@ Enables caching in the system'),
'smtp_show_server_errors' => array(false),
'sieve_auth_plain_initial' => array(true),
'sieve_allow_fileinto_inbox' => array(false),
'sasl_allow_plain' => array(true),
'sasl_allow_scram_sha' => array(false),
'sasl_allow_cram_md5' => array(false),
'mail_func_clear_headers' => array(true),
'mail_func_additional_parameters' => array(false),
'folders_spec_limit' => array(50),

View file

@ -200,34 +200,17 @@ class Domain implements \JsonSerializable
public function ImapSettings() : \MailSo\Imap\Settings
{
return static::mergeGlobalSettings($this->IMAP);
return $this->IMAP;
}
public function SmtpSettings() : \MailSo\Smtp\Settings
{
return static::mergeGlobalSettings($this->SMTP);
return $this->SMTP;
}
public function SieveSettings() : \MailSo\Sieve\Settings
{
return static::mergeGlobalSettings($this->Sieve);
}
private static function mergeGlobalSettings(\MailSo\Net\ConnectSettings $oSettings) : \MailSo\Net\ConnectSettings
{
$oConfig = \RainLoop\API::Config();
if ($oConfig->Get('labs', 'sasl_allow_scram_sha', false)) {
// https://github.com/the-djmaze/snappymail/issues/182
\array_push($oSettings->SASLMechanisms, 'SCRAM-SHA3-512', 'SCRAM-SHA-512', 'SCRAM-SHA-256', 'SCRAM-SHA-1');
}
if ($oConfig->Get('labs', 'sasl_allow_cram_md5', false)) {
$oSettings->SASLMechanisms[] = 'CRAM-MD5';
}
if ($oConfig->Get('labs', 'sasl_allow_plain', true)) {
$oSettings->SASLMechanisms[] = 'PLAIN';
}
return $oSettings;
return $this->Sieve;
}
/**