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