Fixes non-referenced use of User, which would have led to a performance impact.
[platal.git] / modules / email.php
CommitLineData
81b5b746 1<?php
2/***************************************************************************
179afa7f 3 * Copyright (C) 2003-2008 Polytechnique.org *
81b5b746 4 * http://opensource.polytechnique.org/ *
5 * *
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. *
10 * *
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. *
15 * *
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 *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22class EmailModule extends PLModule
23{
81b5b746 24 function handlers()
25 {
26 return array(
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),
62ce6356 33 'emails/antispam/submit' => $this->make_hook('submit', AUTH_COOKIE),
9c0a8f8c 34 'emails/test' => $this->make_hook('test', AUTH_COOKIE, 'user', NO_AUTH),
9e570fe0 35
2ee43273
FB
36 'emails/imap/in' => $this->make_hook('imap_in', AUTH_PUBLIC),
37
7727ffc7 38 'admin/emails/duplicated' => $this->make_hook('duplicated', AUTH_MDP, 'admin'),
f141945d 39 'admin/emails/watch' => $this->make_hook('duplicated', AUTH_MDP, 'admin'),
5ff3f06b 40 'admin/emails/lost' => $this->make_hook('lost', AUTH_MDP, 'admin'),
81b5b746 41 );
42 }
43
b7582015 44 function handler_emails(&$page, $action = null, $email = null)
81b5b746 45 {
46 global $globals;
e97e9b8f 47 require_once 'emails.inc.php';
81b5b746 48
49 $page->changeTpl('emails/index.tpl');
46f272fe 50 $page->setTitle('Mes emails');
81b5b746 51
cab08090 52 $uid = S::v('uid');
81b5b746 53
b7582015 54 if ($action == 'best' && $email) {
46504fb3
VZ
55 if (!S::has_xsrf_token()) {
56 return PL_FORBIDDEN;
57 }
58
81b5b746 59 // bestalias is the first bit : 1
60 // there will be maximum 8 bits in flags : 255
08cce2ff 61 XDB::execute("UPDATE aliases SET flags=flags & (255 - 1) WHERE id={?}", $uid);
62 XDB::execute("UPDATE aliases SET flags=flags | 1 WHERE id={?} AND alias={?}",
b7582015 63 $uid, $email);
81b5b746 64 }
65
a7de4ef7 66 // on regarde si on a affaire à un homonyme
81b5b746 67 $sql = "SELECT alias, (type='a_vie') AS a_vie,
68 (alias REGEXP '\\\\.[0-9]{2}$') AS cent_ans,
69 FIND_IN_SET('bestalias',flags) AS best, expire
70 FROM aliases
71 WHERE id = {?} AND type!='homonyme'
72 ORDER BY LENGTH(alias)";
08cce2ff 73 $page->assign('aliases', XDB::iterator($sql, $uid));
81b5b746 74
e97e9b8f
VZ
75 $homonyme = XDB::query("SELECT alias FROM aliases INNER JOIN homonymes ON (id = homonyme_id) WHERE user_id = {?} AND type = 'homonyme'", $uid);
76 $page->assign('homonyme', $homonyme->fetchOneCell());
e1547442 77
aab4661d 78 // Affichage des redirections de l'utilisateur.
e97e9b8f
VZ
79 $redirect = new Redirect($uid);
80 $page->assign('mails', $redirect->active_emails());
81b5b746 81
82 // on regarde si l'utilisateur a un alias et si oui on l'affiche !
cab08090 83 $forlife = S::v('forlife');
08cce2ff 84 $res = XDB::query(
81b5b746 85 "SELECT alias
86 FROM virtual AS v
87 INNER JOIN virtual_redirect AS vr USING(vid)
eaf30d86 88 WHERE (redirect={?} OR redirect={?})
81b5b746 89 AND alias LIKE '%@{$globals->mail->alias_dom}'",
90 $forlife.'@'.$globals->mail->domain, $forlife.'@'.$globals->mail->domain2);
91 $page->assign('melix', $res->fetchOneCell());
81b5b746 92 }
93
94 function handler_alias(&$page, $action = null, $value = null)
95 {
96 require_once 'validations.inc.php';
97
98 global $globals;
99
100 $page->changeTpl('emails/alias.tpl');
46f272fe 101 $page->setTitle('Alias melix.net');
81b5b746 102
cab08090 103 $uid = S::v('uid');
104 $forlife = S::v('forlife');
81b5b746 105
106 $page->assign('demande', AliasReq::get_request($uid));
107
40d428d8
VZ
108 if ($action == 'delete' && $value) {
109 S::assert_xsrf_token();
110
81b5b746 111 //Suppression d'un alias
08cce2ff 112 XDB::execute(
81b5b746 113 'DELETE virtual, virtual_redirect
114 FROM virtual
115 INNER JOIN virtual_redirect USING (vid)
116 WHERE alias = {?} AND (redirect = {?} OR redirect = {?})', $value,
117 $forlife.'@'.$globals->mail->domain, $forlife.'@'.$globals->mail->domain2);
118 }
119
a7de4ef7 120 //Récupération des alias éventuellement existants
08cce2ff 121 $res = XDB::query(
81b5b746 122 "SELECT alias, emails_alias_pub
123 FROM auth_user_quick, virtual
124 INNER JOIN virtual_redirect USING(vid)
125 WHERE ( redirect={?} OR redirect= {?} )
eaf30d86 126 AND alias LIKE '%@{$globals->mail->alias_dom}' AND user_id = {?}",
81b5b746 127 $forlife.'@'.$globals->mail->domain,
cab08090 128 $forlife.'@'.$globals->mail->domain2, S::v('uid'));
81b5b746 129 list($alias, $visibility) = $res->fetchOneRow();
130 $page->assign('actuel', $alias);
131
40d428d8
VZ
132 if ($action == 'ask' && Env::has('alias') && Env::has('raison')) {
133 S::assert_xsrf_token();
81b5b746 134
40d428d8 135 //Si l'utilisateur vient de faire une damande
5e2307dc 136 $alias = Env::v('alias');
137 $raison = Env::v('raison');
138 $public = (Env::v('public', 'off') == 'on')?"public":"private";
81b5b746 139
140 $page->assign('r_alias', $alias);
141 $page->assign('r_raison', $raison);
142 if ($public == 'public') {
143 $page->assign('r_public', true);
144 }
145
a7de4ef7 146 //Quelques vérifications sur l'alias (caractères spéciaux)
81b5b746 147 if (!preg_match( "/^[a-zA-Z0-9\-.]{3,20}$/", $alias)) {
a7d35093
FB
148 $page->trigError("L'adresse demandée n'est pas valide."
149 . " Vérifie qu'elle comporte entre 3 et 20 caractères"
150 . " et qu'elle ne contient que des lettres non accentuées,"
151 . " des chiffres ou les caractères - et .");
fd8f77de 152 return;
81b5b746 153 } else {
a7de4ef7 154 //vérifier que l'alias n'est pas déja pris
08cce2ff 155 $res = XDB::query('SELECT COUNT(*) FROM virtual WHERE alias={?}',
81b5b746 156 $alias.'@'.$globals->mail->alias_dom);
157 if ($res->fetchOneCell() > 0) {
a7d35093 158 $page->trigError("L'alias $alias@{$globals->mail->alias_dom} a déja été attribué.
81b5b746 159 Tu ne peux donc pas l'obtenir.");
fd8f77de 160 return;
81b5b746 161 }
162
a7de4ef7 163 //vérifier que l'alias n'est pas déja en demande
81b5b746 164 $it = new ValidateIterator ();
165 while($req = $it->next()) {
1f07f6c2 166 if ($req->type == "alias" and $req->alias == $alias . '@' . $globals->mail->alias_dom) {
a7d35093 167 $page->trigError("L'alias $alias@{$globals->mail->alias_dom} a déja été demandé.
81b5b746 168 Tu ne peux donc pas l'obtenir pour l'instant.");
fd8f77de 169 return ;
81b5b746 170 }
171 }
172
a7de4ef7 173 //Insertion de la demande dans la base, écrase les requêtes précédente
5daf68f6 174 $myalias = new AliasReq(S::user(), $alias, $raison, $public);
81b5b746 175 $myalias->submit();
176 $page->assign('success',$alias);
fd8f77de 177 return;
81b5b746 178 }
46504fb3
VZ
179 } elseif ($action == 'set' && ($value == 'public' || $value == 'private')) {
180 if (!S::has_xsrf_token()) {
181 return PL_FORBIDDEN;
182 }
183
81b5b746 184 if ($value == 'public') {
08cce2ff 185 XDB::execute("UPDATE auth_user_quick SET emails_alias_pub = 'public'
cab08090 186 WHERE user_id = {?}", S::v('uid'));
81b5b746 187 } else {
08cce2ff 188 XDB::execute("UPDATE auth_user_quick SET emails_alias_pub = 'private'
cab08090 189 WHERE user_id = {?}", S::v('uid'));
81b5b746 190 }
191
192 $visibility = $value;
193 }
194
195 $page->assign('mail_public', ($visibility == 'public'));
81b5b746 196 }
197
198 function handler_redirect(&$page, $action = null, $email = null)
199 {
200 global $globals;
201
202 require_once 'emails.inc.php';
203
204 $page->changeTpl('emails/redirect.tpl');
205
cab08090 206 $uid = S::v('uid');
207 $forlife = S::v('forlife');
81b5b746 208
3b83212e 209 $page->assign('eleve', S::i('promo') >= date("Y") - 5);
210
cab08090 211 $redirect = new Redirect(S::v('uid'));
81b5b746 212
6d6b65bf 213 // FS#703 : $_GET is urldecoded twice, hence
214 // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
215 // Since there can be no spaces in emails, we can fix this with :
216 $email = str_replace(' ', '+', $email);
217
81b5b746 218 if ($action == 'remove' && $email) {
b7582015 219 $retour = $redirect->delete_email($email);
220 $page->assign('retour', $retour);
81b5b746 221 }
e1547442
FB
222
223 if ($action == 'active' && $email) {
224 $redirect->modify_one_email($email, true);
225 }
226
227 if ($action == 'inactive' && $email) {
228 $redirect->modify_one_email($email, false);
229 }
230
231 if ($action == 'rewrite' && $email) {
232 $rewrite = @func_get_arg(3);
233 $redirect->modify_one_email_redirect($email, $rewrite);
234 }
235
40d428d8
VZ
236 if (Env::has('emailop')) {
237 S::assert_xsrf_token();
238
5e2307dc 239 $actifs = Env::v('emails_actifs', Array());
b7582015 240 print_r(Env::v('emails_rewrite'));
5e2307dc 241 if (Env::v('emailop') == "ajouter" && Env::has('email')) {
242 $page->assign('retour', $redirect->add_email(Env::v('email')));
81b5b746 243 } elseif (empty($actifs)) {
244 $page->assign('retour', ERROR_INACTIVE_REDIRECTION);
245 } elseif (is_array($actifs)) {
246 $page->assign('retour', $redirect->modify_email($actifs,
5e2307dc 247 Env::v('emails_rewrite',Array())));
81b5b746 248 }
249 }
250
08cce2ff 251 $res = XDB::query(
81b5b746 252 "SELECT alias
253 FROM virtual
254 INNER JOIN virtual_redirect USING(vid)
255 WHERE (redirect={?} OR redirect={?})
eaf30d86 256 AND alias LIKE '%@{$globals->mail->alias_dom}'",
81b5b746 257 $forlife.'@'.$globals->mail->domain, $forlife.'@'.$globals->mail->domain2);
258 $melix = $res->fetchOneCell();
259 if ($melix) {
260 list($melix) = explode('@', $melix);
261 $page->assign('melix',$melix);
262 }
263
08cce2ff 264 $res = XDB::query(
81b5b746 265 "SELECT alias,expire
266 FROM aliases
267 WHERE id={?} AND (type='a_vie' OR type='alias')
268 ORDER BY !FIND_IN_SET('usage',flags), LENGTH(alias)", $uid);
bb0727ea 269
81b5b746 270 $page->assign('alias', $res->fetchAllAssoc());
271 $page->assign('emails',$redirect->emails);
aab4661d 272
f5c4bf30
VZ
273 require_once 'googleapps.inc.php';
274 $page->assign('googleapps', GoogleAppsAccount::account_status($uid));
81b5b746 275 }
276
b7582015 277 function handler_antispam(&$page, $statut_filtre = null)
81b5b746 278 {
279 require_once 'emails.inc.php';
8f201b69
FB
280 $wp = new PlWikiPage('Xorg.Antispam');
281 $wp->buildCache();
81b5b746 282
283 $page->changeTpl('emails/antispam.tpl');
284
cab08090 285 $bogo = new Bogo(S::v('uid'));
b7582015 286 if (isset($statut_filtre)) {
11ed26e5 287 $bogo->change($statut_filtre + 0);
81b5b746 288 }
289 $page->assign('filtre',$bogo->level());
81b5b746 290 }
291
62ce6356 292 function handler_submit(&$page)
293 {
8f201b69
FB
294 $wp = new PlWikiPage('Xorg.Mails');
295 $wp->buildCache();
62ce6356 296 $page->changeTpl('emails/submit_spam.tpl');
297
40d428d8
VZ
298 if (Post::has('send_email')) {
299 S::assert_xsrf_token();
300
f3df6d38 301 $upload = PlUpload::get($_FILES['mail'], S::user()->login(), 'spam.submit', true);
15603084 302 if (!$upload) {
a7d35093 303 $page->trigError('Une erreur a été rencontrée lors du transfert du fichier');
62ce6356 304 return;
305 }
15603084 306 $mime = $upload->contentType();
62ce6356 307 if ($mime != 'text/x-mail' && $mime != 'message/rfc822') {
15603084 308 $upload->clear();
faefdbb7 309 $page->trigError('Le fichier ne contient pas un email complet');
62ce6356 310 return;
311 }
312 global $globals;
313 $box = Post::v('type') . '@' . $globals->mail->domain;
314 $mailer = new PlMailer();
315 $mailer->addTo($box);
316 $mailer->setFrom('"' . S::v('prenom') . ' ' . S::v('nom') . '" <web@' . $globals->mail->domain . '>');
317 $mailer->setTxtBody(Post::v('type') . ' soumis par ' . S::v('forlife') . ' via le web');
15603084 318 $mailer->addUploadAttachment($upload, Post::v('type') . '.mail');
62ce6356 319 $mailer->send();
a7d35093 320 $page->trigSuccess('Le message a été transmis à ' . $box);
15603084 321 $upload->clear();
62ce6356 322 }
323 }
324
81b5b746 325 function handler_send(&$page)
326 {
327 global $globals;
81b5b746 328 $page->changeTpl('emails/send.tpl');
da419622 329 $page->addJsLink('ajax.js');
81b5b746 330
46f272fe 331 $page->setTitle('Envoyer un email');
81b5b746 332
333 // action si on recoit un formulaire
3360c04f 334 if (Post::has('save')) {
46504fb3
VZ
335 if (!S::has_xsrf_token()) {
336 return PL_FORBIDDEN;
337 }
338
3360c04f
FB
339 unset($_POST['save']);
340 if (trim(preg_replace('/-- .*/', '', Post::v('contenu'))) != "") {
341 $_POST['to_contacts'] = explode(';', @$_POST['to_contacts']);
342 $_POST['cc_contacts'] = explode(';', @$_POST['cc_contacts']);
343 $data = serialize($_POST);
344 XDB::execute("REPLACE INTO email_send_save
345 VALUES ({?}, {?})", S::i('uid'), $data);
346 }
347 exit;
40d428d8
VZ
348 } else if (Env::v('submit') == 'Envoyer') {
349 S::assert_xsrf_token();
350
91a14f73 351 function getEmails($aliases)
352 {
353 if (!is_array($aliases)) {
354 return null;
355 }
356 $rel = Env::v('contacts');
357 $ret = array();
358 foreach ($aliases as $alias) {
359 $ret[$alias] = $rel[$alias];
360 }
361 return join(', ', $ret);
362 }
363
5e68682e 364 $error = false;
da419622 365 foreach ($_FILES as &$file) {
f3df6d38 366 if ($file['name'] && !PlUpload::get($file, S::user()->login(), 'emails.send', false)) {
a7d35093 367 $page->trigError(PlUpload::$lastError);
5e68682e
FB
368 $error = true;
369 break;
da419622 370 }
371 }
372
5e68682e
FB
373 if (!$error) {
374 XDB::execute("DELETE FROM email_send_save
375 WHERE uid = {?}", S::i('uid'));
376
377 $to2 = getEmails(Env::v('to_contacts'));
378 $cc2 = getEmails(Env::v('cc_contacts'));
379 $txt = str_replace('^M', '', Env::v('contenu'));
380 $to = Env::v('to');
381 $subj = Env::v('sujet');
382 $from = Env::v('from');
383 $cc = trim(Env::v('cc'));
384 $bcc = trim(Env::v('bcc'));
385
386 if (empty($to) && empty($cc) && empty($to2) && empty($bcc) && empty($cc2)) {
a7d35093 387 $page->trigError("Indique au moins un destinataire.");
f3df6d38 388 $page->assign('uploaded_f', PlUpload::listFilenames(S::user()->login(), 'emails.send'));
5e68682e
FB
389 } else {
390 $mymail = new PlMailer();
391 $mymail->setFrom($from);
392 $mymail->setSubject($subj);
393 if (!empty($to)) { $mymail->addTo($to); }
394 if (!empty($cc)) { $mymail->addCc($cc); }
395 if (!empty($bcc)) { $mymail->addBcc($bcc); }
396 if (!empty($to2)) { $mymail->addTo($to2); }
397 if (!empty($cc2)) { $mymail->addCc($cc2); }
f3df6d38 398 $files =& PlUpload::listFiles(S::user()->login(), 'emails.send');
5e68682e
FB
399 foreach ($files as $name=>&$upload) {
400 $mymail->addUploadAttachment($upload, $name);
401 }
402 if (Env::v('nowiki')) {
403 $mymail->setTxtBody(wordwrap($txt, 78, "\n"));
404 } else {
405 $mymail->setWikiBody($txt);
406 }
407 if ($mymail->send()) {
faefdbb7 408 $page->trigSuccess("Ton email a bien été envoyé.");
5e68682e 409 $_REQUEST = array('bcc' => S::v('bestalias').'@'.$globals->mail->domain);
f3df6d38 410 PlUpload::clear(S::user()->login(), 'emails.send');
5e68682e 411 } else {
a7d35093 412 $page->trigError("Erreur lors de l'envoi du courriel, réessaye.");
f3df6d38 413 $page->assign('uploaded_f', PlUpload::listFilenames(S::user()->login(), 'emails.send'));
5e68682e 414 }
81b5b746 415 }
416 }
417 } else {
3360c04f
FB
418 $res = XDB::query("SELECT data
419 FROM email_send_save
420 WHERE uid = {?}", S::i('uid'));
421 if ($res->numRows() == 0) {
f3df6d38 422 PlUpload::clear(S::user()->login(), 'emails.send');
3360c04f
FB
423 $_REQUEST['bcc'] = S::v('bestalias').'@'.$globals->mail->domain;
424 } else {
425 $data = unserialize($res->fetchOneCell());
426 $_REQUEST = array_merge($_REQUEST, $data);
427 }
81b5b746 428 }
429
08cce2ff 430 $res = XDB::query(
81b5b746 431 "SELECT u.prenom, u.nom, u.promo, a.alias as forlife
432 FROM auth_user_md5 AS u
433 INNER JOIN contacts AS c ON (u.user_id = c.contact)
434 INNER JOIN aliases AS a ON (u.user_id=a.id AND FIND_IN_SET('bestalias',a.flags))
435 WHERE c.uid = {?}
cab08090 436 ORDER BY u.nom, u.prenom", S::v('uid'));
81b5b746 437 $page->assign('contacts', $res->fetchAllAssoc());
5e68682e 438 $page->assign('maxsize', ini_get('upload_max_filesize') . 'o');
81b5b746 439 }
440
d0c3e04d 441 function handler_test(&$page, $hruid = null)
5ff3f06b
FB
442 {
443 global $globals;
e4ecada4
VZ
444 require_once 'emails.inc.php';
445
46504fb3
VZ
446 if (!S::has_xsrf_token()) {
447 return PL_FORBIDDEN;
448 }
d0c3e04d
VZ
449
450 // Retrieves the User object for the test email recipient.
451 if (S::has_perms() && $hruid) {
452 $user = User::getSilent($hruid);
453 } else {
454 $user = S::user();
455 }
456 if (!$user) {
457 return PL_NOT_FOUND;
5ff3f06b 458 }
e4ecada4 459
d0c3e04d
VZ
460 // Sends the test email.
461 $redirect = new Redirect($user->id());
e4ecada4
VZ
462
463 $mailer = new PlMailer('emails/test.mail.tpl');
d0c3e04d 464 $mailer->assign('email', $user->bestEmail());
e4ecada4 465 $mailer->assign('redirects', $redirect->active_emails());
d0c3e04d
VZ
466 $mailer->assign('display_name', $user->displayName());
467 $mailer->assign('sexe', $user->isFemale());
468 $mailer->send($user->isEmailFormatHtml());
5ff3f06b
FB
469 exit;
470 }
471
2ee43273
FB
472 function handler_imap_in(&$page, $hash = null, $login = null)
473 {
474 $page->changeTpl('emails/imap_register.tpl');
475 $id = null;
476 if (!empty($hash) || !empty($login)) {
e2cea47d 477 $req = XDB::query("SELECT u.prenom, FIND_IN_SET('femme', u.flags) AS sexe, a.id
2ee43273
FB
478 FROM aliases AS a
479 INNER JOIN newsletter_ins AS ni ON (a.id = ni.user_id)
480 INNER JOIN auth_user_md5 AS u ON (u.user_id = a.id)
481 WHERE a.alias = {?} AND ni.hash = {?}", $login, $hash);
e2cea47d 482 list($prenom, $sexe, $id) = $req->fetchOneRow();
2ee43273
FB
483 }
484
485 require_once('emails.inc.php');
486 $page->assign('ok', false);
487 if (S::logged() && (is_null($id) || $id == S::i('uid'))) {
488 $storage = new EmailStorage(S::i('uid'), 'imap');
489 $storage->activate();
490 $page->assign('ok', true);
491 $page->assign('prenom', S::v('prenom'));
e2cea47d 492 $page->assign('sexe', S::v('femme'));
2ee43273
FB
493 } else if (!S::logged() && $id) {
494 $storage = new EmailStorage($id, 'imap');
495 $storage->activate();
496 $page->assign('ok', true);
497 $page->assign('prenom', $prenom);
e2cea47d 498 $page->assign('sexe', $sexe);
2ee43273
FB
499 }
500 }
501
81b5b746 502 function handler_broken(&$page, $warn = null, $email = null)
503 {
504 require_once 'emails.inc.php';
8f201b69
FB
505 $wp = new PlWikiPage('Xorg.PatteCassée');
506 $wp->buildCache();
81b5b746 507
508 global $globals;
509
510 $page->changeTpl('emails/broken.tpl');
511
40d428d8
VZ
512 if ($warn == 'warn' && $email) {
513 S::assert_xsrf_token();
514
81b5b746 515 $email = valide_email($email);
a7de4ef7 516 // vérifications d'usage
08cce2ff 517 $sel = XDB::query(
81b5b746 518 "SELECT e.uid, a.alias
519 FROM emails AS e
81b5b746 520 INNER JOIN aliases AS a ON (e.uid = a.id AND type!='homonyme'
521 AND FIND_IN_SET('bestalias',a.flags))
522 WHERE e.email={?}", $email);
523
524 if (list($uid, $dest) = $sel->fetchOneRow()) {
525 // envoi du mail
526 $message = "Bonjour !
527
faefdbb7 528Cet email a été généré automatiquement par le service de patte cassée de
cab08090 529Polytechnique.org car un autre utilisateur, ".S::v('prenom').' '.S::v('nom').",
faefdbb7 530nous a signalé qu'en t'envoyant un email, il avait reçu un message d'erreur
81b5b746 531indiquant que ton adresse de redirection $email
532ne fonctionnait plus !
533
a7de4ef7 534Nous te suggérons de vérifier cette adresse, et le cas échéant de mettre
535à jour sur le site <{$globals->baseurl}/emails> tes adresses
81b5b746 536de redirection...
537
661e78f7 538Pour plus de renseignements sur le service de patte cassée, n'hésite pas à
2c388954 539consulter la page <{$globals->baseurl}/emails/broken>.
81b5b746 540
541
661e78f7 542À bientôt sur Polytechnique.org !
1d55fe45 543L'équipe d'administration <support@" . $globals->mail->domain . '>';
81b5b746 544
1e33266a 545 $mail = new PlMailer();
1d55fe45 546 $mail->setFrom('"Polytechnique.org" <support@' . $globals->mail->domain . '>');
547 $mail->addTo("$dest@" . $globals->mail->domain);
81b5b746 548 $mail->setSubject("Une de tes adresse de redirection Polytechnique.org ne marche plus !!");
549 $mail->setTxtBody($message);
550 $mail->send();
faefdbb7 551 $page->trigSuccess("Email envoyé !");
81b5b746 552 }
40d428d8
VZ
553 } elseif (Post::has('email')) {
554 S::assert_xsrf_token();
555
5e2307dc 556 $email = valide_email(Post::v('email'));
81b5b746 557
558 list(,$fqdn) = explode('@', $email);
559 $fqdn = strtolower($fqdn);
40d428d8 560 if ($fqdn == 'polytechnique.org' || $fqdn == 'melix.org' || $fqdn == 'm4x.org' || $fqdn == 'melix.net') {
81b5b746 561 $page->assign('neuneu', true);
562 } else {
563 $page->assign('email',$email);
08cce2ff 564 $sel = XDB::query(
b1797f70
VZ
565 "SELECT e1.uid, e1.panne != 0 AS panne,
566 (count(e2.uid) + IF(FIND_IN_SET('googleapps', u.mail_storage), 1, 0)) AS nb_mails,
4b9ba601 567 u.nom, u.prenom, u.promo, a.alias AS forlife
81b5b746 568 FROM emails as e1
eaf30d86 569 LEFT JOIN emails as e2 ON(e1.uid = e2.uid
81b5b746 570 AND FIND_IN_SET('active', e2.flags)
571 AND e1.email != e2.email)
572 INNER JOIN auth_user_md5 as u ON(e1.uid = u.user_id)
4b9ba601 573 INNER JOIN aliases AS a ON (a.id = e1.uid AND a.type = 'a_vie')
81b5b746 574 WHERE e1.email = {?}
575 GROUP BY e1.uid", $email);
576 if ($x = $sel->fetchOneAssoc()) {
a7de4ef7 577 // on écrit dans la base que l'adresse est cassée
81b5b746 578 if (!$x['panne']) {
74938c82 579 XDB::execute("UPDATE emails
580 SET panne=NOW(),
581 last=NOW(),
582 panne_level = 1
583 WHERE email = {?}", $email);
584 } else {
585 XDB::execute("UPDATE emails
586 SET panne_level = 1
4b9ba601 587 WHERE email = {?} AND panne_level = 0", $email);
81b5b746 588 }
589 $page->assign_by_ref('x', $x);
590 }
591 }
592 }
593 }
9e570fe0 594
595 function handler_duplicated(&$page, $action = 'list', $email = null)
596 {
597 $page->changeTpl('emails/duplicated.tpl');
598
599 $states = array('pending' => 'En attente...',
a7de4ef7 600 'safe' => 'Pas d\'inquiétude',
9e570fe0 601 'unsafe' => 'Recherches en cours',
602 'dangerous' => 'Usurpations par cette adresse');
603 $page->assign('states', $states);
604
40d428d8
VZ
605 if (Post::has('action')) {
606 S::assert_xsrf_token();
46504fb3 607 }
9e570fe0 608 switch (Post::v('action')) {
46504fb3 609 case 'create':
9e570fe0 610 if (trim(Post::v('emailN')) != '') {
611 Xdb::execute('INSERT IGNORE INTO emails_watch (email, state, detection, last, uid, description)
612 VALUES ({?}, {?}, CURDATE(), NOW(), {?}, {?})',
613 trim(Post::v('emailN')), Post::v('stateN'), S::i('uid'), Post::v('descriptionN'));
614 };
615 break;
616
46504fb3 617 case 'edit':
9e570fe0 618 Xdb::execute('UPDATE emails_watch
619 SET state = {?}, last = NOW(), uid = {?}, description = {?}
620 WHERE email = {?}', Post::v('stateN'), S::i('uid'), Post::v('descriptionN'), Post::v('emailN'));
621 break;
622
46504fb3 623 default:
9e570fe0 624 if ($action == 'delete' && !is_null($email)) {
625 Xdb::execute('DELETE FROM emails_watch WHERE email = {?}', $email);
626 }
627 }
628 if ($action != 'create' && $action != 'edit') {
629 $action = 'list';
630 }
631 $page->assign('action', $action);
632
633 if ($action == 'list') {
634 $sql = "SELECT w.email, w.detection, w.state, a.alias AS forlife
635 FROM emails_watch AS w
ca6d07f4 636 LEFT JOIN emails AS e USING(email)
637 LEFT JOIN aliases AS a ON (a.id = e.uid AND a.type = 'a_vie')
9e570fe0 638 ORDER BY w.state, w.email, a.alias";
639 $it = Xdb::iterRow($sql);
640
641 $table = array();
642 $props = array();
643 while (list($email, $date, $state, $forlife) = $it->next()) {
644 if (count($props) == 0 || $props['mail'] != $email) {
645 if (count($props) > 0) {
646 $table[] = $props;
647 }
648 $props = array('mail' => $email,
649 'detection' => $date,
650 'state' => $state,
651 'users' => array($forlife));
652 } else {
653 $props['users'][] = $forlife;
654 }
655 }
656 if (count($props) > 0) {
657 $table[] = $props;
658 }
659 $page->assign('table', $table);
660 } elseif ($action == 'edit') {
661 $sql = "SELECT w.detection, w.state, w.last, w.description,
662 a1.alias AS edit, a2.alias AS forlife
663 FROM emails_watch AS w
eaf30d86 664 LEFT JOIN aliases AS a1 ON (a1.id = w.uid AND a1.type = 'a_vie')
9615c895 665 LEFT JOIN emails AS e ON (w.email = e.email)
ca6d07f4 666 LEFT JOIN aliases AS a2 ON (a2.id = e.uid AND a2.type = 'a_vie')
9e570fe0 667 WHERE w.email = {?}
668 ORDER BY a2.alias";
669 $it = Xdb::iterRow($sql, $email);
670
671 $props = array();
672 while (list($detection, $state, $last, $description, $edit, $forlife) = $it->next()) {
673 if (count($props) == 0) {
674 $props = array('mail' => $email,
675 'detection' => $detection,
676 'state' => $state,
677 'last' => $last,
678 'description' => $description,
679 'edit' => $edit,
680 'users' => array($forlife));
681 } else {
682 $props['users'][] = $forlife;
683 }
684 }
685 $page->assign('doublon', $props);
686 }
687 }
7727ffc7 688 function handler_lost(&$page, $action = 'list', $email = null)
689 {
690 $page->changeTpl('emails/lost.tpl');
eaf30d86 691
7727ffc7 692 $page->assign('lost_emails', XDB::iterator('
0e5ec860
VZ
693 SELECT u.user_id, a.alias
694 FROM auth_user_md5 AS u
695 INNER JOIN aliases AS a ON (a.id = u.user_id AND a.type = "a_vie")
696 LEFT JOIN emails AS e ON (u.user_id=e.uid AND FIND_IN_SET("active",e.flags))
697 WHERE e.uid IS NULL AND
698 FIND_IN_SET("googleapps", u.mail_storage) = 0 AND
699 u.deces = 0
700 ORDER BY u.promo DESC, u.nom, u.prenom'));
7727ffc7 701 }
81b5b746 702}
703
a7de4ef7 704// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
81b5b746 705?>