From b45037625befabbc6a25ab0487321d8b77f62fa4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Fri, 21 Jan 2011 17:40:04 +0100 Subject: [PATCH] Adapts email related user defined parameters to the new mail chain. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This mainly consists in getting the page "My emails" to work with the new mail chain. No changes are made here to the User class, but all storage email (imap, googleapps) code is been ported here. Signed-off-by: Stéphane Jacob --- include/emails.combobox.inc.php | 53 +--- include/emails.inc.php | 515 +++++++++++++------------------ include/googleapps.inc.php | 10 +- include/reminder/email_backup.inc.php | 10 +- include/security.inc.php | 9 +- include/validations/aliases.inc.php | 48 +-- modules/email.php | 228 +++++++------- modules/googleapps.php | 45 +-- modules/register.php | 3 +- templates/emails/alias.tpl | 22 +- templates/emails/antispam.tpl | 10 +- templates/emails/index.tpl | 21 +- templates/emails/redirect.tpl | 49 ++- templates/include/emails.combobox.tpl | 15 +- templates/include/form.valid.aliases.tpl | 4 +- 15 files changed, 444 insertions(+), 598 deletions(-) diff --git a/include/emails.combobox.inc.php b/include/emails.combobox.inc.php index 969d22a..3965ea9 100644 --- a/include/emails.combobox.inc.php +++ b/include/emails.combobox.inc.php @@ -21,8 +21,6 @@ function fill_email_combobox(PlPage $page, $user = null, $profile = null) { - global $globals; - if (is_null($user)) { $user = S::user(); } @@ -30,24 +28,15 @@ function fill_email_combobox(PlPage $page, $user = null, $profile = null) /* Always refetch the profile. */ $profile = $user->profile(true); } - $email_type = "directory"; + $email_type = 'directory'; if ($profile) { $email_directory = $profile->email_directory; - if ($email_directory) { - $page->assign('email_directory', $email_directory); - list($alias, $domain) = explode('@', $email_directory); - } else { - $page->assign('email_directory', ''); - $email_type = NULL; - $alias = $domain = ''; - } + $page->assign('email_directory', $email_directory); - $res = XDB::query( - "SELECT email - FROM profile_job - WHERE pid = {?}", $profile->id()); - $res = $res->fetchAllAssoc(); + $res = XDB::fetchAllAssoc('SELECT email + FROM profile_job + WHERE pid = {?}', $profile->id()); $pro = array(); foreach ($res as $res_it) { if ($res_it['email'] != '') { @@ -61,26 +50,16 @@ function fill_email_combobox(PlPage $page, $user = null, $profile = null) } if ($user) { - $melix = $user->emailAlias(); - if ($melix) { - list($melix) = explode('@', $melix); - $page->assign('melix', $melix); - if (($domain == $globals->mail->alias_dom) || ($domain == $globals->mail->alias_dom2)) { - $email_type = "melix"; - } - } - - $res = XDB::query( - "SELECT alias - FROM aliases - WHERE uid={?} AND (type='a_vie' OR type='alias')", $user->id()); - $res = $res->fetchAllAssoc(); + $res = XDB::fetchAllAssoc('SELECT CONCAT(s.email, \'@\', d.name) + FROM email_source_account AS s + INNER JOIN email_virtual_domains AS m ON (s.domain = m.id) + INNER JOIN email_virtual_domains AS d ON (d.aliasing = m.id) + WHERE s.uid = {?} + ORDER BY s.email, d.name', $user->id()); $page->assign('list_email_X', $res); - if (($domain == $globals->mail->domain) || ($domain == $globals->mail->domain2)) { - foreach ($res as $res_it) { - if ($alias == $res_it['alias']) { - $email_type = "X"; - } + foreach ($res as $res_it) { + if ($email_directory == $res_it) { + $email_type = 'X'; } } @@ -88,10 +67,10 @@ function fill_email_combobox(PlPage $page, $user = null, $profile = null) $redirect = new Redirect($user); $redir = array(); foreach ($redirect->emails as $redirect_it) { - if ($redirect_it instanceof EmailRedirection) { + if ($redirect_it->is_redirection()) { $redir[] = $redirect_it->email; if ($email_directory == $redirect_it->email) { - $email_type = "redir"; + $email_type = 'redir'; } } } diff --git a/include/emails.inc.php b/include/emails.inc.php index a68f1f0..6e079f0 100644 --- a/include/emails.inc.php +++ b/include/emails.inc.php @@ -19,29 +19,40 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -define("SUCCESS", 1); -define("ERROR_INACTIVE_REDIRECTION", 2); -define("ERROR_INVALID_EMAIL", 3); -define("ERROR_LOOP_EMAIL", 4); +define('SUCCESS', 1); +define('ERROR_INACTIVE_REDIRECTION', 2); +define('ERROR_INVALID_EMAIL', 3); +define('ERROR_LOOP_EMAIL', 4); // function fix_bestalias() {{{1 // Checks for an existing 'bestalias' among the the current user's aliases, and // eventually selects a new bestalias when required. function fix_bestalias(User $user) { - $res = XDB::query("SELECT COUNT(*) - FROM aliases - WHERE uid = {?} AND FIND_IN_SET('bestalias', flags) AND type != 'homonyme'", - $user->id()); - if ($res->fetchOneCell()) { - return; - } + $count = XDB::fetchOneCell('SELECT COUNT(*) + FROM email_source_account + WHERE uid = {?} AND FIND_IN_SET(\'bestalias\', flags)', + $user->id()); - XDB::execute("UPDATE aliases - SET flags=CONCAT(flags,',','bestalias') - WHERE uid={?} AND type!='homonyme' - ORDER BY !FIND_IN_SET('usage',flags),alias LIKE '%.%', LENGTH(alias) - LIMIT 1", $user->id()); + if ($count == 1) { + return; + } elseif ($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 + SET flags = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', flags, ','), ',bestalias,', ',')) + WHERE uid = {?}", + $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 = {?} + ORDER BY NOT FIND_IN_SET('usage', flags), email LIKE '%.%', LENGTH(email) + LIMIT 1", + $user->id()); } // function valide_email() {{{1 @@ -67,8 +78,8 @@ function valide_email($str) } // function isvalid_email_redirection() {{{1 -/** vérifie si une adresse email convient comme adresse de redirection - * @param $email l'adresse email a verifier +/** Checks if an email is a suitable redirection. + * @param $email the email to check * @return BOOL */ function isvalid_email_redirection($email) @@ -78,17 +89,18 @@ function isvalid_email_redirection($email) } // function ids_from_mails() {{{1 -// Converts an array of emails to an array of email => uid +// Converts an array of emails to an array of email => uid, where email is the +// given email when we found a matching user. function ids_from_mails(array $emails) { global $globals; - $domain_mails = array(); - $alias_mails = array(); - $other_mails = array(); - // Determine the type of the email adresses. It can eiher be a domain - // email (@polytechnique.org), an alias email (@melix.net) or any other - // email (potentially used as a redirection by one user) + // Removes duplicates, if any. + $emails = array_unique($emails); + + // Formats and splits by domain type (locally managed or external) emails. + $domain_emails = array(); + $other_emails = array(); foreach ($emails as $email) { if (strpos($email, '@') === false) { $user = $email; @@ -96,72 +108,37 @@ function ids_from_mails(array $emails) } else { list($user, $domain) = explode('@', $email); } - if ($domain == $globals->mail->alias_dom || $domain == $globals->mail->alias_dom2) { + if ($domain == $globals->mail->alias_dom || $domain == $globals->mail->alias_dom2 + || $domain == $globals->mail->domain || $domain == $globals->mail->domain2) { list($user) = explode('+', $user); list($user) = explode('_', $user); - $alias_mails[$email] = $user . "@" . $globals->mail->alias_dom; - } elseif ($domain == $globals->mail->domain || $domain == $globals->mail->domain2) { - list($user) = explode('+', $user); - list($user) = explode('_', $user); - $domain_mails[$email] = $user; + $domain_emails[$email] = strtolower($user . '@' . $domain); } else { - $other_mails[] = $email; + $other_emails[$email] = strtolower($user . '@' . $domain); } } - $uids = array(); - // Look up user ids for addresses in domain - $alias_uids = array(); - if (count($domain_mails)) { - $res = XDB::query("SELECT alias, uid - FROM aliases - WHERE alias IN {?}", array_unique($domain_mails)); - foreach ($res->fetchAllRow() as $row) { - list ($alias, $id) = $row; - $domain_uids[$alias] = $id; - } - } - // Connect emails with uids - foreach ($domain_mails as $email => $user) { - // Some 'domain' emails might be invalid. - if (array_key_exists($user, $domain_uids)) { - $uids[$email] = $domain_uids[$user]; - } - } + // Retrieves emails from our domains. + $domain_uids = XDB::fetchAllAssoc('email', + 'SELECT email, uid + FROM email_source_account + WHERE email IN {?}', + array_unique($domain_emails)); - // Look up user ids for addresses in our alias domain - $alias_uids = array(); - if (count($alias_mails)) { - $res = XDB::query("SELECT v.alias, a.uid - FROM virtual AS v - INNER JOIN virtual_redirect AS r USING(vid) - INNER JOIN aliases AS a ON (a.type = 'a_vie' - AND r.redirect = CONCAT(a.alias, '@{$globals->mail->domain2}')) - WHERE v.alias IN {?}", array_unique($alias_mails)); - foreach ($res->fetchAllRow() as $row) { - list ($alias, $id) = $row; - $alias_uids[$alias] = $id; - } - } - // Connect emails with uids - foreach ($alias_mails as $email => $user) { - if (array_key_exists($user, $alias_uids)) { - $uids[$email] = $alias_uids[$user]; - } - } + // Retrieves emails from redirections. + $other_uids = XDB::fetchAllAssoc('redirect', + 'SELECT redirect, uid + FROM email_redirect_account + WHERE redirect IN {?}', + array_unique($other_emails)); - // Look up user ids for other addresses in the email redirection list - if (count($other_mails)) { - $lowerupper = array(); - foreach ($other_mails as $mail) { - $lowerupper[strtolower($mail)] = $mail; - } - $res = XDB::query("SELECT email, uid - FROM emails - WHERE email IN {?}", $other_mails); - foreach ($res->fetchAllRow() as $row) { - list ($email, $uid) = $row; - $uids[$lowerupper[strtolower($email)]] = $uid; + // Associates given emails with the corresponding uid. + $uids = array(); + foreach (array_merge($domain_emails, $other_emails) as $email => $canonical_email) { + if (array_key_exists($canonical_email, $domain_uids)) { + $uids[$email] = $domain_uids[$canonical_email]; + } elseif (array_key_exists($canonical_email, $other_uids)) { + $uids[$email] = $other_uids[$canonical_email]; } } @@ -172,13 +149,10 @@ function ids_from_mails(array $emails) // The Bogo class represents a spam filtering level in plat/al architecture. class Bogo { - // properties {{{2 + private static $states = array('let_spams', 'tag_spams', 'tag_and_drop_spams', 'drop_spams'); private $user; private $state; - private $_states = Array('let_spams', 'tag_spams', 'tag_and_drop_spams', 'drop_spams'); - - // constructor {{{2 public function __construct(User $user) { @@ -187,52 +161,63 @@ class Bogo } $this->user = &$user; - $res = XDB::query('SELECT email FROM emails WHERE uid = {?} AND flags = "filter"', $user->id()); - if ($res->numRows()) { - $this->state = $res->fetchOneCell(); - } else { - $this->state = 'tag_and_drop_spams'; - $res = XDB::query( - "INSERT INTO emails (uid, email, rewrite, panne, flags) - VALUES ({?}, 'tag_and_drop_spams', '', '0000-00-00', 'filter')", - $user->id()); + $res = XDB::query('SELECT action + FROM email_redirect_account + WHERE uid = {?} AND (type = \'smtp\' OR type = \'googleapps\')', + $user->id()); + if ($res->numRows() == 0) { + return; } + $this->state = $res->fetchOneCell(); } - // public function change() {{{2 - public function change($state) { - $this->state = is_int($state) ? $this->_states[$state] : $state; - XDB::execute('UPDATE emails SET email = {?} WHERE uid = {?} AND flags = "filter"', + $this->state = is_int($state) ? self::$states[$state] : $state; + XDB::execute('UPDATE email_redirect_account + SET action = {?} + WHERE uid = {?} AND (type = \'smtp\' OR type = \'googleapps\')', $this->state, $this->user->id()); } - // pubic function level() {{{2 - public function level() { - return array_search($this->state, $this->_states); + return array_search($this->state, self::$states); } } // class Email {{{1 // Represents an "email address" used as final recipient for plat/al-managed -// addresses; it can be subclasses a Redirection emails (third-party) or as -// Storage emails (Polytechnique.org). -abstract class Email +// addresses. +class Email { - protected $user; + // Lists fields to load automatically. + static private $field_names = array('rewrite', 'type', 'action', 'broken_date', 'broken_level', 'last', 'hash', 'allow_rewrite'); + + // Shortname to realname mapping for known mail storage backends. + static private $display_names = array( + 'imap' => 'Accès de secours aux emails (IMAP)', + 'googleapps' => 'Compte Google Apps', + ); + static private $storage_domains = array( + 'imap' => 'imap', + 'googleapps' => 'g' + ); + + private $user; // Basic email properties; $sufficient indicates if the email can be used as - // an unique redirection; $email contains the delivery email address. + // an unique redirection; $redirect contains the delivery email address. public $type; public $sufficient; public $email; public $display_email; + public $domain; + public $action; // Redirection status properties. public $active; + public $inactive; public $broken; public $disabled; public $rewrite; @@ -240,96 +225,82 @@ abstract class Email public $hash; // Redirection bounces stats. - public $panne; public $last; - public $panne_level; + public $broken_level; + public $broken_date; - // Activates the email address as a redirection. - public abstract function activate(); - - // Deactivates the email address as a redirection. - public abstract function deactivate(); - - // Sets the rewrite rule for the given address. - public abstract function set_rewrite($rewrite); - - // Resets the error counts associated with the redirection. - public abstract function clean_errors(); - - // Email backend capabilities ('rewrite' refers to From: rewrite for mails - // forwarded by Polytechnique.org's MXs; 'removable' indicates if the email - // can be definitively removed; 'disable' indicates if the email has a third - // status 'disabled' in addition to 'active' and 'inactive'). - public abstract function has_rewrite(); - public abstract function is_removable(); - public abstract function has_disable(); -} - -// class EmailRedirection {{{1 -// Implementation of Email for third-party redirection (redirection of emails to -// external user-supplied addresses). -class EmailRedirection extends Email -{ - // constructor {{{2 - - public function __construct(User $user, $row) + public function __construct(User $user, array $row) { - $this->user = &$user; - $this->sufficient = true; + foreach (self::$field_names as $field) { + if (array_key_exists($field, $row)) { + $this->$field = $row[$field]; + } + } + $this->email = $row['redirect']; - list($this->email, $flags, $this->rewrite, $this->allow_rewrite, $this->hash, $this->panne, $this->last, $this->panne_level) = $row; - $this->display_email = $this->email; - $this->active = ($flags == 'active'); - $this->broken = ($flags == 'panne'); - $this->disabled = ($flags == 'disable'); + if (array_key_exists($this->type, Email::$display_names)) { + $this->display_email = self::$display_names[$this->type]; + } else { + $this->display_email = $this->email; + } + foreach (array('active', 'inactive', 'broken', 'disabled') as $status) { + $this->$status = ($status == $row['flags']); + } + $this->sufficient = ($this->type == 'smtp' || $this->type == 'googleapps'); + $this->user = &$user; } - // public function activate() {{{2 - + // Activates the email address as a redirection. public function activate() { - if (!$this->active) { - XDB::execute("UPDATE emails - SET panne_level = IF(flags = 'panne', panne_level - 1, panne_level), - flags = 'active' - WHERE uid = {?} AND email = {?}", $this->user->id(), $this->email); - S::logger()->log("email_on", $this->email . ($this->user->id() != S::v('uid') ? "(admin on {$this->user->login()})" : "")); - $this->active = true; - $this->broken = false; + if ($this->inactive) { + XDB::execute('UPDATE email_redirect_account + SET broken_level = IF(flags = \'broken\', broken_level - 1, broken_level), flags = \'active\' + WHERE uid = {?} AND redirect = {?}', + $this->user->id(), $this->email); + S::logger()->log('email_on', $this->email . ($this->user->id() != S::v('uid') ? "(admin on {$this->user->login()})" : '')); + $this->inactive = false; + $this->active = true; } } - // public function deactivate() {{{2 - + // Deactivates the email address as a redirection. public function deactivate() { if ($this->active) { - XDB::execute("UPDATE emails SET flags ='' - WHERE uid = {?} AND email = {?}", $this->user->id(), $this->email); - S::logger()->log("email_off", $this->email . ($this->user->id() != S::v('uid') ? "(admin on {$this->user->login()})" : "") ); - $this->active = false; + XDB::execute('UPDATE email_redirect_account + SET flags = \'inactive\' + WHERE uid = {?} AND redirect = {?}', + $this->user->id(), $this->email); + S::logger()->log('email_off', $this->email . ($this->user->id() != S::v('uid') ? "(admin on {$this->user->login()})" : "") ); + $this->inactive = true; + $this->active = false; } } - // public function set_rewrite() {{{2 + // Sets the rewrite rule for the given address. public function set_rewrite($rewrite) { - if ($this->rewrite == $rewrite) { + if ($this->type != 'smtp' || $this->rewrite == $rewrite) { return; } if (!$rewrite || !isvalid_email($rewrite)) { $rewrite = ''; } - XDB::execute('UPDATE emails SET rewrite = {?} WHERE uid = {?} AND email = {?}', $rewrite, $this->user->id(), $this->email); + XDB::execute('UPDATE email_redirect_account + SET rewrite = {?} + WHERE uid = {?} AND redirect = {?} AND type = \'smtp\'', + $rewrite, $this->user->id(), $this->email); $this->rewrite = $rewrite; if (!$this->allow_rewrite) { global $globals; if (empty($this->hash)) { $this->hash = rand_url_id(); - XDB::execute("UPDATE emails - SET hash = {?} - WHERE uid = {?} AND email = {?}", $this->hash, $this->user->id(), $this->email); + XDB::execute('UPDATE email_redirect_account + SET hash = {?} + WHERE uid = {?} AND redirect = {?} AND type = \'smtp\'', + $this->hash, $this->user->id(), $this->email); } $mail = new PlMailer('emails/rewrite-in.mail.tpl'); $mail->assign('mail', $this); @@ -339,76 +310,54 @@ class EmailRedirection extends Email $mail->assign('to', $this->email); $mail->send($this->user->isEmailFormatHtml()); } - return; } - // public function clean_errors() {{{2 + // Resets the error counts associated with the redirection. public function clean_errors() { + if ($this->type != 'smtp') { + return; + } if (!S::admin()) { return false; } - $this->panne = 0; - $this->panne_level = 0; - $this->last = 0; - return XDB::execute("UPDATE emails - SET panne_level = 0, panne = 0, last = 0 - WHERE uid = {?} AND email = {?}", + $this->broken = 0; + $this->broken_level = 0; + $this->last = 0; + return XDB::execute('UPDATE email_redirect_account + SET broken_level = 0, broken_date = 0, last = 0 + WHERE uid = {?} AND redirect = {?} AND type = \'smtp\'', $this->user->id(), $this->email); } - // public function has_rewrite() {{{2 + // Email backend capabilities ('rewrite' refers to From: rewrite for mails + // forwarded by Polytechnique.org's MXs; 'removable' indicates if the email + // can be definitively removed; 'disable' indicates if the email has a third + // status 'disabled' in addition to 'active' and 'inactive'). public function has_rewrite() { - return true; + return ($this->type == 'smtp'); } - // public function is_removable() {{{2 - public function is_removable() { - return true; + return ($this->type == 'smtp'); } - // public function has_disable() {{{2 - public function has_disable() { return true; } -} - -// class EmailStorage {{{1 -// Implementation of Email for email storage backends from Polytechnique.org. -class EmailStorage extends Email -{ - // Shortname to realname mapping for known mail storage backends. - private $display_names = array( - 'imap' => 'Accès de secours aux emails (IMAP)', - 'googleapps' => 'Compte Google Apps', - ); - - // Retrieves the current list of actives storages. - private function get_storages() - { - return new PlFlagSet(XDB::fetchOneCell('SELECT storage - FROM email_options - WHERE uid = {?}', - $this->user->id())); - } - // Updates the list of active storages. - private function set_storages($storages) + public function is_redirection() { - XDB::execute("UPDATE email_options - SET storage = {?} - WHERE uid = {?}", $storages, $this->user->id()); + return ($this->type == 'smtp'); } // Returns the list of allowed storages for the @p user. - static public function get_allowed_storages(User $user) + static private function get_allowed_storages(User $user) { global $globals; $storages = array(); @@ -429,93 +378,68 @@ class EmailStorage extends Email return $storages; } - - public function __construct(User $user, $name) + static public function activate_storage(User $user, $storage) { - $this->user = &$user; - $this->email = $name; - $this->display_email = (isset($this->display_names[$name]) ? $this->display_names[$name] : $name); + Platal::assert(in_array($storage, self::get_allowed_storages($user))); - $storages = $this->get_storages(); - $this->sufficient = ($name == 'googleapps'); - $this->active = $storages->hasFlag($name); - $this->broken = false; - $this->disabled = false; - $this->rewrite = ''; - $this->panne = $this->last = $this->panne_level = 0; + if (!self::is_active_storage($user, $storage)) { + global $globals; + + XDB::execute('INSERT INTO email_redirect_account (uid, type, redirect, flags) + VALUES ({?}, {?}, {?}, \'active\')', + $user->id(), $storage, + $user->hruid . '@' . self::$storage_domains[$storage] . '.' . $globals->mail->domain); + } } - public function activate() + static public function deactivate_storage(User $user, $storage) { - if (!$this->active) { - $storages = $this->get_storages(); - $storages->addFlag($this->email); - $this->set_storages($storages); - $this->active = true; - } + if (in_array($storage, self::$storage_domains)) { + XDB::execute('DELETE FROM email_redirect_account + WHERE uid = {?} AND type = {?}', + $user->id(), $storage); + } } - public function deactivate() + static public function is_active_storage(User $user, $storage) { - if ($this->active) { - $storages = $this->get_storages(); - $storages->rmFlag($this->email); - $this->set_storages($storages); - $this->active = false; + if (!in_array($storage, self::$storage_domains)) { + return false; } - + $res = XDB::fetchOneCell('SELECT COUNT(*) + FROM email_redirect_account + WHERE uid = {?} AND type = {?} AND flags = \'active\')', + $user->id(), $storage); + return !is_null($res) && $res > 0; } - - // Source rewrite can't be enabled for email storage addresses. - public function set_rewrite($rewrite) {} - - // Email storage are not supposed to be broken, hence not supposed to be - // cleaned-up. - public function clean_errors() {} - - // Capabilities. - public function has_rewrite() { return false; } - public function is_removable() { return false; } - public function has_disable() { return false; } } - // class Redirect {{{1 // Redirect is a placeholder class for an user's active redirections (third-party // redirection email, or Polytechnique.org mail storages). class Redirect { - // properties {{{2 - - private $flag_active = 'active'; + private $flags = 'active'; private $user; public $emails; public $bogo; - // constructor {{{2 - public function __construct(User $user) { $this->user = &$user; $this->bogo = new Bogo($user); // Adds third-party email redirections. - $res = XDB::iterRow("SELECT email, flags, rewrite, allow_rewrite, hash, panne, last, panne_level - FROM emails - WHERE uid = {?} AND flags != 'filter'", $user->id()); - $this->emails = Array(); + $res = XDB::iterator('SELECT redirect, rewrite, type, action, broken_date, broken_level, last, flags, hash, allow_rewrite + FROM email_redirect_account + WHERE uid = {?} AND type != \'homonym\'', + $user->id()); + $this->emails = array(); while ($row = $res->next()) { - $this->emails[] = new EmailRedirection($user, $row); - } - - // Adds local email storage backends. - foreach (EmailStorage::get_allowed_storages($user) as $storage) { - $this->emails[] = new EmailStorage($user, $storage); + $this->emails[] = new Email($user, $row); } } - // public function other_active() {{{2 - public function other_active($email) { foreach ($this->emails as $mail) { @@ -526,14 +450,14 @@ class Redirect return false; } - // public function delete_email() {{{2 - public function delete_email($email) { if (!$this->other_active($email)) { return ERROR_INACTIVE_REDIRECTION; } - XDB::execute('DELETE FROM emails WHERE uid = {?} AND email = {?}', $this->user->id(), $email); + XDB::execute('DELETE FROM email_redirect_account + WHERE uid = {?} AND redirect = {?} AND type != \'homonym\'', + $this->user->id(), $email); S::logger()->log('email_del', $email . ($this->user->id() != S::v('uid') ? " (admin on {$this->user->login()})" : "")); foreach ($this->emails as $i => $mail) { if ($email == $mail->email) { @@ -544,8 +468,6 @@ class Redirect return SUCCESS; } - // public function add_email() {{{2 - public function add_email($email) { $email_stripped = strtolower(trim($email)); @@ -556,7 +478,7 @@ class Redirect return ERROR_LOOP_EMAIL; } // 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 emails (uid, email, flags) + XDB::execute('REPLACE INTO email_redirect_account (uid, redirect, flags) VALUES ({?}, {?}, \'active\')', $this->user->id(), $email); if ($logger = S::v('log', null)) { // may be absent --> step4.php @@ -567,7 +489,18 @@ class Redirect return SUCCESS; } } - $this->emails[] = new EmailRedirection($this->user, array($email, 'active', '', 0, null, '0000-00-00', '0000-00-00', 0)); + $this->emails[] = new Email($this->user, array( + 'redirect' => $email, + 'rewrite' => '', + 'type' => 'smtp', + 'action' => 'default', + 'broken_date' => '0000-00-00', + 'broken_level' => 0, + 'last' => '0000-00-00', + 'flags' => 'active', + 'hash' => null, + 'allow_rewrite' => 0 + )); // security stuff check_email($email, "Ajout d'une adresse surveillée aux redirections de " . $this->user->login()); @@ -575,23 +508,20 @@ class Redirect return SUCCESS; } - // public function modify_email() {{{2 - public function modify_email($emails_actifs, $emails_rewrite) { - foreach ($this->emails as &$mail) { - if (in_array($mail->email, $emails_actifs)) { - $mail->activate(); + foreach ($this->emails as &$email) { + if (in_array($email->email, $emails_actifs)) { + $email->activate(); } else { - $mail->deactivate(); + $email->deactivate(); } - $mail->set_rewrite($emails_rewrite[$mail->email]); + $email->set_rewrite($emails_rewrite[$email->email]); } check_redirect($this); + return SUCCESS; } - // public function modify_one_email() {{{2 - public function modify_one_email($email, $activate) { $allinactive = true; @@ -613,13 +543,10 @@ class Redirect check_redirect($this); if ($allinactive && !$activate) { return ERROR_INACTIVE_REDIRECTION; - } else { - return SUCCESS; } + return SUCCESS; } - // public function modify_one_email_redirect() {{{2 - public function modify_one_email_redirect($email, $redirect) { foreach ($this->emails as &$mail) { @@ -631,8 +558,6 @@ class Redirect } } - // function clean_errors() {{{2 - public function clean_errors($email) { foreach ($this->emails as &$mail) { @@ -644,11 +569,9 @@ class Redirect return false; } - // function disable() {{{2 - public function disable() { - XDB::execute("UPDATE emails + XDB::execute("UPDATE email_redirect_account SET flags = 'disable' WHERE flags = 'active' AND uid = {?}", $this->user->id()); foreach ($this->emails as &$mail) { @@ -660,24 +583,20 @@ class Redirect check_redirect($this); } - // function enable() {{{2 - public function enable() { - XDB::execute("UPDATE emails + XDB::execute("UPDATE email_redirect_account SET flags = 'active' WHERE flags = 'disable' AND uid = {?}", $this->user->id()); foreach ($this->emails as &$mail) { if ($mail->disabled) { - $mail->active = true; $mail->disabled = false; + $mail->active = true; } check_redirect($this); } } - // function get_broken_mx() {{{2 - public function get_broken_mx() { $res = XDB::query("SELECT host, text @@ -713,8 +632,6 @@ class Redirect return $mails; } - // function active_emails() {{{2 - public function active_emails() { $emails = array(); @@ -726,8 +643,6 @@ class Redirect return $emails; } - // function get_uid() {{{2 - public function get_uid() { return $this->user->id(); diff --git a/include/googleapps.inc.php b/include/googleapps.inc.php index a1ae96f..68bf04d 100644 --- a/include/googleapps.inc.php +++ b/include/googleapps.inc.php @@ -34,9 +34,8 @@ function post_queue_u_create($job) { // the user at creation time. $account = new GoogleAppsAccount($user); if ($account->activate_mail_redirection) { - require_once('emails.inc.php'); - $storage = new EmailStorage($user, 'googleapps'); - $storage->activate(); + require_once 'emails.inc.php'; + Email::activate_storage($user, 'googleapps'); } // Sends the 'account created' email to the user, with basic documentation. @@ -63,13 +62,12 @@ function post_queue_u_update($job) { } if (isset($parameters['suspended']) && $parameters['suspended'] == false) { - require_once('emails.inc.php'); + require_once 'emails.inc.php'; $account = new GoogleAppsAccount($user); if ($account->active()) { // Re-adds the email redirection (if the user did request it). if ($account->activate_mail_redirection) { - $storage = new EmailStorage($user, 'googleapps'); - $storage->activate(); + Email::activate_storage($user, 'googleapps'); } // Sends an email to the account owner. diff --git a/include/reminder/email_backup.inc.php b/include/reminder/email_backup.inc.php index 45984c4..9bd599b 100644 --- a/include/reminder/email_backup.inc.php +++ b/include/reminder/email_backup.inc.php @@ -25,9 +25,7 @@ class ReminderEmailBackup extends Reminder { if ($action == 'yes') { require_once 'emails.inc.php'; - $storage = new EmailStorage($this->user, 'imap'); - $storage->activate(); - + Email::activate_storage($this->user, 'imap'); $this->UpdateOnYes(); } @@ -62,11 +60,11 @@ class ReminderEmailBackup extends Reminder } require_once 'emails.inc.php'; - $storage = new EmailStorage($user, 'imap'); - if ($storage->active) { + $active = Email::is_active_storage($user, 'imap') + if ($active) { Reminder::MarkCandidateAsAccepted($user->id(), $candidate); } - return !$storage->active; + return !$active; } } diff --git a/include/security.inc.php b/include/security.inc.php index cb3cba5..d978e5d 100644 --- a/include/security.inc.php +++ b/include/security.inc.php @@ -66,10 +66,11 @@ function check_ip($level) function check_email($email, $message) { - $res = XDB::query("SELECT state, description - FROM email_watch - WHERE state != 'safe' AND email = {?}", $email); - if ($res->numRows()) { + $res = XDB::fetchOneCell('SELECT COUNT(*) + FROM email_watch + WHERE state != \'safe\' AND email = {?}', + $email); + if ($res) { send_warning_mail($message); return true; } diff --git a/include/validations/aliases.inc.php b/include/validations/aliases.inc.php index e47e001..2cf9509 100644 --- a/include/validations/aliases.inc.php +++ b/include/validations/aliases.inc.php @@ -24,10 +24,10 @@ class AliasReq extends Validate { // properties {{{2 public $alias; - public $raison; + public $reason; public $unique = true; - public $old = ''; + public $old; public $public = 'private'; public $rules = "Interdire ce qui peut nous servir (virus@, postmaster@…), @@ -35,17 +35,14 @@ class AliasReq extends Validate Pas de contrainte pour les tirets ou les points, en revanche le souligné (_) est interdit."; // constructor {{{2 - public function __construct(User $_user, $_alias, $_raison, $_public, $_stamp=0) + public function __construct(User $_user, $_alias, $_reason, $_public, $_old, $_stamp = 0) { global $globals; parent::__construct($_user, true, 'alias', $_stamp); - $this->alias = $_alias.'@'.$globals->mail->alias_dom; - $this->raison = $_raison; + $this->alias = $_alias; + $this->reason = $_reason; $this->public = $_public; - $this->old = $_user->emailAlias(); - if (empty($this->old)) { - unset($this->old); - } + $this->old = $_old; } // function get_request() {{{2 @@ -63,23 +60,27 @@ class AliasReq extends Validate // function _mail_subj {{{2 protected function _mail_subj() { - return "[Polytechnique.org/MELIX] Demande de l'alias {$this->alias}"; + global $globals; + return "[Polytechnique.org/MELIX] Demande de l'alias {$this->alias}@{$globals->mail->alias_dom}"; } // function _mail_body {{{2 protected function _mail_body($isok) { + global $globals; if ($isok) { - return " L'adresse email {$this->alias} que tu avais demandée vient d'être créée, tu peux désormais l'utiliser à ta convenance." + return " L'adresse email {$this->alias}@{$globals->mail->alias_dom} que tu avais demandée vient d'être créée, tu peux désormais l'utiliser à ta convenance." . ($this->public == 'public' ? ' À ta demande, cette adresse apparaît maintenant sur ta fiche.' : ''); } else { - return " La demande que tu avais faite pour l'alias {$this->alias} a été refusée."; + return " La demande que tu avais faite pour l'alias {$this->alias}@{$globals->mail->alias_dom} a été refusée."; } } // function commit() {{{2 public function commit() { + global $globals; + if ($this->user->hasProfile()) { XDB::execute('UPDATE profiles SET alias_pub = {?} @@ -88,19 +89,20 @@ class AliasReq extends Validate } if ($this->old) { - return XDB::execute('UPDATE virtual - SET alias = {?} - WHERE alias = {?}', - $this->alias, $this->old); + $success = XDB::execute('UPDATE email_source_account AS s + INNER JOIN email_virtual_domains AS d ON (s.domain = d.id) + SET s.email = {?} + WHERE s.uid = {?} AND d.name = {?}', + $this->alias, $this->user->id(), $globals->mail->alias_dom); } else { - XDB::execute('INSERT INTO virtual - SET alias = {?}, type=\'user\'', - $this->alias); - $vid = XDB::insertId(); - return XDB::execute('INSERT INTO virtual_redirect (vid, redirect) - VALUES ({?}, {?})', - $vid, $this->user->forlifeEmail()); + $success = XDB::execute('INSERT INTO email_source_account (email, uid, domain, type, flags) + SELECT {?}, {?}, id, \'alias\', \'\' + FROM email_virtual_domains + WHERE name = {?}', + $this->alias, $this->user->id(), $globals->mail->alias_dom); } + + return $success; } } diff --git a/modules/email.php b/modules/email.php index 8b4bcf3..b0bb942 100644 --- a/modules/email.php +++ b/modules/email.php @@ -61,12 +61,16 @@ class EmailModule extends PLModule return PL_FORBIDDEN; } - XDB::execute("UPDATE aliases + // First delete the bestalias flag from all this user's emails. + XDB::execute("UPDATE email_source_account SET flags = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', flags, ','), ',bestalias,', ',')) WHERE uid = {?}", $user->id()); - XDB::execute("UPDATE aliases - SET flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'bestalias') - WHERE uid = {?} AND alias = {?}", $user->id(), $email); + // Then gives the bestalias flag to the given email. + list($email, $domain) = explode('@', $email); + XDB::execute("UPDATE email_source_account AS s + INNER JOIN email_virtual_domains AS d ON (s.domain = d.id) + SET s.flags = CONCAT_WS(',', IF(s.flags = '', NULL, s.flags), 'bestalias') + WHERE s.uid = {?} AND s.email = {?} AND d.name = {?}", $user->id(), $email, $domain); // As having a non-null bestalias value is critical in // plat/al's code, we do an a posteriori check on the @@ -75,13 +79,24 @@ class EmailModule extends PLModule } // Fetch and display aliases. - $sql = "SELECT alias, (type='a_vie') AS a_vie, - (alias REGEXP '\\\\.[0-9]{2}$') AS cent_ans, - FIND_IN_SET('bestalias',flags) AS best, expire - FROM aliases - WHERE uid = {?} AND type!='homonyme' - ORDER BY LENGTH(alias)"; - $page->assign('aliases', XDB::iterator($sql, $user->id())); + $aliases = XDB::iterator("SELECT CONCAT(s.email, '@', d.name) AS email, (s.type = 'forlife') AS forlife, + (s.email REGEXP '\\\\.[0-9]{2}$') AS hundred_year, + FIND_IN_SET('bestalias', s.flags) AS bestalias, s.expire, + (d.name = {?}) AS alias + FROM email_source_account AS s + INNER JOIN email_virtual_domains AS d ON (s.domain = d.id) + WHERE s.uid = {?} + ORDER BY !alias, s.email", + $globals->mail->alias_dom, $user->id()); + $page->assign('aliases', $aliases); + + $alias = XDB::fetchOneCell('SELECT COUNT(s.email) + FROM email_source_account AS s + INNER JOIN email_virtual_domains AS d ON (s.domain = d.id) + WHERE s.uid = {?} AND d.name = {?}', + $user->id(), $globals->mail->alias_dom); + $page->assign('alias', $alias); + // Check for homonyms. $page->assign('homonyme', $user->homonyme); @@ -89,19 +104,6 @@ class EmailModule extends PLModule // Display active redirections. $redirect = new Redirect($user); $page->assign('mails', $redirect->active_emails()); - - // Display, when available, the @alias_dom email alias. - $res = XDB::query( - "SELECT alias - FROM virtual AS v - INNER JOIN virtual_redirect AS vr USING(vid) - WHERE (redirect={?} OR redirect={?}) - AND alias LIKE '%@{$globals->mail->alias_dom}'", - $user->forlifeEmail(), - // TODO: remove this über-ugly hack. The issue is that you need - // to remove all @m4x.org addresses in virtual_redirect first. - $user->login() . '@' . $globals->mail->domain2); - $page->assign('melix', $res->fetchOneCell()); } function handler_alias($page, $action = null, $value = null) @@ -112,76 +114,79 @@ class EmailModule extends PLModule $page->setTitle('Alias melix.net'); $user = S::user(); - $page->assign('demande', AliasReq::get_request($user->id())); + $page->assign('request', AliasReq::get_request($user->id())); // Remove the email alias. - if ($action == 'delete' && $value) { + if ($action == 'delete') { S::assert_xsrf_token(); - XDB::execute( - "DELETE virtual, virtual_redirect - FROM virtual - INNER JOIN virtual_redirect USING (vid) - WHERE alias = {?} AND (redirect = {?} OR redirect = {?})", - $value, $user->forlifeEmail(), $user->m4xForlifeEmail()); + XDB::execute('DELETE s + FROM email_source_account AS s + INNER JOIN email_virtual_domains AS d ON (s.domain = d.id) + WHERE s.uid = {?} AND d.name = {?}', + $user->id(), $globals->mail->alias_dom); + + require_once 'emails.inc.php'; + fix_bestalias($user); } // Fetch existing @alias_dom aliases. - $alias = $user->emailAlias(); - $visibility = $user->hasProfile() && $user->profile()->alias_pub; - $page->assign('actuel', $alias); + list($alias, $old_alias) = XDB::fetchOneRow('SELECT CONCAT(s.email, \'@\', d.name), s.email + FROM email_source_account AS s + INNER JOIN email_virtual_domains AS d ON (s.domain = d.id) + WHERE s.uid = {?} AND d.name = {?}', + $user->id(), $globals->mail->alias_dom); + $visibility = $user->hasProfile() && ($user->profile(true)->alias_pub == 'public'); + $page->assign('current', $alias); $page->assign('user', $user); $page->assign('mail_public', $visibility); - if ($action == 'ask' && Env::has('alias') && Env::has('raison')) { + if ($action == 'ask' && Env::has('alias') && Env::has('reason')) { S::assert_xsrf_token(); - //Si l'utilisateur vient de faire une damande - $alias = Env::v('alias'); - $raison = Env::v('raison'); + // Retrieves user request. + $new_alias = Env::v('alias'); + $reason = Env::v('reason'); $public = (Env::v('public', 'off') == 'on') ? 'public' : 'private'; - $page->assign('r_alias', $alias); - $page->assign('r_raison', $raison); + $page->assign('r_alias', $new_alias); + $page->assign('r_reason', $reason); if ($public == 'public') { $page->assign('r_public', true); } - //Quelques vérifications sur l'alias (caractères spéciaux) - if (!preg_match("/^[a-zA-Z0-9\-.]{3,20}$/", $alias)) { + // Checks special charaters in alias. + if (!preg_match("/^[a-zA-Z0-9\-.]{3,20}$/", $new_alias)) { $page->trigError("L'adresse demandée n'est pas valide." . " Vérifie qu'elle comporte entre 3 et 20 caractères" . " et qu'elle ne contient que des lettres non accentuées," . " des chiffres ou les caractères - et ."); return; } else { - $alias_mail = $alias.'@'.$globals->mail->alias_dom; - - //vérifier que l'alias n'est pas déja pris - $res = XDB::query('SELECT COUNT(*) - FROM virtual - WHERE alias={?}', - $alias_mail); + // Checks if the alias has already been given. + $res = XDB::query('SELECT COUNT(s.email) + FROM email_source_account AS s + INNER JOIN email_virtual_domains AS d ON (s.domain = d.id) + WHERE s.email = {?} AND d.name = {?}', + $new_alias, $globals->mail->alias_dom); if ($res->fetchOneCell() > 0) { - $page->trigError("L'alias $alias_mail a déja été attribué. - Tu ne peux donc pas l'obtenir."); + $page->trigError("L'alias $new_alias a déja été attribué. Tu ne peux donc pas l'obtenir."); return; } - //vérifier que l'alias n'est pas déja en demande + // Checks if the alias has already been asked for. $it = Validate::iterate('alias'); while($req = $it->next()) { - if ($req->alias == $alias_mail) { - $page->trigError("L'alias $alias_mail a déja été demandé. - Tu ne peux donc pas l'obtenir pour l'instant."); - return ; + if ($req->alias == $new_alias) { + $page->trigError("L'alias $new_alias a déja été demandé. Tu ne peux donc pas l'obtenir pour l'instant."); + return; } } - //Insertion de la demande dans la base, écrase les requêtes précédente - $myalias = new AliasReq($user, $alias, $raison, $public); + // Sends requests. This will erase any previous alias pending request. + $myalias = new AliasReq($user, $new_alias, $reason, $public, $old_alias); $myalias->submit(); - $page->assign('success',$alias); + $page->assign('success', $new_alias); return; } } elseif ($action == 'set' && ($value == 'public' || $value == 'private')) { @@ -190,24 +195,18 @@ class EmailModule extends PLModule } if ($user->hasProfile()) { - XDB::execute("UPDATE profiles + XDB::execute('UPDATE profiles SET alias_pub = {?} - WHERE pid = {?}", + WHERE pid = {?}', $value, $user->profile()->id()); } - $visibility = ($value == 'public'); exit; } - - $page->assign('actuel', $alias); - $page->assign('user', $user); - $page->assign('mail_public', $visibility); } - function handler_redirect($page, $action = null, $email = null) + function handler_redirect($page, $action = null, $email = null, $rewrite = null) { global $globals; - require_once 'emails.inc.php'; $page->changeTpl('emails/redirect.tpl'); @@ -238,15 +237,13 @@ class EmailModule extends PLModule } if ($action == 'rewrite' && $email) { - $rewrite = @func_get_arg(3); $redirect->modify_one_email_redirect($email, $rewrite); } if (Env::has('emailop')) { S::assert_xsrf_token(); - $actifs = Env::v('emails_actifs', Array()); - print_r(Env::v('emails_rewrite')); + $actifs = Env::v('emails_actifs', array()); if (Env::v('emailop') == "ajouter" && Env::has('email')) { $error_email = false; $new_email = Env::v('email'); @@ -263,7 +260,7 @@ class EmailModule extends PLModule } elseif (empty($actifs)) { $result = ERROR_INACTIVE_REDIRECTION; } elseif (is_array($actifs)) { - $result = $redirect->modify_email($actifs, Env::v('emails_rewrite', Array())); + $result = $redirect->modify_email($actifs, Env::v('emails_rewrite', array())); } } @@ -281,31 +278,16 @@ class EmailModule extends PLModule . $globals->mail->domain2 . ' ni vers polytechnique.edu.'); break; } - - // Fetch the @alias_dom email alias, if any. - $res = XDB::query( - "SELECT alias - FROM virtual - INNER JOIN virtual_redirect USING(vid) - WHERE (redirect={?} OR redirect={?}) - AND alias LIKE '%@{$globals->mail->alias_dom}'", - $user->forlifeEmail(), - // TODO: remove this über-ugly hack. The issue is that you need - // to remove all @m4x.org addresses in virtual_redirect first. - $user->login() . '@' . $globals->mail->domain2); - $melix = $res->fetchOneCell(); - if ($melix) { - list($melix) = explode('@', $melix); - $page->assign('melix',$melix); - } - // Fetch existing email aliases. - $res = XDB::query( - "SELECT alias,expire - FROM aliases - WHERE uid={?} AND (type='a_vie' OR type='alias') - ORDER BY !FIND_IN_SET('usage',flags), LENGTH(alias)", $user->id()); - $page->assign('alias', $res->fetchAllAssoc()); + $alias = XDB::query('SELECT CONCAT(s.email, \'@\', d.name) AS email, s.expire + FROM email_source_account AS s + INNER JOIN email_virtual_domains AS m ON (s.domain = m.id) + INNER JOIN email_virtual_domains AS d ON (m.id = d.aliasing) + WHERE s.uid = {?} + ORDER BY NOT (m.name = {?}), s.email, d.name', + $user->id(), $globals->mail->alias_dom); + $page->assign('alias', $alias->fetchAllAssoc()); + $page->assign('emails', $redirect->emails); // Display GoogleApps acount information. @@ -316,7 +298,7 @@ class EmailModule extends PLModule fill_email_combobox($page); } - function handler_antispam($page, $statut_filtre = null) + function handler_antispam($page, $filter_status = null) { require_once 'emails.inc.php'; $wp = new PlWikiPage('Xorg.Antispam'); @@ -326,10 +308,10 @@ class EmailModule extends PLModule $user = S::user(); $bogo = new Bogo($user); - if (isset($statut_filtre)) { - $bogo->change($statut_filtre + 0); + if (isset($filter_status)) { + $bogo->change($filter_status + 0); } - $page->assign('filtre', $bogo->level()); + $page->assign('filter', $bogo->level()); } function handler_submit($page) @@ -537,16 +519,16 @@ class EmailModule extends PLModule return PL_NOT_FOUND; } $mail{$pos} = '@'; - $res = XDB::query("SELECT COUNT(*) - FROM emails - WHERE email = {?} AND hash = {?}", + $res = XDB::query('SELECT COUNT(*) + FROM email_redirect_account + WHERE redirect = {?} AND hash = {?} AND type = \'smtp\'', $mail, $hash); $count = intval($res->fetchOneCell()); if ($count > 0) { - XDB::query("UPDATE emails + XDB::query('UPDATE email_redirect_account SET allow_rewrite = true, hash = NULL - WHERE email = {?} AND hash = {?}", - $mail, $hash); + WHERE redirect = {?} AND hash = {?} AND type = \'smtp\'', + $mail, $hash); $page->trigSuccess("Réécriture activée pour l'adresse " . $mail); return; } @@ -565,28 +547,28 @@ class EmailModule extends PLModule return PL_NOT_FOUND; } $mail{$pos} = '@'; - $res = XDB::query("SELECT COUNT(*) - FROM emails - WHERE email = {?} AND hash = {?}", + $res = XDB::query('SELECT COUNT(*) + FROM email_redirect_account + WHERE redirect = {?} AND hash = {?} AND type = \'smtp\'', $mail, $hash); $count = intval($res->fetchOneCell()); if ($count > 0) { global $globals; - $res = XDB::query("SELECT e.email, e.rewrite, a.alias - FROM emails AS e - INNER JOIN aliases AS a ON (a.uid = e.uid AND a.type = 'a_vie') - WHERE e.email = {?} AND e.hash = {?}", + $res = XDB::query('SELECT e.redirect, e.rewrite, a.hruid + FROM email_redirect_account AS e + INNER JOIN accounts AS a ON (e.uid = a.uid) + WHERE e.redirect = {?} AND e.hash = {?}', $mail, $hash); - XDB::query("UPDATE emails + XDB::query('UPDATE email_redirect_account SET allow_rewrite = false, hash = NULL - WHERE email = {?} AND hash = {?}", - $mail, $hash); - list($mail, $rewrite, $forlife) = $res->fetchOneRow(); + WHERE redirect = {?} AND hash = {?}', + $mail, $hash); + list($mail, $rewrite, $hruid) = $res->fetchOneRow(); $mail = new PlMailer(); $mail->setFrom("webmaster@" . $globals->mail->domain); $mail->addTo("support@" . $globals->mail->domain); $mail->setSubject("Tentative de détournement de correspondance via le rewrite"); - $mail->setTxtBody("$forlife a tenté un rewrite de $mail vers $rewrite. Cette demande a été rejetée via le web"); + $mail->setTxtBody("$hruid a tenté un rewrite de $mail vers $rewrite. Cette demande a été rejetée via le web"); $mail->send(); $page->trigWarning("Un mail d'alerte a été envoyé à l'équipe de " . $globals->core->sitename); return; @@ -611,17 +593,15 @@ class EmailModule extends PLModule } } - require_once('emails.inc.php'); + require_once 'emails.inc.php'; $page->assign('ok', false); if (S::logged() && (is_null($user) || $user->id() == S::i('uid'))) { - $storage = new EmailStorage(S::user(), 'imap'); - $storage->activate(); + Email::activate_storage(S::user(), 'imap'); $page->assign('ok', true); $page->assign('yourself', S::user()->displayName()); $page->assign('sexe', S::user()->isFemale()); } else if (!S::logged() && $user) { - $storage = new EmailStorage($user, 'imap'); - $storage->activate(); + Email::activate_storage($user, 'imap'); $page->assign('ok', true); $page->assign('yourself', $user->displayName()); $page->assign('sexe', $user->isFemale()); diff --git a/modules/googleapps.php b/modules/googleapps.php index dd3e97e..bbe1c9f 100644 --- a/modules/googleapps.php +++ b/modules/googleapps.php @@ -38,8 +38,8 @@ class GoogleAppsModule extends PLModule function handler_index($page, $action = null) { - require_once("emails.inc.php"); - require_once("googleapps.inc.php"); + require_once 'emails.inc.php'; + require_once 'googleapps.inc.php'; $page->changeTpl('googleapps/index.tpl'); $page->setTitle('Compte Google Apps'); @@ -47,16 +47,20 @@ class GoogleAppsModule extends PLModule $account = new GoogleAppsAccount($user); // Fills up the 'is Google Apps redirection active' variable. - $page->assign('redirect_active', false); - $page->assign('redirect_unique', true); + $redirect_active = false; + $redirect_unique = true; if ($account->active()) { $redirect = new Redirect($user); - $page->assign('redirect_unique', !$redirect->other_active('googleapps')); - - $storage = new EmailStorage($user, 'googleapps'); - $page->assign('redirect_active', $storage->active); + foreach ($redirect->emails as $email) { + if ($email->type == 'googleapps') { + $redirect_active = $email->active; + $redirect_unique = !$redirect->other_active($email->email); + } + } } + $page->assign('redirect_active', $redirect_active); + $page->assign('redirect_unique', $redirect_unique); // Updates the Google Apps account as required. if ($action) { @@ -115,7 +119,7 @@ class GoogleAppsModule extends PLModule } function handler_admin($page, $action = null) { - require_once("googleapps.inc.php"); + require_once 'googleapps.inc.php'; $page->changeTpl('googleapps/admin.tpl'); $page->setTitle('Administration Google Apps'); $page->assign('googleapps_admin', GoogleAppsAccount::is_administrator(S::v('uid'))); @@ -132,10 +136,10 @@ class GoogleAppsModule extends PLModule // Retrieves latest pending administrative requests from the gappsd queue. $res = XDB::iterator( - "SELECT q_id, q_recipient_id, a.alias, j_type, j_parameters, + "SELECT q_id, q_recipient_id, s.email AS alias, j_type, j_parameters, UNIX_TIMESTAMP(q.p_entry_date) AS p_entry_date FROM gapps_queue AS q - LEFT JOIN aliases AS a ON (a.uid = q_recipient_id AND a.type = 'a_vie') + LEFT JOIN email_source_account AS s ON (s.uid = q.q_recipient_id AND s.type = 'forlife') WHERE p_status IN ('idle', 'active', 'softfail') AND p_admin_request IS TRUE ORDER BY p_entry_date"); @@ -150,10 +154,10 @@ class GoogleAppsModule extends PLModule // Retrieves latest failed requests from the gappsd queue. $res = XDB::iterator( - "SELECT q.q_id, q.q_recipient_id, a.alias, q.j_type, q.r_result, + "SELECT q.q_id, q.q_recipient_id, s.email AS alias, q.j_type, q.r_result, UNIX_TIMESTAMP(q.p_entry_date) AS p_entry_date FROM gapps_queue AS q - LEFT JOIN aliases AS a ON (a.uid = q.q_recipient_id AND a.type = 'a_vie') + LEFT JOIN email_source_account AS s ON (s.uid = q.q_recipient_id AND s.type = 'forlife') WHERE q.p_status = 'hardfail' ORDER BY p_entry_date DESC LIMIT 20"); @@ -161,17 +165,17 @@ class GoogleAppsModule extends PLModule } function handler_admin_job($page, $job = null) { - require_once("googleapps.inc.php"); + require_once 'googleapps.inc.php'; $page->changeTpl('googleapps/admin.job.tpl'); $page->setTitle('Administration Google Apps'); $page->assign('googleapps_admin', GoogleAppsAccount::is_administrator(S::v('uid'))); if ($job) { $res = XDB::query( - "SELECT q.*, ao.alias AS q_owner, ar.alias AS q_recipient + "SELECT q.*, so.email AS q_owner, sr.email AS q_recipient FROM gapps_queue AS q - LEFT JOIN aliases AS ao ON (ao.uid = q.q_owner_id AND ao.type = 'a_vie') - LEFT JOIN aliases AS ar ON (ar.uid = q.q_recipient_id AND ar.type = 'a_vie') + LEFT JOIN email_source_account AS so ON (so.uid = q.q_owner_id AND so.type = 'forlife') + LEFT JOIN email_source_account AS sr ON (sr.uid = q.q_recipient_id AND sr.type = 'forlife') WHERE q_id = {?}", $job); $sql_job = $res->fetchOneAssoc(); $sql_job['decoded_parameters'] = var_export(json_decode($sql_job['j_parameters'], true), true); @@ -180,8 +184,8 @@ class GoogleAppsModule extends PLModule } function handler_admin_user($page, $user = null) { - require_once("emails.inc.php"); - require_once("googleapps.inc.php"); + require_once 'emails.inc.php'; + require_once 'googleapps.inc.php'; $page->changeTpl('googleapps/admin.user.tpl'); $page->setTitle('Administration Google Apps'); $page->assign('googleapps_admin', GoogleAppsAccount::is_administrator(S::v('uid'))); @@ -193,7 +197,6 @@ class GoogleAppsModule extends PLModule if ($user) { $account = new GoogleAppsAccount($user); - $storage = new EmailStorage($user, 'googleapps'); // Apply requested actions. if (Post::has('suspend') && $account->active() && !$account->pending_update_suspension) { @@ -217,7 +220,7 @@ class GoogleAppsModule extends PLModule // Displays basic account information. $page->assign('account', $account); $page->assign('admin_account', GoogleAppsAccount::is_administrator($user->id())); - $page->assign('googleapps_storage', $storage->active); + $page->assign('googleapps_storage', Email::is_active_storage($user, 'googleapps')); $page->assign('user', $user->id()); // Retrieves user's pending requests. diff --git a/modules/register.php b/modules/register.php index 6a1defc..d0c5323 100644 --- a/modules/register.php +++ b/modules/register.php @@ -365,8 +365,7 @@ class RegisterModule extends PLModule NewsLetter::forGroup(NewsLetter::GROUP_XORG)->subscribe($user); break; case 'imap': - $storage = new EmailStorage($user, 'imap'); - $storage->activate(); + Email::activate_storage($user, 'imap'); break; case 'ml_promo': $r = XDB::query('SELECT id FROM groups WHERE diminutif = {?}', $yearpromo); diff --git a/templates/emails/alias.tpl b/templates/emails/alias.tpl index d502146..8eb7b75 100644 --- a/templates/emails/alias.tpl +++ b/templates/emails/alias.tpl @@ -35,7 +35,7 @@ Adresses email personnalisées -{if $actuel} +{if $current} {if $user->hasProfile()} @@ -46,7 +46,7 @@ " /> @@ -65,16 +65,16 @@ sans doute à toutes tes questions.

- {if $actuel} + {if $current}

- Note : tu as déjà l'alias {$actuel}, or tu ne peux avoir qu'un seul alias à la fois. + Note : tu as déjà l'alias {$current}, or tu ne peux avoir qu'un seul alias à la fois. Si tu effectues une nouvelle demande l'ancien alias sera effacé.

{/if} - {if $demande} + {if $request}

- Note : tu as déjà effectué une demande pour {$demande->alias}, dont le traitement est + Note : tu as déjà effectué une demande pour {$request->alias}, dont le traitement est en cours. Si tu souhaites modifier ceci refais une demande, sinon ce n'est pas la peine.

{/if} @@ -112,16 +112,16 @@
- +
- Ton alias est actuellement : {$actuel}. Il est pour l'instant + Ton alias est actuellement : {$current}. Il est pour l'instant {if $mail_public}public et apparaît donc sur ta fiche.{else}privé et n'apparaît nulle part sur le site.{/if}
Brève explication :
- {if $actuel} -
+ {if $current} + {xsrf_token_field} @@ -129,7 +129,7 @@
- +
diff --git a/templates/emails/antispam.tpl b/templates/emails/antispam.tpl index 628cf37..e2af941 100644 --- a/templates/emails/antispam.tpl +++ b/templates/emails/antispam.tpl @@ -27,7 +27,7 @@ $(function() { var url = '{/literal}{$globals->baseurl}/emails/antispam/{literal}'; var msg = "Le changement de réglage de l'antispam a bien été effectué."; - $(':radio[name=statut_filtre]').change(function() { + $(':radio[name=filter_status]').change(function() { $("#bogo-msg").successMessage(url + $(this).val(), msg); }); }); @@ -35,16 +35,16 @@ //]]>
Choisis ton propre réglage : - +
- +
- +
- +
diff --git a/templates/emails/index.tpl b/templates/emails/index.tpl index de94958..bfcd67e 100644 --- a/templates/emails/index.tpl +++ b/templates/emails/index.tpl @@ -44,10 +44,10 @@ Tes adresses polytechniciennes sont :
{iterate from=$aliases item=a} - +  {if $a.forlife}(**){/if}{if $a.hundred_year}(*){/if} {if $a.expire}(expire le {$a.expire|date_format}){/if} + {if $a.alias}(changer ou supprimer mon alias melix){/if}
{/iterate}
@@ -56,20 +56,13 @@
Coche une autre case pour en changer !

-
-
- {if $melix} -
- Tu dispose également de l'alias : {$melix} - (changer ou supprimer mon alias melix) -
- {/if} +


(M4X signifie mail for X, son intérêt est de te doter d'une adresse à vie moins "voyante" que l'adresse @{#globals.mail.domain#}). - {if !$melix} + {if !$alias} Tu peux ouvrir en supplément une adresse synonyme de ton adresse @{#globals.mail.domain#}, sur les domaines @{#globals.mail.alias_dom#} et @{#globals.mail.alias_dom2#} (melix = Mél X).
@@ -79,10 +72,10 @@

{assign var="profile" value=$smarty.session.user->profile()} -(*) cette adresse email t'est réservée pour une période 100 ans après ton entrée à l'X (dans ton cas, jusqu'en {$profile->yearpromo()+100}). +(*) ces adresses email t'est réservée pour une période 100 ans après ton entrée à l'X (dans ton cas, jusqu'en {$profile->yearpromo()+100}).

-(**) cette adresse email t'est réservée à vie. +(**) ces adresses email te sont réservées à vie.

{if $homonyme} diff --git a/templates/emails/redirect.tpl b/templates/emails/redirect.tpl index 4fb801f..6d64ef2 100644 --- a/templates/emails/redirect.tpl +++ b/templates/emails/redirect.tpl @@ -27,16 +27,10 @@ Tu configures ici les adresses emails vers lesquelles tes adresses (listées ci-dessous) sont redirigées :

    - {if $melix} -
  • - {$melix}@{#globals.mail.alias_dom#}, - {$melix}@{#globals.mail.alias_dom2#} -
  • - {/if} {foreach from=$alias item=a}
  • - {$a.alias}@{#globals.mail.domain#} - {if $a.expire}(expire le {$a.expire|date_format}){/if} + {$a.email} + {if $a.expire}(expire le {$a.expire|date_format}){/if}
  • {/foreach}
@@ -80,7 +74,7 @@ { if (confirm("Supprimer l'adresse " + email + " ?")) { $.get(link.href, {},function() { - $('#line_' + email.replace('@', '_at_').replace('.','\\.')).remove(); + $('#line_' + email.replace('@', '_at_').replace('.', '\\.')).remove(); showRemove(); activeEnable(); }); @@ -135,8 +129,8 @@ - {if $e->broken}{assign var="erreur" value="1"}{/if} - {if $e->panne neq '0000-00-00'}{assign var="panne" value="1"}{icon name=error title="En panne"}{/if} + {if $e->broken}{assign var="error" value="1"}{/if} + {if $e->broken_date neq '0000-00-00'}{assign var="broken" value="1"}{icon name=error title="En panne"}{/if} {$e->display_email} {if $e->broken}{/if} @@ -150,13 +144,8 @@ {if $e->has_rewrite()} {if $e->rewrite neq '' && !$e->allow_rewrite}{icon name="error" title="en attente de validation"}{/if} @@ -166,9 +155,8 @@ {if $e->is_removable()} - + {icon name=cross title="Supprimer"} {else} @@ -178,13 +166,16 @@ {/foreach} - {cycle values="pair,impair" assign=class_combobox} - {$error_email} - {include file="include/emails.combobox.tpl" name="email" val=$email class=$class_combobox error=$error_email i="0"} -
- - {xsrf_token_field} -
+ {cycle values="pair,impair" assign=class_combobox} + {include file="include/emails.combobox.tpl" name="email" val=$email class=$class_combobox error=$error_email i="0"} + + +
+ + {xsrf_token_field} +
+ + @@ -193,7 +184,7 @@ Légende : {icon name=cross title="Supprimer"} Supprimer la redirection - {icon name=information title="Plus d'informations"} Plus d'informations

-{if $panne} +{if t($broken)}

{icon name=error title="En panne"} @@ -203,7 +194,7 @@ a été détectée. Si le problème persiste, la redirection vers ces adresses sera désactivée.

{/if} -{if $erreur} +{if t($error)}

{icon name=error title="En panne"} diff --git a/templates/include/emails.combobox.tpl b/templates/include/emails.combobox.tpl index b1a3f7e..021a47f 100644 --- a/templates/include/emails.combobox.tpl +++ b/templates/include/emails.combobox.tpl @@ -44,21 +44,8 @@ {/if} {if $name eq "email_directory"} - {if $melix} - - - {/if} {foreach from=$list_email_X item=email} - - + {/foreach} {/if} diff --git a/templates/include/form.valid.aliases.tpl b/templates/include/form.valid.aliases.tpl index c5c3c51..dbab548 100644 --- a/templates/include/form.valid.aliases.tpl +++ b/templates/include/form.valid.aliases.tpl @@ -23,7 +23,7 @@ Ancien alias - {$valid->old|default:"-none-"} + {$valid->old|default:"-aucun-"} Nouvel alias : @@ -35,7 +35,7 @@ Motif : - {$valid->raison|nl2br} + {$valid->reason|nl2br} {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} -- 2.1.4