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(), $user->m4xForlifeEmail());
135 // Fetch existing @alias_dom aliases.
136 $alias = $user->emailAlias();
137 $visibility = $user->hasProfile() && $user->profile()->alias_pub
;
139 if ($action == 'ask' && Env
::has('alias') && Env
::has('raison')) {
140 S
::assert_xsrf_token();
142 //Si l'utilisateur vient de faire une damande
143 $alias = Env
::v('alias');
144 $raison = Env
::v('raison');
145 $public = (Env
::v('public', 'off') == 'on')?
"public":"private";
147 $page->assign('r_alias', $alias);
148 $page->assign('r_raison', $raison);
149 if ($public == 'public') {
150 $page->assign('r_public', true
);
153 //Quelques vérifications sur l'alias (caractères spéciaux)
154 if (!preg_match("/^[a-zA-Z0-9\-.]{3,20}$/", $alias)) {
155 $page->trigError("L'adresse demandée n'est pas valide."
156 . " Vérifie qu'elle comporte entre 3 et 20 caractères"
157 . " et qu'elle ne contient que des lettres non accentuées,"
158 . " des chiffres ou les caractères - et .");
161 $alias_mail = $alias.'@'.$globals->mail
->alias_dom
;
163 //vérifier que l'alias n'est pas déja pris
164 $res = XDB
::query('SELECT COUNT(*)
168 if ($res->fetchOneCell() > 0) {
169 $page->trigError("L'alias $alias_mail a déja été attribué.
170 Tu ne peux donc pas l'obtenir.");
174 //vérifier que l'alias n'est pas déja en demande
175 $it = new ValidateIterator();
176 while($req = $it->next()) {
177 if ($req->type
== 'alias' and $req->alias
== $alias_mail) {
178 $page->trigError("L'alias $alias_mail a déja été demandé.
179 Tu ne peux donc pas l'obtenir pour l'instant.");
184 //Insertion de la demande dans la base, écrase les requêtes précédente
185 $myalias = new AliasReq($user, $alias, $raison, $public);
187 $page->assign('success',$alias);
190 } elseif ($action == 'set' && ($value == 'public' ||
$value == 'private')) {
191 if (!S
::has_xsrf_token()) {
195 if ($user->hasProfile()) {
196 XDB
::execute("UPDATE profiles
199 $value, $user->profile()->id());
201 $visibility = ($value == 'public');
204 $page->assign('actuel', $alias);
205 $page->assign('user', $user);
206 $page->assign('mail_public', $visibility);
209 function handler_redirect(&$page, $action = null
, $email = null
)
213 require_once 'emails.inc.php';
215 $page->changeTpl('emails/redirect.tpl');
218 $page->assign_by_ref('user', $user);
219 $page->assign('eleve', $user->promo() >= date("Y") - 5);
221 $redirect = new Redirect($user);
223 // FS#703 : $_GET is urldecoded twice, hence
224 // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
225 // Since there can be no spaces in emails, we can fix this with :
226 $email = str_replace(' ', '+', $email);
228 // Apply email redirection change requests.
229 if ($action == 'remove' && $email) {
230 $retour = $redirect->delete_email($email);
233 if ($action == 'active' && $email) {
234 $redirect->modify_one_email($email, true
);
237 if ($action == 'inactive' && $email) {
238 $redirect->modify_one_email($email, false
);
241 if ($action == 'rewrite' && $email) {
242 $rewrite = @func_get_arg
(3);
243 $redirect->modify_one_email_redirect($email, $rewrite);
246 if (Env
::has('emailop')) {
247 S
::assert_xsrf_token();
249 $actifs = Env
::v('emails_actifs', Array());
250 print_r(Env
::v('emails_rewrite'));
251 if (Env
::v('emailop') == "ajouter" && Env
::has('email')) {
252 $new_email = Env
::v('email');
253 if ($new_email == "new@example.org") {
254 $new_email = Env
::v('email_new');
256 $retour = $redirect->add_email($new_email);
257 if ($retour == ERROR_INVALID_EMAIL
) {
258 $page->assign('email', $new_email);
260 $page->assign('retour', $retour);
261 } elseif (empty($actifs)) {
262 $retour = ERROR_INACTIVE_REDIRECTION
;
263 } elseif (is_array($actifs)) {
264 $retour = $redirect->modify_email($actifs, Env
::v('emails_rewrite', Array()));
269 case ERROR_INACTIVE_REDIRECTION
:
270 $page->trigError('Tu ne peux pas avoir aucune adresse de redirection active, sinon ton adresse '
271 . $user->forlifeEmail() . ' ne fonctionnerait plus.');
273 case ERROR_INVALID_EMAIL
:
274 $page->trigError('Erreur: l\'email n\'est pas valide.');
276 case ERROR_LOOP_EMAIL
:
277 $page->trigError('Erreur : ' . $user->forlifeEmail()
278 . ' ne doit pas être renvoyé vers lui-même, ni vers son équivalent en '
279 . $globals->mail
->domain2
. ' ni vers polytechnique.edu.');
283 // Fetch the @alias_dom email alias, if any.
287 INNER JOIN virtual_redirect USING(vid)
288 WHERE (redirect={?} OR redirect={?})
289 AND alias LIKE '%@{$globals->mail->alias_dom}'",
290 $user->forlifeEmail(),
291 // TODO: remove this über-ugly hack. The issue is that you need
292 // to remove all @m4x.org addresses in virtual_redirect first.
293 $user->login() . '@' . $globals->mail
->domain2
);
294 $melix = $res->fetchOneCell();
296 list($melix) = explode('@', $melix);
297 $page->assign('melix',$melix);
300 // Fetch existing email aliases.
304 WHERE id={?} AND (type='a_vie' OR type='alias')
305 ORDER BY !FIND_IN_SET('usage',flags), LENGTH(alias)", $user->id());
306 $page->assign('alias', $res->fetchAllAssoc());
307 $page->assign('emails', $redirect->emails
);
309 // Display GoogleApps acount information.
310 require_once 'googleapps.inc.php';
311 $page->assign('googleapps', GoogleAppsAccount
::account_status($user->id()));
313 require_once 'emails.combobox.inc.php';
314 fill_email_combobox($page);
317 function handler_antispam(&$page, $statut_filtre = null
)
319 require_once 'emails.inc.php';
320 $wp = new PlWikiPage('Xorg.Antispam');
323 $page->changeTpl('emails/antispam.tpl');
325 $bogo = new Bogo(S
::user());
326 if (isset($statut_filtre)) {
327 $bogo->change($statut_filtre +
0);
329 $page->assign('filtre', $bogo->level());
332 function handler_submit(&$page)
334 $wp = new PlWikiPage('Xorg.Mails');
336 $page->changeTpl('emails/submit_spam.tpl');
338 if (Post
::has('send_email')) {
339 S
::assert_xsrf_token();
341 $upload = PlUpload
::get($_FILES['mail'], S
::user()->login(), 'spam.submit', true
);
343 $page->trigError('Une erreur a été rencontrée lors du transfert du fichier');
346 $mime = $upload->contentType();
347 if ($mime != 'text/x-mail' && $mime != 'message/rfc822') {
349 $page->trigError('Le fichier ne contient pas un email complet');
352 $type = (Post
::v('type') == 'spam' ?
'spam' : 'nonspam');
355 $box = $type . '@' . $globals->mail
->domain
;
356 $mailer = new PlMailer();
357 $mailer->addTo($box);
358 $mailer->setFrom('"' . S
::user()->fullName() . '" <web@' . $globals->mail
->domain
. '>');
359 $mailer->setTxtBody($type . ' soumis par ' . S
::user()->login() . ' via le web');
360 $mailer->addUploadAttachment($upload, $type . '.mail');
362 $page->trigSuccess('Le message a été transmis à ' . $box);
367 function handler_send(&$page)
369 $page->changeTpl('emails/send.tpl');
370 $page->addJsLink('ajax.js');
372 $page->setTitle('Envoyer un email');
374 // action si on recoit un formulaire
375 if (Post
::has('save')) {
376 if (!S
::has_xsrf_token()) {
380 unset($_POST['save']);
381 if (trim(preg_replace('/-- .*/', '', Post
::v('contenu'))) != "") {
382 $_POST['to_contacts'] = explode(';', @$_POST['to_contacts']);
383 $_POST['cc_contacts'] = explode(';', @$_POST['cc_contacts']);
384 $data = serialize($_POST);
385 XDB
::execute("REPLACE INTO email_send_save
386 VALUES ({?}, {?})", S
::i('uid'), $data);
389 } else if (Env
::v('submit') == 'Envoyer') {
390 S
::assert_xsrf_token();
392 function getEmails($aliases)
394 if (!is_array($aliases)) {
397 $rel = Env
::v('contacts');
399 foreach ($aliases as $alias) {
400 $ret[$alias] = $rel[$alias];
402 return join(', ', $ret);
406 foreach ($_FILES as &$file) {
407 if ($file['name'] && !PlUpload
::get($file, S
::user()->login(), 'emails.send', false
)) {
408 $page->trigError(PlUpload
::$lastError);
415 XDB
::execute("DELETE FROM email_send_save
416 WHERE uid = {?}", S
::i('uid'));
418 $to2 = getEmails(Env
::v('to_contacts'));
419 $cc2 = getEmails(Env
::v('cc_contacts'));
420 $txt = str_replace('^M', '', Env
::v('contenu'));
422 $subj = Env
::v('sujet');
423 $from = Env
::v('from');
424 $cc = trim(Env
::v('cc'));
425 $bcc = trim(Env
::v('bcc'));
427 if (empty($to) && empty($cc) && empty($to2) && empty($bcc) && empty($cc2)) {
428 $page->trigError("Indique au moins un destinataire.");
429 $page->assign('uploaded_f', PlUpload
::listFilenames(S
::user()->login(), 'emails.send'));
431 $mymail = new PlMailer();
432 $mymail->setFrom($from);
433 $mymail->setSubject($subj);
434 if (!empty($to)) { $mymail->addTo($to); }
435 if (!empty($cc)) { $mymail->addCc($cc); }
436 if (!empty($bcc)) { $mymail->addBcc($bcc); }
437 if (!empty($to2)) { $mymail->addTo($to2); }
438 if (!empty($cc2)) { $mymail->addCc($cc2); }
439 $files =& PlUpload
::listFiles(S
::user()->login(), 'emails.send');
440 foreach ($files as $name=>&$upload) {
441 $mymail->addUploadAttachment($upload, $name);
443 if (Env
::v('nowiki')) {
444 $mymail->setTxtBody(wordwrap($txt, 78, "\n"));
446 $mymail->setWikiBody($txt);
448 if ($mymail->send()) {
449 $page->trigSuccess("Ton email a bien été envoyé.");
450 $_REQUEST = array('bcc' => S
::user()->bestEmail());
451 PlUpload
::clear(S
::user()->login(), 'emails.send');
453 $page->trigError("Erreur lors de l'envoi du courriel, réessaye.");
454 $page->assign('uploaded_f', PlUpload
::listFilenames(S
::user()->login(), 'emails.send'));
459 $res = XDB
::query("SELECT data
461 WHERE uid = {?}", S
::i('uid'));
462 if ($res->numRows() == 0) {
463 PlUpload
::clear(S
::user()->login(), 'emails.send');
464 $_REQUEST['bcc'] = S
::user()->bestEmail();
466 $data = unserialize($res->fetchOneCell());
467 $_REQUEST = array_merge($_REQUEST, $data);
472 "SELECT ac.full_name, a.alias as forlife
474 INNER JOIN contacts AS c ON (ac.uid = c.contact)
475 INNER JOIN aliases AS a ON (ac.uid = a.id AND FIND_IN_SET('bestalias', a.flags))
477 ORDER BY ac.full_name", S
::i('uid'));
478 $page->assign('contacts', $res->fetchAllAssoc());
479 $page->assign('maxsize', ini_get('upload_max_filesize') . 'o');
480 $page->assign('user', S
::user());
483 function handler_test(&$page, $hruid = null
)
485 require_once 'emails.inc.php';
487 if (!S
::has_xsrf_token()) {
491 // Retrieves the User object for the test email recipient.
492 if (S
::has_perms() && $hruid) {
493 $user = User
::getSilent($hruid);
501 // Sends the test email.
502 $redirect = new Redirect($user);
504 $mailer = new PlMailer('emails/test.mail.tpl');
505 $mailer->assign('email', $user->bestEmail());
506 $mailer->assign('redirects', $redirect->active_emails());
507 $mailer->assign('display_name', $user->displayName());
508 $mailer->assign('sexe', $user->isFemale());
509 $mailer->send($user->isEmailFormatHtml());
513 function handler_rewrite_in(&$page, $mail, $hash)
515 $page->changeTpl('emails/rewrite.tpl');
516 $page->assign('option', 'in');
517 if (empty($mail) ||
empty($hash)) {
520 $pos = strrpos($mail, '_');
521 if ($pos === false
) {
525 $res = XDB
::query("SELECT COUNT(*)
527 WHERE email = {?} AND hash = {?}",
529 $count = intval($res->fetchOneCell());
531 XDB
::query("UPDATE emails
532 SET allow_rewrite = true, hash = NULL
533 WHERE email = {?} AND hash = {?}",
535 $page->trigSuccess("Réécriture activée pour l'adresse " . $mail);
541 function handler_rewrite_out(&$page, $mail, $hash)
543 $page->changeTpl('emails/rewrite.tpl');
544 $page->assign('option', 'out');
545 if (empty($mail) ||
empty($hash)) {
548 $pos = strrpos($mail, '_');
549 if ($pos === false
) {
553 $res = XDB
::query("SELECT COUNT(*)
555 WHERE email = {?} AND hash = {?}",
557 $count = intval($res->fetchOneCell());
560 $res = XDB
::query("SELECT e.email, e.rewrite, a.alias
562 INNER JOIN aliases AS a ON (a.id = e.uid AND a.type = 'a_vie')
563 WHERE e.email = {?} AND e.hash = {?}",
565 XDB
::query("UPDATE emails
566 SET allow_rewrite = false, hash = NULL
567 WHERE email = {?} AND hash = {?}",
569 list($mail, $rewrite, $forlife) = $res->fetchOneRow();
570 $mail = new PlMailer();
571 $mail->setFrom("webmaster@" . $globals->mail
->domain
);
572 $mail->addTo("support@" . $globals->mail
->domain
);
573 $mail->setSubject("Tentative de détournement de correspondance via le rewrite");
574 $mail->setTxtBody("$forlife a tenté un rewrite de $mail vers $rewrite. Cette demande a été rejetée via le web");
576 $page->trigWarning("Un mail d'alerte a été envoyé à l'équipe de " . $globals->core
->sitename
);
582 function handler_imap_in(&$page, $hash = null
, $login = null
)
584 $page->changeTpl('emails/imap_register.tpl');
586 if (!empty($hash) ||
!empty($login)) {
587 $user = User
::getSilent($login);
589 $req = XDB
::query("SELECT 1 FROM newsletter_ins WHERE user_id = {?} AND hash = {?}", $user->id(), $hash);
590 if ($req->numRows() == 0) {
596 require_once('emails.inc.php');
597 $page->assign('ok', false
);
598 if (S
::logged() && (is_null($user) ||
$user->id() == S
::i('uid'))) {
599 $storage = new EmailStorage(S
::user(), 'imap');
600 $storage->activate();
601 $page->assign('ok', true
);
602 $page->assign('prenom', S
::v('prenom'));
603 $page->assign('sexe', S
::v('femme'));
604 } else if (!S
::logged() && $user) {
605 $storage = new EmailStorage($user, 'imap');
606 $storage->activate();
607 $page->assign('ok', true
);
608 $page->assign('prenom', $user->displayName());
609 $page->assign('sexe', $user->isFemale());
613 function handler_broken(&$page, $warn = null
, $email = null
)
615 require_once 'emails.inc.php';
616 $wp = new PlWikiPage('Xorg.PatteCassée');
621 $page->changeTpl('emails/broken.tpl');
623 if ($warn == 'warn' && $email) {
624 S
::assert_xsrf_token();
626 $email = valide_email($email);
627 // vérifications d'usage
628 $sel = XDB
::query("SELECT uid FROM emails WHERE email = {?}", $email);
629 if (($uid = $sel->fetchOneCell())) {
630 $dest = User
::getSilent($uid);
633 $message = "Bonjour !
635 Cet email a été généré automatiquement par le service de patte cassée de
636 Polytechnique.org car un autre utilisateur, " . S
::user()->fullName() . ",
637 nous a signalé qu'en t'envoyant un email, il avait reçu un message d'erreur
638 indiquant que ton adresse de redirection $email
639 ne fonctionnait plus !
641 Nous te suggérons de vérifier cette adresse, et le cas échéant de mettre
642 à jour sur le site <{$globals->baseurl}/emails> tes adresses
645 Pour plus de renseignements sur le service de patte cassée, n'hésite pas à
646 consulter la page <{$globals->baseurl}/emails/broken>.
649 À bientôt sur Polytechnique.org !
650 L'équipe d'administration <support@" . $globals->mail
->domain
. '>';
652 $mail = new PlMailer();
653 $mail->setFrom('"Polytechnique.org" <support@' . $globals->mail
->domain
. '>');
654 $mail->addTo($dest->bestEmail());
655 $mail->setSubject("Une de tes adresse de redirection Polytechnique.org ne marche plus !!");
656 $mail->setTxtBody($message);
658 $page->trigSuccess("Email envoyé !");
660 } elseif (Post
::has('email')) {
661 S
::assert_xsrf_token();
663 $email = valide_email(Post
::v('email'));
665 list(,$fqdn) = explode('@', $email);
666 $fqdn = strtolower($fqdn);
667 if ($fqdn == 'polytechnique.org' ||
$fqdn == 'melix.org' ||
$fqdn == 'm4x.org' ||
$fqdn == 'melix.net') {
668 $page->assign('neuneu', true
);
670 $page->assign('email',$email);
672 "SELECT e1.uid, e1.panne != 0 AS panne,
673 (count(e2.uid) + IF(FIND_IN_SET('googleapps', u.mail_storage), 1, 0)) AS nb_mails,
674 u.nom, u.prenom, u.promo, u.hruid
676 LEFT JOIN emails as e2 ON(e1.uid = e2.uid
677 AND FIND_IN_SET('active', e2.flags)
678 AND e1.email != e2.email)
679 INNER JOIN auth_user_md5 as u ON(e1.uid = u.user_id)
681 GROUP BY e1.uid", $email);
682 if ($x = $sel->fetchOneAssoc()) {
683 // on écrit dans la base que l'adresse est cassée
685 XDB
::execute("UPDATE emails
689 WHERE email = {?}", $email);
691 XDB
::execute("UPDATE emails
693 WHERE email = {?} AND panne_level = 0", $email);
695 $page->assign_by_ref('x', $x);
701 function handler_duplicated(&$page, $action = 'list', $email = null
)
703 $page->changeTpl('emails/duplicated.tpl');
705 $states = array('pending' => 'En attente...',
706 'safe' => 'Pas d\'inquiétude',
707 'unsafe' => 'Recherches en cours',
708 'dangerous' => 'Usurpations par cette adresse');
709 $page->assign('states', $states);
711 if (Post
::has('action')) {
712 S
::assert_xsrf_token();
714 switch (Post
::v('action')) {
716 if (trim(Post
::v('emailN')) != '') {
717 Xdb
::execute('INSERT IGNORE INTO emails_watch (email, state, detection, last, uid, description)
718 VALUES ({?}, {?}, CURDATE(), NOW(), {?}, {?})',
719 trim(Post
::v('emailN')), Post
::v('stateN'), S
::i('uid'), Post
::v('descriptionN'));
724 Xdb
::execute('UPDATE emails_watch
725 SET state = {?}, last = NOW(), uid = {?}, description = {?}
726 WHERE email = {?}', Post
::v('stateN'), S
::i('uid'), Post
::v('descriptionN'), Post
::v('emailN'));
730 if ($action == 'delete' && !is_null($email)) {
731 Xdb
::execute('DELETE FROM emails_watch WHERE email = {?}', $email);
734 if ($action != 'create' && $action != 'edit') {
737 $page->assign('action', $action);
739 if ($action == 'list') {
740 $sql = "SELECT w.email, w.detection, w.state, a.alias AS forlife
741 FROM emails_watch AS w
742 LEFT JOIN emails AS e USING(email)
743 LEFT JOIN aliases AS a ON (a.id = e.uid AND a.type = 'a_vie')
744 ORDER BY w.state, w.email, a.alias";
745 $it = Xdb
::iterRow($sql);
749 while (list($email, $date, $state, $forlife) = $it->next()) {
750 if (count($props) == 0 ||
$props['mail'] != $email) {
751 if (count($props) > 0) {
754 $props = array('mail' => $email,
755 'detection' => $date,
757 'users' => array($forlife));
759 $props['users'][] = $forlife;
762 if (count($props) > 0) {
765 $page->assign('table', $table);
766 } elseif ($action == 'edit') {
767 $sql = "SELECT w.detection, w.state, w.last, w.description,
768 a1.alias AS edit, a2.alias AS forlife
769 FROM emails_watch AS w
770 LEFT JOIN aliases AS a1 ON (a1.id = w.uid AND a1.type = 'a_vie')
771 LEFT JOIN emails AS e ON (w.email = e.email)
772 LEFT JOIN aliases AS a2 ON (a2.id = e.uid AND a2.type = 'a_vie')
775 $it = Xdb
::iterRow($sql, $email);
778 while (list($detection, $state, $last, $description, $edit, $forlife) = $it->next()) {
779 if (count($props) == 0) {
780 $props = array('mail' => $email,
781 'detection' => $detection,
784 'description' => $description,
786 'users' => array($forlife));
788 $props['users'][] = $forlife;
791 $page->assign('doublon', $props);
794 function handler_lost(&$page, $action = 'list', $email = null
)
796 $page->changeTpl('emails/lost.tpl');
798 $page->assign('lost_emails', XDB
::iterator("
799 SELECT u.user_id, u.hruid
800 FROM auth_user_md5 AS u
801 LEFT JOIN emails AS e ON (u.user_id = e.uid AND FIND_IN_SET('active', e.flags))
802 WHERE e.uid IS NULL AND FIND_IN_SET('googleapps', u.mail_storage) = 0 AND
803 u.deces = 0 AND u.perms IN ('user', 'admin', 'disabled')
804 ORDER BY u.promo DESC, u.nom, u.prenom"));
808 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: