return;
}
- $user = XDB::fetchOneAssoc('SELECT r1.uid, r1.broken_level != 0 AS broken, a.hruid, COUNT(r2.uid) AS nb_mails, a.full_name, s.email AS alias
+ $user = XDB::fetchOneAssoc('SELECT r1.uid, r1.broken_level != 0 AS broken, COUNT(r2.uid) AS nb_mails,
+ s.email AS alias, DATE_ADD(r1.last, INTERVAL 14 DAY) < CURDATE() as notify
FROM email_redirect_account AS r1
INNER JOIN accounts AS a ON (a.uid = r1.uid)
INNER JOIN email_source_account AS s ON (a.uid = s.uid AND s.flags = \'bestalias\')
// eventually selects a new bestalias when required.
function fix_bestalias(User $user)
{
- $count = XDB::fetchOneCell('SELECT COUNT(*)
- FROM email_source_account
- WHERE uid = {?} AND FIND_IN_SET(\'bestalias\', flags) AND expire IS NULL',
- $user->id());
+ // First check if the bestalias is properly set.
+ $alias_count = XDB::fetchOneCell('SELECT COUNT(*)
+ FROM email_source_account
+ WHERE uid = {?} AND FIND_IN_SET(\'bestalias\', flags) AND expire IS NULL',
+ $user->id());
- if ($count == 1) {
- return;
- } elseif ($count > 1) {
+ if ($alias_count > 1) {
// If too many bestaliases, delete the bestalias flag from all this
// user's emails (this should never happen).
XDB::execute("UPDATE email_source_account
WHERE uid = {?}",
$user->id());
}
+ if ($alias_count != 1) {
+ // If no bestalias is selected, we choose the shortest email which is not
+ // related to a usage name and contains a '.'.
+ XDB::execute("UPDATE email_source_account
+ SET flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'bestalias')
+ WHERE uid = {?} AND expire IS NULL
+ ORDER BY NOT FIND_IN_SET('usage', flags), email LIKE '%.%', LENGTH(email)
+ LIMIT 1",
+ $user->id());
+ }
+
+ // First check if best_domain is properly set.
+ $domain_count = XDB::fetchOneCell('SELECT COUNT(*)
+ FROM accounts AS a
+ INNER JOIN email_source_account AS s ON (s.uid = a.uid AND FIND_IN_SET(\'bestalias\', s.flags))
+ 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)
+ INNER JOIN email_virtual_domains AS v ON (v.aliasing = m.id AND v.id = s.domain)
+ WHERE a.uid = {?} AND (m.name = {?} OR m.name = {?})',
+ $user->id(), $user->mainEmailDomain(), Platal::globals()->mail->alias_dom);
+
+ if ($domain_count == 0) {
+ XDB::execute('UPDATE accounts AS a
+ INNER JOIN email_source_account AS s ON (s.uid = a.uid AND FIND_IN_SET(\'bestalias\', s.flags))
+ INNER JOIN email_virtual_domains AS d ON (d.aliasing = s.domain AND (d.name = {?} OR d.name = {?}))
+ SET a.best_domain = d.id
+ WHERE a.uid = {?}',
+ $user->mainEmailDomain(), Platal::globals()->mail->alias_dom, $user->id());
+ }
+
- // If no bestalias is selected, we choose the shortest email which is not
- // related to a usage name and contains a '.'.
- XDB::execute("UPDATE email_source_account
- SET flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'bestalias')
- WHERE uid = {?} AND expire IS NULL
- ORDER BY NOT FIND_IN_SET('usage', flags), email LIKE '%.%', LENGTH(email)
- LIMIT 1",
- $user->id());
}
// function valide_email() {{{1
}
$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;
}
private $user;
public $emails;
- public $bogo;
public function __construct(User $user)
{
$this->user = &$user;
- $this->bogo = new Bogo($user);
// Adds third-party email redirections.
$res = XDB::iterator('SELECT redirect, rewrite, type, action, broken_date, broken_level, last, flags, hash, allow_rewrite
}
}
check_redirect($this);
+ $this->update_imap();
return SUCCESS;
}
if (!isvalid_email_redirection($email_stripped)) {
return ERROR_LOOP_EMAIL;
}
+ // We first need to retrieve the value for the antispam filter: it is
+ // either the user's redirections common value, or if they differ, our
+ // default value.
+ $bogo = new Bogo($this->user);
+ $filter = ($bogo->single_state ? Bogo::$states[$bogo->state] : Bogo::$states[0]);
// If the email was already present for this user, we reset it to the default values, we thus use REPLACE INTO.
- XDB::execute('REPLACE INTO email_redirect_account (uid, redirect, flags)
- VALUES ({?}, {?}, \'active\')',
- $this->user->id(), $email);
+ XDB::execute('REPLACE INTO email_redirect_account (uid, redirect, flags, action)
+ VALUES ({?}, {?}, \'active\', {?})',
+ $this->user->id(), $email, $filter);
if ($logger = S::v('log', null)) { // may be absent --> step4.php
S::logger()->log('email_add', $email . ($this->user->id() != S::v('uid') ? " (admin on {$this->user->login()})" : ""));
}
'redirect' => $email,
'rewrite' => '',
'type' => 'smtp',
- 'action' => 'default',
+ 'action' => $filter,
'broken_date' => '0000-00-00',
'broken_level' => 0,
'last' => '0000-00-00',
// 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: