X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Femail.php;h=1badbd88420b07708049309bf1969ff5663ded1e;hb=a6735b65f3b060a836b6fc56bbc823ce4017d100;hp=22abcf530a8616c8cf15a3ed7e55804c4e15c083;hpb=5e2307dcebc38ebb0ffe469967a377eb3baed571;p=platal.git diff --git a/modules/email.php b/modules/email.php index 22abcf5..1badbd8 100644 --- a/modules/email.php +++ b/modules/email.php @@ -1,6 +1,6 @@ $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), + + 'admin/emails/duplicated' => $this->make_hook('duplicated', AUTH_MDP, 'admin') ); } - function handler_emails(&$page) + function handler_emails(&$page, $action = null, $email = null) { global $globals; @@ -42,12 +45,12 @@ class EmailModule extends PLModule $uid = S::v('uid'); - if (Post::has('best')) { + if ($action == 'best' && $email) { // bestalias is the first bit : 1 // there will be maximum 8 bits in flags : 255 XDB::execute("UPDATE aliases SET flags=flags & (255 - 1) WHERE id={?}", $uid); XDB::execute("UPDATE aliases SET flags=flags | 1 WHERE id={?} AND alias={?}", - $uid, Post::v('best')); + $uid, $email); } // on regarde si on a affaire à un homonyme @@ -59,6 +62,9 @@ class EmailModule extends PLModule ORDER BY LENGTH(alias)"; $page->assign('aliases', XDB::iterator($sql, $uid)); + $homonyme = XDB::query("SELECT alias FROM aliases INNER JOIN homonymes ON (id = homonyme_id) WHERE user_id = {?} AND type = 'homonyme'", $uid); + $page->assign('homonyme', $homonyme->fetchOneCell()); + $sql = "SELECT email FROM emails WHERE uid = {?} AND FIND_IN_SET('active', flags)"; @@ -91,7 +97,7 @@ class EmailModule extends PLModule $page->assign('demande', AliasReq::get_request($uid)); - if ($action == 'suppr' && $value) { + if ($action == 'delete' && $value) { //Suppression d'un alias XDB::execute( 'DELETE virtual, virtual_redirect @@ -188,14 +194,31 @@ class EmailModule extends PLModule $uid = S::v('uid'); $forlife = S::v('forlife'); + $page->assign('eleve', S::i('promo') >= date("Y") - 5); + $redirect = new Redirect(S::v('uid')); if ($action == 'remove' && $email) { - $page->assign('retour', $redirect->delete_email($email)); + $retour = $redirect->delete_email($email); + $page->assign('retour', $retour); } - + + if ($action == 'active' && $email) { + $redirect->modify_one_email($email, true); + } + + if ($action == 'inactive' && $email) { + $redirect->modify_one_email($email, false); + } + + if ($action == 'rewrite' && $email) { + $rewrite = @func_get_arg(3); + $redirect->modify_one_email_redirect($email, $rewrite); + } + if (Env::has('emailop')) { $actifs = Env::v('emails_actifs', Array()); + print_r(Env::v('emails_rewrite')); if (Env::v('emailop') == "ajouter" && Env::has('email')) { $page->assign('retour', $redirect->add_email(Env::v('email'))); } elseif (empty($actifs)) { @@ -228,19 +251,48 @@ class EmailModule extends PLModule $page->assign('emails',$redirect->emails); } - function handler_antispam(&$page) + function handler_antispam(&$page, $statut_filtre = null) { require_once 'emails.inc.php'; + require_once('wiki.inc.php'); + wiki_require_page('Xorg.Antispam'); $page->changeTpl('emails/antispam.tpl'); $bogo = new Bogo(S::v('uid')); - if (Env::has('statut_filtre')) { - $bogo->change(S::v('uid'), Env::i('statut_filtre')); + if (isset($statut_filtre)) { + $bogo->change(S::v('uid'), $statut_filtre + 0); } $page->assign('filtre',$bogo->level()); } + function handler_submit(&$page) + { + $page->changeTpl('emails/submit_spam.tpl'); + + if (Post::has('send_email')) { + $upload = $_FILES['mail']['tmp_name']; + if (!is_uploaded_file($upload)) { + $page->trig('Une erreur a été rencontrée lors du transfert du fichier'); + return; + } + $mime = mime_content_type($upload); + if ($mime != 'text/x-mail' && $mime != 'message/rfc822') { + $page->trig('Le fichier ne contient pas un mail complet'); + return; + } + global $globals; + $box = Post::v('type') . '@' . $globals->mail->domain; + $mailer = new PlMailer(); + $mailer->addTo($box); + $mailer->setFrom('"' . S::v('prenom') . ' ' . S::v('nom') . '" mail->domain . '>'); + $mailer->setTxtBody(Post::v('type') . ' soumis par ' . S::v('forlife') . ' via le web'); + $mailer->addAttachment($upload, 'message/rfc822', $_FILES['mail']['name']); + $mailer->send(); + $page->trig('Le message a été transmis à ' . $box); + } + } + function handler_send(&$page) { global $globals; @@ -252,7 +304,21 @@ class EmailModule extends PLModule // action si on recoit un formulaire if (Env::v('submit') == 'Envoyer') { - $to2 = join(', ', Env::v('contacts', Array())); + function getEmails($aliases) + { + if (!is_array($aliases)) { + return null; + } + $rel = Env::v('contacts'); + $ret = array(); + foreach ($aliases as $alias) { + $ret[$alias] = $rel[$alias]; + } + return join(', ', $ret); + } + + $to2 = getEmails(Env::v('to_contacts')); + $cc2 = getEmails(Env::v('cc_contacts')); $txt = str_replace('^M', '', Env::v('contenu')); $to = Env::v('to'); $subj = Env::v('sujet'); @@ -263,15 +329,19 @@ class EmailModule extends PLModule if (empty($to) && empty($cc) && empty($to2)) { $page->trig("Indique au moins un destinataire."); } else { - require_once("diogenes/diogenes.hermes.inc.php"); - - $mymail = new HermesMailer(); + $mymail = new PlMailer(); $mymail->setFrom($from); $mymail->setSubject($subj); if (!empty($to)) { $mymail->addTo($to); } if (!empty($cc)) { $mymail->addCc($cc); } if (!empty($bcc)) { $mymail->addBcc($bcc); } if (!empty($to2)) { $mymail->addTo($to2); } + if (!empty($cc2)) { $mymail->addCc($cc2); } + if (is_uploaded_file($_FILES['uploaded']['tmp_name'])) { + $mymail->addAttachment($_FILES['uploaded']['tmp_name'], + $_FILES['uploaded']['type'], + $_FILES['uploaded']['name']); + } $mymail->setTxtBody(wordwrap($txt,72,"\n")); if ($mymail->send()) { $page->trig("Ton mail a bien été envoyé."); @@ -334,8 +404,7 @@ consulter la page <{$globals->baseurl}/emails/broken>. A bientôt sur Polytechnique.org ! L'équipe d'administration "; - require_once("diogenes/diogenes.hermes.inc.php"); - $mail = new HermesMailer(); + $mail = new PlMailer(); $mail->setFrom('"Polytechnique.org" '); $mail->addTo("$dest@polytechnique.org"); $mail->setSubject("Une de tes adresse de redirection Polytechnique.org ne marche plus !!"); @@ -367,13 +436,112 @@ L' if ($x = $sel->fetchOneAssoc()) { // on écrit dans la base que l'adresse est cassée if (!$x['panne']) { - XDB::execute("UPDATE emails SET panne=NOW() WHERE email = {?}", $email); + XDB::execute("UPDATE emails + SET panne=NOW(), + last=NOW(), + panne_level = 1 + WHERE email = {?}", $email); + } else { + XDB::execute("UPDATE emails + SET panne_level = 1 + WHERE email = {?} AND panne_level = 0"); } $page->assign_by_ref('x', $x); } } } } + + function handler_duplicated(&$page, $action = 'list', $email = null) + { + $page->changeTpl('emails/duplicated.tpl'); + + $states = array('pending' => 'En attente...', + 'safe' => 'Pas d\'inquiétude', + 'unsafe' => 'Recherches en cours', + 'dangerous' => 'Usurpations par cette adresse'); + $page->assign('states', $states); + + switch (Post::v('action')) { + case 'create': + if (trim(Post::v('emailN')) != '') { + Xdb::execute('INSERT IGNORE INTO emails_watch (email, state, detection, last, uid, description) + VALUES ({?}, {?}, CURDATE(), NOW(), {?}, {?})', + trim(Post::v('emailN')), Post::v('stateN'), S::i('uid'), Post::v('descriptionN')); + }; + break; + + case 'edit': + Xdb::execute('UPDATE emails_watch + SET state = {?}, last = NOW(), uid = {?}, description = {?} + WHERE email = {?}', Post::v('stateN'), S::i('uid'), Post::v('descriptionN'), Post::v('emailN')); + break; + + default: + if ($action == 'delete' && !is_null($email)) { + Xdb::execute('DELETE FROM emails_watch WHERE email = {?}', $email); + } + } + if ($action != 'create' && $action != 'edit') { + $action = 'list'; + } + $page->assign('action', $action); + + if ($action == 'list') { + $sql = "SELECT w.email, w.detection, w.state, a.alias AS forlife + FROM emails_watch AS w + LEFT JOIN emails AS e USING(email) + LEFT JOIN aliases AS a ON (a.id = e.uid AND a.type = 'a_vie') + ORDER BY w.state, w.email, a.alias"; + $it = Xdb::iterRow($sql); + + $table = array(); + $props = array(); + while (list($email, $date, $state, $forlife) = $it->next()) { + if (count($props) == 0 || $props['mail'] != $email) { + if (count($props) > 0) { + $table[] = $props; + } + $props = array('mail' => $email, + 'detection' => $date, + 'state' => $state, + 'users' => array($forlife)); + } else { + $props['users'][] = $forlife; + } + } + if (count($props) > 0) { + $table[] = $props; + } + $page->assign('table', $table); + } elseif ($action == 'edit') { + $sql = "SELECT w.detection, w.state, w.last, w.description, + a1.alias AS edit, a2.alias AS forlife + FROM emails_watch AS w + LEFT JOIN aliases AS a1 ON (a1.id = w.uid AND a1.type = 'a_vie') + LEFT JOIN emails AS e ON (w.email = e.email) + LEFT JOIN aliases AS a2 ON (a2.id = e.uid AND a2.type = 'a_vie') + WHERE w.email = {?} + ORDER BY a2.alias"; + $it = Xdb::iterRow($sql, $email); + + $props = array(); + while (list($detection, $state, $last, $description, $edit, $forlife) = $it->next()) { + if (count($props) == 0) { + $props = array('mail' => $email, + 'detection' => $detection, + 'state' => $state, + 'last' => $last, + 'description' => $description, + 'edit' => $edit, + 'users' => array($forlife)); + } else { + $props['users'][] = $forlife; + } + } + $page->assign('doublon', $props); + } + } } ?>