Skip to content

Commit

Permalink
email: Check Auth Backend on Save
Browse files Browse the repository at this point in the history
Make sure authentication backend is configured when selection is made, even if
the account is disabled.
  • Loading branch information
protich committed Aug 1, 2022
1 parent 72b2a24 commit 90ed880
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions include/class.email.php
Expand Up @@ -659,13 +659,14 @@ public function getCredentials($auth=null, $refresh=false) {
return [];

if (!isset($this->cred) || $refresh) {
$creds = array();
$cred = null;
$auth = $auth ?: $this->getAuthBk();
list($type, $provider) = explode(':', $auth);
switch ($type) {
case 'mailbox':
if (($mb=$this->email->getMailBoxAccount()))
$cred = $mb->getCredentials(null, $refresh);
if (($mb=$this->email->getMailBoxAccount())
&& $mb->getAuthBk())
$cred = $mb->getCredentials($mb->getAuthBk(), $refresh);
break;
case 'none':
// No authentication required (open replay)
Expand Down Expand Up @@ -736,7 +737,8 @@ public function getCredentials($auth=null, $refresh=false) {
}
break;
default:
throw Exception(__('Unknown Credential Type'));
throw new Exception(sprintf('%s: %s',
$type, __('Unknown Credential Type')));
}
$this->cred = $cred;
}
Expand Down Expand Up @@ -954,12 +956,8 @@ protected function setInfo($vars, &$errors) {
$errors['mailbox_protocol'] = __('Select protocol');
elseif (!in_array($vars['mailbox_protocol'], Email::mailboxProtocols()))
$errors['mailbox_protocol'] = __('Invalid protocol');
// Check to make sure authentication is configured
if (!$vars['mailbox_auth_bk']
|| in_array($vars['mailbox_auth_bk'], ['none', 'mailbox']))
if (!$vars['mailbox_auth_bk'])
$errors['mailbox_auth_bk'] = __('Select Authentication');
elseif (!($creds=$this->getFreshCredentials($vars['mailbox_auth_bk'])))
$errors['mailbox_auth_bk'] = __('Configure Authentication');
if (!$vars['mailbox_fetchfreq'] || !is_numeric($vars['mailbox_fetchfreq']))
$errors['mailbox_fetchfreq'] = __('Fetch interval required');
if (!$vars['mailbox_fetchmax'] || !is_numeric($vars['mailbox_fetchmax']))
Expand All @@ -980,6 +978,11 @@ protected function setInfo($vars, &$errors) {
$errors['mailbox_postfetch'] = __('Archive folder cannot be same as fetched folder (INBOX)');
}

// Make sure authentication is configured if selection is made
if ($vars['mailbox_auth_bk']
&& !($creds=$this->getFreshCredentials($vars['mailbox_auth_bk'])))
$errors['mailbox_auth_bk'] = __('Configure Authentication');

if (!$errors) {
$this->active = $vars['mailbox_active'] ? 1 : 0;
$this->host = $vars['mailbox_host'];
Expand Down Expand Up @@ -1107,12 +1110,16 @@ protected function setInfo($vars, &$errors) {
$_errors['smtp_port'] = __('Port required');
if (!$vars['smtp_auth_bk'])
$_errors['smtp_auth_bk'] = __('Select Authentication');
elseif (!($creds=$this->getFreshCredentials($vars['smtp_auth_bk']))) {
elseif (!($creds=$this->getFreshCredentials($vars['smtp_auth_bk'])))
$_errors['smtp_auth_bk'] = ($vars['smtp_auth_bk'] == 'mailbox')
? __('Configure Mailbox Authentication')
: __('Configure Authentication');
}
}
} elseif ($vars['smtp_auth_bk']
// We default to mailbox - so we're not going to check
// unless account is active, see above!
&& strcasecmp($vars['smtp_auth_bk'], 'mailbox')
&& !($creds=$this->getFreshCredentials($vars['smtp_auth_bk'])))
$_errors['smtp_auth_bk'] = __('Configure Authentication');

if (!$_errors) {
$this->active = $vars['smtp_active'] ? 1 : 0;
Expand Down

0 comments on commit 90ed880

Please sign in to comment.