X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Femail.php;h=80dda05fbde1fbd8dad5fc267f5faa7976887db3;hb=1dc71da137a384e771723b8a893539a7f5cc9fab;hp=504e8eb9218f6aa6f13d3d94f62f9b5c02768cd6;hpb=59bec5bc5512a4f962ebac7b0346f59cdf56f901;p=platal.git diff --git a/modules/email.php b/modules/email.php index 504e8eb..80dda05 100644 --- a/modules/email.php +++ b/modules/email.php @@ -24,23 +24,24 @@ class EmailModule extends PLModule function handlers() { return array( - 'emails' => $this->make_hook('emails', AUTH_COOKIE), - 'emails/alias' => $this->make_hook('alias', AUTH_MDP), - 'emails/antispam' => $this->make_hook('antispam', AUTH_MDP), - 'emails/broken' => $this->make_hook('broken', AUTH_COOKIE), - 'emails/redirect' => $this->make_hook('redirect', AUTH_MDP), - 'emails/send' => $this->make_hook('send', AUTH_MDP), - 'emails/antispam/submit' => $this->make_hook('submit', AUTH_COOKIE), - 'emails/test' => $this->make_hook('test', AUTH_COOKIE, 'user', NO_AUTH), - - 'emails/rewrite/in' => $this->make_hook('rewrite_in', AUTH_PUBLIC), - 'emails/rewrite/out' => $this->make_hook('rewrite_out', AUTH_PUBLIC), - - 'emails/imap/in' => $this->make_hook('imap_in', AUTH_PUBLIC), - - 'admin/emails/duplicated' => $this->make_hook('duplicated', AUTH_MDP, 'admin'), - 'admin/emails/watch' => $this->make_hook('duplicated', AUTH_MDP, 'admin'), - 'admin/emails/lost' => $this->make_hook('lost', AUTH_MDP, 'admin'), + 'emails' => $this->make_hook('emails', AUTH_COOKIE), + 'emails/alias' => $this->make_hook('alias', AUTH_MDP), + 'emails/antispam' => $this->make_hook('antispam', AUTH_MDP), + 'emails/broken' => $this->make_hook('broken', AUTH_COOKIE), + 'emails/redirect' => $this->make_hook('redirect', AUTH_MDP), + 'emails/send' => $this->make_hook('send', AUTH_MDP), + 'emails/antispam/submit' => $this->make_hook('submit', AUTH_COOKIE), + 'emails/test' => $this->make_hook('test', AUTH_COOKIE, 'user', NO_AUTH), + + 'emails/rewrite/in' => $this->make_hook('rewrite_in', AUTH_PUBLIC), + 'emails/rewrite/out' => $this->make_hook('rewrite_out', AUTH_PUBLIC), + + 'emails/imap/in' => $this->make_hook('imap_in', AUTH_PUBLIC), + + 'admin/emails/duplicated' => $this->make_hook('duplicated', AUTH_MDP, 'admin'), + 'admin/emails/watch' => $this->make_hook('duplicated', AUTH_MDP, 'admin'), + 'admin/emails/lost' => $this->make_hook('lost', AUTH_MDP, 'admin'), + 'admin/emails/broken' => $this->make_hook('broken_addr', AUTH_MDP, 'admin'), ); } @@ -235,8 +236,9 @@ class EmailModule extends PLModule $email = str_replace(' ', '+', $email); // Apply email redirection change requests. + $result = SUCCESS; if ($action == 'remove' && $email) { - $retour = $redirect->delete_email($email); + $result = $redirect->delete_email($email); } if ($action == 'active' && $email) { @@ -258,15 +260,23 @@ class EmailModule extends PLModule $actifs = Env::v('emails_actifs', Array()); print_r(Env::v('emails_rewrite')); if (Env::v('emailop') == "ajouter" && Env::has('email')) { - $retour = $redirect->add_email(Env::v('email')); + $new_email = Env::v('email'); + if ($new_email == "new@example.org") { + $new_email = Env::v('email_new'); + } + $result = $redirect->add_email($new_email); + if ($result == ERROR_INVALID_EMAIL) { + $page->assign('email', $new_email); + } + $page->assign('retour', $result); } elseif (empty($actifs)) { - $retour = ERROR_INACTIVE_REDIRECTION; + $result = ERROR_INACTIVE_REDIRECTION; } elseif (is_array($actifs)) { - $retour = $redirect->modify_email($actifs, Env::v('emails_rewrite', Array())); + $result = $redirect->modify_email($actifs, Env::v('emails_rewrite', Array())); } } - switch ($retour) { + switch ($result) { case ERROR_INACTIVE_REDIRECTION: $page->trigError('Tu ne peux pas avoir aucune adresse de redirection active, sinon ton adresse ' . $user->forlifeEmail() . ' ne fonctionnerait plus.'); @@ -310,6 +320,9 @@ class EmailModule extends PLModule // Display GoogleApps acount information. require_once 'googleapps.inc.php'; $page->assign('googleapps', GoogleAppsAccount::account_status($user->id())); + + require_once 'emails.combobox.inc.php'; + fill_email_combobox($page); } function handler_antispam(&$page, $statut_filtre = null) @@ -487,7 +500,7 @@ class EmailModule extends PLModule } // Retrieves the User object for the test email recipient. - if (S::has_perms() && $hruid) { + if (S::admin() && $hruid) { $user = User::getSilent($hruid); } else { $user = S::user(); @@ -653,7 +666,7 @@ L'équipe d'administration mail->domain . '>'; $mail->setSubject("Une de tes adresse de redirection Polytechnique.org ne marche plus !!"); $mail->setTxtBody($message); $mail->send(); - $page->trigSuccess("Email envoyé !"); + $page->trigSuccess('Email envoyé !'); } } elseif (Post::has('email')) { S::assert_xsrf_token(); @@ -789,6 +802,7 @@ L'équipe d'administration mail->domain . '>'; $page->assign('doublon', $props); } } + function handler_lost(&$page, $action = 'list', $email = null) { $page->changeTpl('emails/lost.tpl'); @@ -801,6 +815,141 @@ L'équipe d'administration mail->domain . '>'; u.deces = 0 AND u.perms IN ('user', 'admin', 'disabled') ORDER BY u.promo DESC, u.nom, u.prenom")); } + + function handler_broken_addr(&$page) + { + require_once 'emails.inc.php'; + $page->changeTpl('emails/broken_addr.tpl'); + + if (Env::has('sort_broken')) { + S::assert_xsrf_token(); + + $list = trim(Env::v('list')); + if ($list == '') { + $page->trigError('La liste est vide.'); + } else { + $valid_emails = array(); + $invalid_emails = array(); + $broken_list = explode("\n", $list); + sort($broken_list); + foreach ($broken_list as $orig_email) { + $email = valide_email(trim($orig_email)); + if (empty($email) || $email == '@') { + $invalid_emails[] = "$orig_email: invalid email"; + } else { + $res = XDB::query('SELECT COUNT(*) + FROM emails + WHERE email = {?}', $email); + if ($res->fetchOneCell() > 0) { + $valid_emails[] = $email; + } else { + $invalid_emails[] = "$orig_email: no such redirection"; + } + } + } + + $page->assign('valid_emails', $valid_emails); + $page->assign('invalid_emails', $invalid_emails); + } + } + + if (Env::has('process_broken')) { + S::assert_xsrf_token(); + + $list = trim(Env::v('list')); + if ($list == '') { + $page->trigError('La liste est vide.'); + } else { + global $platal; + + $broken_user_list = array(); + $broken_list = explode("\n", $list); + sort($broken_list); + foreach ($broken_list as $orig_email) { + $email = valide_email(trim($orig_email)); + if (empty($email) || $email == '@') { + continue; + } + + $sel = XDB::query( + "SELECT e1.uid, e1.panne != 0 AS panne, count(e2.uid) AS nb_mails, + u.nom, u.prenom, u.promo, a.alias + FROM emails AS e1 + LEFT JOIN emails AS e2 ON (e1.uid = e2.uid AND FIND_IN_SET('active', e2.flags) + AND e1.email != e2.email) + INNER JOIN auth_user_md5 AS u ON (e1.uid = u.user_id) + INNER JOIN aliases AS a ON (u.user_id = a.id AND FIND_IN_SET('bestalias', a.flags)) + WHERE e1.email = {?} + GROUP BY e1.uid", $email); + + if ($x = $sel->fetchOneAssoc()) { + if (!$x['panne']) { + XDB::execute('UPDATE emails + SET panne=NOW(), last=NOW(), panne_level = 1 + WHERE email = {?}', + $email); + } else { + XDB::execute('UPDATE emails + SET last = CURDATE(), panne_level = panne_level + 1 + WHERE email = {?} + AND DATE_ADD(last, INTERVAL 14 DAY) < CURDATE()', + $email); + } + + if (!empty($x['nb_mails'])) { + $mail = new PlMailer('emails/broken.mail.tpl'); + $mail->addTo("\"{$x['prenom']} {$x['nom']}\" <{$x['alias']}@" + . $globals->mail->domain . '>'); + $mail->assign('x', $x); + $mail->assign('email', $email); + $mail->send(); + } + + if (!isset($broken_user_list[$x['alias']])) { + $broken_user_list[$x['alias']] = array($email); + } else { + $broken_user_list[$x['alias']][] = $email; + } + } + } + + XDB::execute("UPDATE emails + SET panne_level = panne_level - 1 + WHERE flags = 'active' AND panne_level > 1 + AND DATE_ADD(last, INTERVAL 1 MONTH) < CURDATE()"); + XDB::execute("UPDATE emails + SET panne_level = 0 + WHERE flags = 'active' AND panne_level = 1 + AND DATE_ADD(last, INTERVAL 1 YEAR) < CURDATE()"); + + // Output the list of users with recently broken addresses, + // along with the count of valid redirections. + header('Content-Type: text/x-csv; charset=utf-8;'); + header('Cache-Control: no-cache'); + + $csv = fopen('php://output', 'w'); + fputcsv($csv, array('nom', 'prenom', 'alias', 'bounce', 'nbmails', 'url'), ';'); + foreach ($broken_user_list as $alias => $mails) { + $sel = Xdb::query( + "SELECT u.user_id, count(e.email) AS nb_mails, u.nom, u.prenom, u.promo + FROM aliases AS a + INNER JOIN auth_user_md5 AS u ON a.id = u.user_id + LEFT JOIN emails AS e ON (e.uid = u.user_id + AND FIND_IN_SET('active', e.flags) AND e.panne = 0) + WHERE a.alias = {?} + GROUP BY u.user_id", $alias); + + if ($x = $sel->fetchOneAssoc()) { + fputcsv($csv, array($x['nom'], $x['prenom'], $x['promo'], $alias, + join(',', $mails), $x['nb_mails']), + 'https://www.polytechnique.org/marketing/broken/' . $alias, ';'); + } + } + fclose($csv); + exit; + } + } + } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: