// eventually selects a new bestalias when required.
function fix_bestalias(User $user)
{
+ // First check if best_domain is properly set.
+ $count = XDB::fetchOneCell('SELECT COUNT(*)
+ FROM accounts AS a
+ INNER JOIN email_virtual_domains AS d ON (d.id = a.best_domain)
+ INNER JOIN email_virtual_domains AS m ON (d.aliasing = m.id)
+ WHERE a.uid = {?} AND m.name = {?}',
+ $user->id(), $user->mainEmailDomain());
+ if ($count == 0) {
+ XDB::execute('UPDATE accounts AS a
+ INNER JOIN email_virtual_domains AS d ON (d.name = {?})
+ SET a.best_domain = d.id
+ WHERE a.uid = {?}',
+ $user->mainEmailDomain(), $user->id());
+ }
+
+ // Then check the alias.
$count = XDB::fetchOneCell('SELECT COUNT(*)
FROM email_source_account
WHERE uid = {?} AND FIND_IN_SET(\'bestalias\', flags) AND expire IS NULL',
}
$res = XDB::fetchOneCell('SELECT COUNT(*)
FROM email_redirect_account
- WHERE uid = {?} AND type = {?} AND flags = \'active\')',
+ WHERE uid = {?} AND type = {?} AND flags = \'active\'',
$user->id(), $storage);
return !is_null($res) && $res > 0;
}
}
}
check_redirect($this);
+ $this->update_imap();
return SUCCESS;
}
// security stuff
check_email($email, "Ajout d'une adresse surveillée aux redirections de " . $this->user->login());
check_redirect($this);
+ $this->update_imap();
return SUCCESS;
}
$email->set_rewrite($emails_rewrite[$email->email]);
}
check_redirect($this);
+ $this->update_imap();
return SUCCESS;
}
$this->emails[$thisone]->deactivate();
}
check_redirect($this);
+ $this->update_imap();
if ($allinactive && !$activate) {
return ERROR_INACTIVE_REDIRECTION;
}
if ($mail->email == $email) {
$mail->set_rewrite($redirect);
check_redirect($this);
+ $this->update_imap();
return;
}
}
foreach ($this->emails as &$mail) {
if ($mail->email == $email) {
check_redirect($this);
+ $this->update_imap();
return $mail->clean_errors();
}
}
}
}
check_redirect($this);
+ $this->update_imap();
}
public function enable()
}
check_redirect($this);
}
+ $this->update_imap();
}
public function get_broken_mx()
{
return $this->user->id();
}
+
+ private function update_imap()
+ {
+ // Imaps must bounce if and only if the user has no active redirection.
+ if (!$this->other_active('')) {
+ XDB::execute('UPDATE email_redirect_account
+ SET action = \'imap_and_bounce\'
+ WHERE type = \'imap\' AND uid = {?}',
+ $this->user->id());
+ } else {
+ XDB::execute('UPDATE email_redirect_account
+ SET action = \'let_spams\'
+ WHERE type = \'imap\' AND uid = {?}',
+ $this->user->id());
+ }
+ }
}
// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: