2 /***************************************************************************
3 * Copyright (C) 2003-2008 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class EmailModule
extends PLModule
27 'emails' => $this->make_hook('emails', AUTH_COOKIE
),
28 'emails/alias' => $this->make_hook('alias', AUTH_MDP
),
29 'emails/antispam' => $this->make_hook('antispam', AUTH_MDP
),
30 'emails/broken' => $this->make_hook('broken', AUTH_COOKIE
),
31 'emails/redirect' => $this->make_hook('redirect', AUTH_MDP
),
32 'emails/send' => $this->make_hook('send', AUTH_MDP
),
33 'emails/antispam/submit' => $this->make_hook('submit', AUTH_COOKIE
),
34 'emails/test' => $this->make_hook('test', AUTH_COOKIE
, 'user', NO_AUTH
),
36 'emails/rewrite/in' => $this->make_hook('rewrite_in', AUTH_PUBLIC
),
37 'emails/rewrite/out' => $this->make_hook('rewrite_out', AUTH_PUBLIC
),
39 'emails/imap/in' => $this->make_hook('imap_in', AUTH_PUBLIC
),
41 'admin/emails/duplicated' => $this->make_hook('duplicated', AUTH_MDP
, 'admin'),
42 'admin/emails/watch' => $this->make_hook('duplicated', AUTH_MDP
, 'admin'),
43 'admin/emails/lost' => $this->make_hook('lost', AUTH_MDP
, 'admin'),
47 function handler_emails(&$page, $action = null
, $email = null
)
50 require_once 'emails.inc.php';
52 $page->changeTpl('emails/index.tpl');
53 $page->setTitle('Mes emails');
57 // Apply the bestalias change request.
58 if ($action == 'best' && $email) {
59 if (!S
::has_xsrf_token()) {
63 XDB
::execute("UPDATE aliases
64 SET flags = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', flags, ','), ',bestalias,', ','))
65 WHERE id = {?}", $user->id());
66 XDB
::execute("UPDATE aliases
67 SET flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'bestalias')
68 WHERE id = {?} AND alias = {?}", $user->id(), $email);
70 // As having a non-null bestalias value is critical in
71 // plat/al's code, we do an a posteriori check on the
72 // validity of the bestalias.
76 // Fetch and display aliases.
77 $sql = "SELECT alias, (type='a_vie') AS a_vie,
78 (alias REGEXP '\\\\.[0-9]{2}$') AS cent_ans,
79 FIND_IN_SET('bestalias',flags) AS best, expire
81 WHERE id = {?} AND type!='homonyme'
82 ORDER BY LENGTH(alias)";
83 $page->assign('aliases', XDB
::iterator($sql, $user->id()));
85 // Check for homonyms.
86 $homonyme = XDB
::query(
89 INNER JOIN homonymes ON (id = homonyme_id)
90 WHERE user_id = {?} AND type = 'homonyme'", $user->id());
91 $page->assign('homonyme', $homonyme->fetchOneCell());
93 // Display active redirections.
94 $redirect = new Redirect($user);
95 $page->assign('mails', $redirect->active_emails());
97 // Display, when available, the @alias_dom email alias.
101 INNER JOIN virtual_redirect AS vr USING(vid)
102 WHERE (redirect={?} OR redirect={?})
103 AND alias LIKE '%@{$globals->mail->alias_dom}'",
104 $user->forlifeEmail(),
105 // TODO: remove this über-ugly hack. The issue is that you need
106 // to remove all @m4x.org addresses in virtual_redirect first.
107 $user->login() . '@' . $globals->mail
->domain2
);
108 $page->assign('melix', $res->fetchOneCell());
111 function handler_alias(&$page, $action = null
, $value = null
)
113 require_once 'validations.inc.php';
117 $page->changeTpl('emails/alias.tpl');
118 $page->setTitle('Alias melix.net');
121 $page->assign('demande', AliasReq
::get_request($user->id()));
123 // Remove the email alias.
124 if ($action == 'delete' && $value) {
125 S
::assert_xsrf_token();
128 "DELETE virtual, virtual_redirect
130 INNER JOIN virtual_redirect USING (vid)
131 WHERE alias = {?} AND (redirect = {?} OR redirect = {?})",
132 $value, $user->forlifeEmail(),
133 // TODO: remove this über-ugly hack. The issue is that you need
134 // to remove all @m4x.org addresses in virtual_redirect first.
135 $user->login() . '@' . $globals->mail
->domain2
);
138 // Fetch existing @alias_dom aliases.
140 "SELECT alias, emails_alias_pub
141 FROM auth_user_quick, virtual
142 INNER JOIN virtual_redirect USING(vid)
143 WHERE (redirect = {?} OR redirect = {?})
144 AND alias LIKE '%@{$globals->mail->alias_dom}' AND user_id = {?}",
145 $user->forlifeEmail(),
146 // TODO: remove this über-ugly hack. The issue is that you need
147 // to remove all @m4x.org addresses in virtual_redirect first.
148 $user->login() . '@' . $globals->mail
->domain2
, $user->id());
149 list($alias, $visibility) = $res->fetchOneRow();
150 $page->assign('actuel', $alias);
152 if ($action == 'ask' && Env
::has('alias') && Env
::has('raison')) {
153 S
::assert_xsrf_token();
155 //Si l'utilisateur vient de faire une damande
156 $alias = Env
::v('alias');
157 $raison = Env
::v('raison');
158 $public = (Env
::v('public', 'off') == 'on')?
"public":"private";
160 $page->assign('r_alias', $alias);
161 $page->assign('r_raison', $raison);
162 if ($public == 'public') {
163 $page->assign('r_public', true
);
166 //Quelques vérifications sur l'alias (caractères spéciaux)
167 if (!preg_match( "/^[a-zA-Z0-9\-.]{3,20}$/", $alias)) {
168 $page->trigError("L'adresse demandée n'est pas valide."
169 . " Vérifie qu'elle comporte entre 3 et 20 caractères"
170 . " et qu'elle ne contient que des lettres non accentuées,"
171 . " des chiffres ou les caractères - et .");
174 //vérifier que l'alias n'est pas déja pris
175 $res = XDB
::query('SELECT COUNT(*) FROM virtual WHERE alias={?}',
176 $alias.'@'.$globals->mail
->alias_dom
);
177 if ($res->fetchOneCell() > 0) {
178 $page->trigError("L'alias $alias@{$globals->mail->alias_dom} a déja été attribué.
179 Tu ne peux donc pas l'obtenir.");
183 //vérifier que l'alias n'est pas déja en demande
184 $it = new ValidateIterator ();
185 while($req = $it->next()) {
186 if ($req->type
== "alias" and $req->alias
== $alias . '@' . $globals->mail
->alias_dom
) {
187 $page->trigError("L'alias $alias@{$globals->mail->alias_dom} a déja été demandé.
188 Tu ne peux donc pas l'obtenir pour l'instant.");
193 //Insertion de la demande dans la base, écrase les requêtes précédente
194 $myalias = new AliasReq($user, $alias, $raison, $public);
196 $page->assign('success',$alias);
199 } elseif ($action == 'set' && ($value == 'public' ||
$value == 'private')) {
200 if (!S
::has_xsrf_token()) {
204 if ($value == 'public') {
205 XDB
::execute("UPDATE auth_user_quick SET emails_alias_pub = 'public'
206 WHERE user_id = {?}", $user->id());
208 XDB
::execute("UPDATE auth_user_quick SET emails_alias_pub = 'private'
209 WHERE user_id = {?}", $user->id());
212 $visibility = $value;
215 $page->assign('mail_public', ($visibility == 'public'));
218 function handler_redirect(&$page, $action = null
, $email = null
)
222 require_once 'emails.inc.php';
224 $page->changeTpl('emails/redirect.tpl');
227 $page->assign_by_ref('user', $user);
228 $page->assign('eleve', $user->promo() >= date("Y") - 5);
230 $redirect = new Redirect($user);
232 // FS#703 : $_GET is urldecoded twice, hence
233 // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
234 // Since there can be no spaces in emails, we can fix this with :
235 $email = str_replace(' ', '+', $email);
237 // Apply email redirection change requests.
238 if ($action == 'remove' && $email) {
239 $retour = $redirect->delete_email($email);
242 if ($action == 'active' && $email) {
243 $redirect->modify_one_email($email, true
);
246 if ($action == 'inactive' && $email) {
247 $redirect->modify_one_email($email, false
);
250 if ($action == 'rewrite' && $email) {
251 $rewrite = @func_get_arg
(3);
252 $redirect->modify_one_email_redirect($email, $rewrite);
255 if (Env
::has('emailop')) {
256 S
::assert_xsrf_token();
258 $actifs = Env
::v('emails_actifs', Array());
259 print_r(Env
::v('emails_rewrite'));
260 if (Env
::v('emailop') == "ajouter" && Env
::has('email')) {
261 $retour = $redirect->add_email(Env
::v('email'));
262 } elseif (empty($actifs)) {
263 $retour = ERROR_INACTIVE_REDIRECTION
;
264 } elseif (is_array($actifs)) {
265 $retour = $redirect->modify_email($actifs, Env
::v('emails_rewrite', Array()));
270 case ERROR_INACTIVE_REDIRECTION
:
271 $page->trigError('Tu ne peux pas avoir aucune adresse de redirection active, sinon ton adresse '
272 . $user->forlifeEmail() . ' ne fonctionnerait plus.');
274 case ERROR_INVALID_EMAIL
:
275 $page->trigError('Erreur: l\'email n\'est pas valide.');
277 case ERROR_LOOP_EMAIL
:
278 $page->trigError('Erreur : ' . $user->forlifeEmail()
279 . ' ne doit pas être renvoyé vers lui-même, ni vers son équivalent en '
280 . $globals->mail
->domain2
. ' ni vers polytechnique.edu.');
284 // Fetch the @alias_dom email alias, if any.
288 INNER JOIN virtual_redirect USING(vid)
289 WHERE (redirect={?} OR redirect={?})
290 AND alias LIKE '%@{$globals->mail->alias_dom}'",
291 $user->forlifeEmail(),
292 // TODO: remove this über-ugly hack. The issue is that you need
293 // to remove all @m4x.org addresses in virtual_redirect first.
294 $user->login() . '@' . $globals->mail
->domain2
);
295 $melix = $res->fetchOneCell();
297 list($melix) = explode('@', $melix);
298 $page->assign('melix',$melix);
301 // Fetch existing email aliases.
305 WHERE id={?} AND (type='a_vie' OR type='alias')
306 ORDER BY !FIND_IN_SET('usage',flags), LENGTH(alias)", $user->id());
307 $page->assign('alias', $res->fetchAllAssoc());
308 $page->assign('emails', $redirect->emails
);
310 // Display GoogleApps acount information.
311 require_once 'googleapps.inc.php';
312 $page->assign('googleapps', GoogleAppsAccount
::account_status($user->id()));
315 function handler_antispam(&$page, $statut_filtre = null
)
317 require_once 'emails.inc.php';
318 $wp = new PlWikiPage('Xorg.Antispam');
321 $page->changeTpl('emails/antispam.tpl');
323 $bogo = new Bogo(S
::user());
324 if (isset($statut_filtre)) {
325 $bogo->change($statut_filtre +
0);
327 $page->assign('filtre', $bogo->level());
330 function handler_submit(&$page)
332 $wp = new PlWikiPage('Xorg.Mails');
334 $page->changeTpl('emails/submit_spam.tpl');
336 if (Post
::has('send_email')) {
337 S
::assert_xsrf_token();
339 $upload = PlUpload
::get($_FILES['mail'], S
::user()->login(), 'spam.submit', true
);
341 $page->trigError('Une erreur a été rencontrée lors du transfert du fichier');
344 $mime = $upload->contentType();
345 if ($mime != 'text/x-mail' && $mime != 'message/rfc822') {
347 $page->trigError('Le fichier ne contient pas un email complet');
350 $type = (Post
::v('type') == 'spam' ?
'spam' : 'nonspam');
353 $box = $type . '@' . $globals->mail
->domain
;
354 $mailer = new PlMailer();
355 $mailer->addTo($box);
356 $mailer->setFrom('"' . S
::user()->fullName() . '" <web@' . $globals->mail
->domain
. '>');
357 $mailer->setTxtBody($type . ' soumis par ' . S
::user()->login() . ' via le web');
358 $mailer->addUploadAttachment($upload, $type . '.mail');
360 $page->trigSuccess('Le message a été transmis à ' . $box);
365 function handler_send(&$page)
367 $page->changeTpl('emails/send.tpl');
368 $page->addJsLink('ajax.js');
370 $page->setTitle('Envoyer un email');
372 // action si on recoit un formulaire
373 if (Post
::has('save')) {
374 if (!S
::has_xsrf_token()) {
378 unset($_POST['save']);
379 if (trim(preg_replace('/-- .*/', '', Post
::v('contenu'))) != "") {
380 $_POST['to_contacts'] = explode(';', @$_POST['to_contacts']);
381 $_POST['cc_contacts'] = explode(';', @$_POST['cc_contacts']);
382 $data = serialize($_POST);
383 XDB
::execute("REPLACE INTO email_send_save
384 VALUES ({?}, {?})", S
::i('uid'), $data);
387 } else if (Env
::v('submit') == 'Envoyer') {
388 S
::assert_xsrf_token();
390 function getEmails($aliases)
392 if (!is_array($aliases)) {
395 $rel = Env
::v('contacts');
397 foreach ($aliases as $alias) {
398 $ret[$alias] = $rel[$alias];
400 return join(', ', $ret);
404 foreach ($_FILES as &$file) {
405 if ($file['name'] && !PlUpload
::get($file, S
::user()->login(), 'emails.send', false
)) {
406 $page->trigError(PlUpload
::$lastError);
413 XDB
::execute("DELETE FROM email_send_save
414 WHERE uid = {?}", S
::i('uid'));
416 $to2 = getEmails(Env
::v('to_contacts'));
417 $cc2 = getEmails(Env
::v('cc_contacts'));
418 $txt = str_replace('^M', '', Env
::v('contenu'));
420 $subj = Env
::v('sujet');
421 $from = Env
::v('from');
422 $cc = trim(Env
::v('cc'));
423 $bcc = trim(Env
::v('bcc'));
425 if (empty($to) && empty($cc) && empty($to2) && empty($bcc) && empty($cc2)) {
426 $page->trigError("Indique au moins un destinataire.");
427 $page->assign('uploaded_f', PlUpload
::listFilenames(S
::user()->login(), 'emails.send'));
429 $mymail = new PlMailer();
430 $mymail->setFrom($from);
431 $mymail->setSubject($subj);
432 if (!empty($to)) { $mymail->addTo($to); }
433 if (!empty($cc)) { $mymail->addCc($cc); }
434 if (!empty($bcc)) { $mymail->addBcc($bcc); }
435 if (!empty($to2)) { $mymail->addTo($to2); }
436 if (!empty($cc2)) { $mymail->addCc($cc2); }
437 $files =& PlUpload
::listFiles(S
::user()->login(), 'emails.send');
438 foreach ($files as $name=>&$upload) {
439 $mymail->addUploadAttachment($upload, $name);
441 if (Env
::v('nowiki')) {
442 $mymail->setTxtBody(wordwrap($txt, 78, "\n"));
444 $mymail->setWikiBody($txt);
446 if ($mymail->send()) {
447 $page->trigSuccess("Ton email a bien été envoyé.");
448 $_REQUEST = array('bcc' => S
::user()->bestEmail());
449 PlUpload
::clear(S
::user()->login(), 'emails.send');
451 $page->trigError("Erreur lors de l'envoi du courriel, réessaye.");
452 $page->assign('uploaded_f', PlUpload
::listFilenames(S
::user()->login(), 'emails.send'));
457 $res = XDB
::query("SELECT data
459 WHERE uid = {?}", S
::i('uid'));
460 if ($res->numRows() == 0) {
461 PlUpload
::clear(S
::user()->login(), 'emails.send');
462 $_REQUEST['bcc'] = S
::user()->bestEmail();
464 $data = unserialize($res->fetchOneCell());
465 $_REQUEST = array_merge($_REQUEST, $data);
470 "SELECT u.prenom, u.nom, u.promo, a.alias as forlife
471 FROM auth_user_md5 AS u
472 INNER JOIN contacts AS c ON (u.user_id = c.contact)
473 INNER JOIN aliases AS a ON (u.user_id=a.id AND FIND_IN_SET('bestalias',a.flags))
475 ORDER BY u.nom, u.prenom", S
::v('uid'));
476 $page->assign('contacts', $res->fetchAllAssoc());
477 $page->assign('maxsize', ini_get('upload_max_filesize') . 'o');
478 $page->assign('user', S
::user());
481 function handler_test(&$page, $hruid = null
)
483 require_once 'emails.inc.php';
485 if (!S
::has_xsrf_token()) {
489 // Retrieves the User object for the test email recipient.
490 if (S
::has_perms() && $hruid) {
491 $user = User
::getSilent($hruid);
499 // Sends the test email.
500 $redirect = new Redirect($user);
502 $mailer = new PlMailer('emails/test.mail.tpl');
503 $mailer->assign('email', $user->bestEmail());
504 $mailer->assign('redirects', $redirect->active_emails());
505 $mailer->assign('display_name', $user->displayName());
506 $mailer->assign('sexe', $user->isFemale());
507 $mailer->send($user->isEmailFormatHtml());
511 function handler_rewrite_in(&$page, $mail, $hash)
513 $page->changeTpl('emails/rewrite.tpl');
514 $page->assign('option', 'in');
515 if (empty($mail) ||
empty($hash)) {
518 $pos = strrpos($mail, '_');
519 if ($pos === false
) {
523 $res = XDB
::query("SELECT COUNT(*)
525 WHERE email = {?} AND hash = {?}",
527 $count = intval($res->fetchOneCell());
529 XDB
::query("UPDATE emails
530 SET allow_rewrite = true, hash = NULL
531 WHERE email = {?} AND hash = {?}",
533 $page->trigSuccess("Réécriture activée pour l'adresse " . $mail);
539 function handler_rewrite_out(&$page, $mail, $hash)
541 $page->changeTpl('emails/rewrite.tpl');
542 $page->assign('option', 'out');
543 if (empty($mail) ||
empty($hash)) {
546 $pos = strrpos($mail, '_');
547 if ($pos === false
) {
551 $res = XDB
::query("SELECT COUNT(*)
553 WHERE email = {?} AND hash = {?}",
555 $count = intval($res->fetchOneCell());
558 $res = XDB
::query("SELECT e.email, e.rewrite, a.alias
560 INNER JOIN aliases AS a ON (a.id = e.uid AND a.type = 'a_vie')
561 WHERE e.email = {?} AND e.hash = {?}",
563 XDB
::query("UPDATE emails
564 SET allow_rewrite = false, hash = NULL
565 WHERE email = {?} AND hash = {?}",
567 list($mail, $rewrite, $forlife) = $res->fetchOneRow();
568 $mail = new PlMailer();
569 $mail->setFrom("webmaster@" . $globals->mail
->domain
);
570 $mail->addTo("support@" . $globals->mail
->domain
);
571 $mail->setSubject("Tentative de détournement de correspondance via le rewrite");
572 $mail->setTxtBody("$forlife a tenté un rewrite de $mail vers $rewrite. Cette demande a été rejetée via le web");
574 $page->trigWarning("Un mail d'alerte a été envoyé à l'équipe de " . $globals->core
->sitename
);
580 function handler_imap_in(&$page, $hash = null
, $login = null
)
582 $page->changeTpl('emails/imap_register.tpl');
584 if (!empty($hash) ||
!empty($login)) {
585 $user = User
::getSilent($login);
587 $req = XDB
::query("SELECT 1 FROM newsletter_ins WHERE user_id = {?} AND hash = {?}", $user->id(), $hash);
588 if ($req->numRows() == 0) {
594 require_once('emails.inc.php');
595 $page->assign('ok', false
);
596 if (S
::logged() && (is_null($user) ||
$user->id() == S
::i('uid'))) {
597 $storage = new EmailStorage(S
::user(), 'imap');
598 $storage->activate();
599 $page->assign('ok', true
);
600 $page->assign('prenom', S
::v('prenom'));
601 $page->assign('sexe', S
::v('femme'));
602 } else if (!S
::logged() && $user) {
603 $storage = new EmailStorage($user, 'imap');
604 $storage->activate();
605 $page->assign('ok', true
);
606 $page->assign('prenom', $user->displayName());
607 $page->assign('sexe', $user->isFemale());
611 function handler_broken(&$page, $warn = null
, $email = null
)
613 require_once 'emails.inc.php';
614 $wp = new PlWikiPage('Xorg.PatteCassée');
619 $page->changeTpl('emails/broken.tpl');
621 if ($warn == 'warn' && $email) {
622 S
::assert_xsrf_token();
624 $email = valide_email($email);
625 // vérifications d'usage
626 $sel = XDB
::query("SELECT uid FROM emails WHERE email = {?}", $email);
627 if (($uid = $sel->fetchOneCell())) {
628 $dest = User
::getSilent($uid);
631 $message = "Bonjour !
633 Cet email a été généré automatiquement par le service de patte cassée de
634 Polytechnique.org car un autre utilisateur, " . S
::user()->fullName() . ",
635 nous a signalé qu'en t'envoyant un email, il avait reçu un message d'erreur
636 indiquant que ton adresse de redirection $email
637 ne fonctionnait plus !
639 Nous te suggérons de vérifier cette adresse, et le cas échéant de mettre
640 à jour sur le site <{$globals->baseurl}/emails> tes adresses
643 Pour plus de renseignements sur le service de patte cassée, n'hésite pas à
644 consulter la page <{$globals->baseurl}/emails/broken>.
647 À bientôt sur Polytechnique.org !
648 L'équipe d'administration <support@" . $globals->mail
->domain
. '>';
650 $mail = new PlMailer();
651 $mail->setFrom('"Polytechnique.org" <support@' . $globals->mail
->domain
. '>');
652 $mail->addTo($dest->bestEmail());
653 $mail->setSubject("Une de tes adresse de redirection Polytechnique.org ne marche plus !!");
654 $mail->setTxtBody($message);
656 $page->trigSuccess("Email envoyé !");
658 } elseif (Post
::has('email')) {
659 S
::assert_xsrf_token();
661 $email = valide_email(Post
::v('email'));
663 list(,$fqdn) = explode('@', $email);
664 $fqdn = strtolower($fqdn);
665 if ($fqdn == 'polytechnique.org' ||
$fqdn == 'melix.org' ||
$fqdn == 'm4x.org' ||
$fqdn == 'melix.net') {
666 $page->assign('neuneu', true
);
668 $page->assign('email',$email);
670 "SELECT e1.uid, e1.panne != 0 AS panne,
671 (count(e2.uid) + IF(FIND_IN_SET('googleapps', u.mail_storage), 1, 0)) AS nb_mails,
672 u.nom, u.prenom, u.promo, u.hruid
674 LEFT JOIN emails as e2 ON(e1.uid = e2.uid
675 AND FIND_IN_SET('active', e2.flags)
676 AND e1.email != e2.email)
677 INNER JOIN auth_user_md5 as u ON(e1.uid = u.user_id)
679 GROUP BY e1.uid", $email);
680 if ($x = $sel->fetchOneAssoc()) {
681 // on écrit dans la base que l'adresse est cassée
683 XDB
::execute("UPDATE emails
687 WHERE email = {?}", $email);
689 XDB
::execute("UPDATE emails
691 WHERE email = {?} AND panne_level = 0", $email);
693 $page->assign_by_ref('x', $x);
699 function handler_duplicated(&$page, $action = 'list', $email = null
)
701 $page->changeTpl('emails/duplicated.tpl');
703 $states = array('pending' => 'En attente...',
704 'safe' => 'Pas d\'inquiétude',
705 'unsafe' => 'Recherches en cours',
706 'dangerous' => 'Usurpations par cette adresse');
707 $page->assign('states', $states);
709 if (Post
::has('action')) {
710 S
::assert_xsrf_token();
712 switch (Post
::v('action')) {
714 if (trim(Post
::v('emailN')) != '') {
715 Xdb
::execute('INSERT IGNORE INTO emails_watch (email, state, detection, last, uid, description)
716 VALUES ({?}, {?}, CURDATE(), NOW(), {?}, {?})',
717 trim(Post
::v('emailN')), Post
::v('stateN'), S
::i('uid'), Post
::v('descriptionN'));
722 Xdb
::execute('UPDATE emails_watch
723 SET state = {?}, last = NOW(), uid = {?}, description = {?}
724 WHERE email = {?}', Post
::v('stateN'), S
::i('uid'), Post
::v('descriptionN'), Post
::v('emailN'));
728 if ($action == 'delete' && !is_null($email)) {
729 Xdb
::execute('DELETE FROM emails_watch WHERE email = {?}', $email);
732 if ($action != 'create' && $action != 'edit') {
735 $page->assign('action', $action);
737 if ($action == 'list') {
738 $sql = "SELECT w.email, w.detection, w.state, a.alias AS forlife
739 FROM emails_watch AS w
740 LEFT JOIN emails AS e USING(email)
741 LEFT JOIN aliases AS a ON (a.id = e.uid AND a.type = 'a_vie')
742 ORDER BY w.state, w.email, a.alias";
743 $it = Xdb
::iterRow($sql);
747 while (list($email, $date, $state, $forlife) = $it->next()) {
748 if (count($props) == 0 ||
$props['mail'] != $email) {
749 if (count($props) > 0) {
752 $props = array('mail' => $email,
753 'detection' => $date,
755 'users' => array($forlife));
757 $props['users'][] = $forlife;
760 if (count($props) > 0) {
763 $page->assign('table', $table);
764 } elseif ($action == 'edit') {
765 $sql = "SELECT w.detection, w.state, w.last, w.description,
766 a1.alias AS edit, a2.alias AS forlife
767 FROM emails_watch AS w
768 LEFT JOIN aliases AS a1 ON (a1.id = w.uid AND a1.type = 'a_vie')
769 LEFT JOIN emails AS e ON (w.email = e.email)
770 LEFT JOIN aliases AS a2 ON (a2.id = e.uid AND a2.type = 'a_vie')
773 $it = Xdb
::iterRow($sql, $email);
776 while (list($detection, $state, $last, $description, $edit, $forlife) = $it->next()) {
777 if (count($props) == 0) {
778 $props = array('mail' => $email,
779 'detection' => $detection,
782 'description' => $description,
784 'users' => array($forlife));
786 $props['users'][] = $forlife;
789 $page->assign('doublon', $props);
792 function handler_lost(&$page, $action = 'list', $email = null
)
794 $page->changeTpl('emails/lost.tpl');
796 $page->assign('lost_emails', XDB
::iterator("
797 SELECT u.user_id, u.hruid
798 FROM auth_user_md5 AS u
799 LEFT JOIN emails AS e ON (u.user_id = e.uid AND FIND_IN_SET('active', e.flags))
800 WHERE e.uid IS NULL AND FIND_IN_SET('googleapps', u.mail_storage) = 0 AND
801 u.deces = 0 AND u.perms IN ('user', 'admin', 'disabled')
802 ORDER BY u.promo DESC, u.nom, u.prenom"));
806 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: