Commit | Line | Data |
---|---|---|
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 | ||
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), |
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'); | |
50 | $page->assign('xorg_title','Polytechnique.org - Mes emails'); | |
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'); | |
101 | $page->assign('xorg_title','Polytechnique.org - Alias melix.net'); | |
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 |
81b5b746 | 174 | $myalias = new AliasReq($uid, $alias, $raison, $public); |
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')) { |
b715c1e1 | 242 | $new_email = Env::v('email'); |
6ea6d9c1 | 243 | if ($new_email == "new@example.org") { |
b715c1e1 SJ |
244 | $new_email = Env::v('email_new'); |
245 | } | |
246 | $retour = $redirect->add_email($new_email); | |
247 | if ($retour == ERROR_INVALID_EMAIL) { | |
248 | $page->assign('email', $new_email); | |
249 | } | |
250 | $page->assign('retour', $retour); | |
81b5b746 | 251 | } elseif (empty($actifs)) { |
252 | $page->assign('retour', ERROR_INACTIVE_REDIRECTION); | |
253 | } elseif (is_array($actifs)) { | |
254 | $page->assign('retour', $redirect->modify_email($actifs, | |
5e2307dc | 255 | Env::v('emails_rewrite',Array()))); |
81b5b746 | 256 | } |
257 | } | |
258 | ||
08cce2ff | 259 | $res = XDB::query( |
81b5b746 | 260 | "SELECT alias |
261 | FROM virtual | |
262 | INNER JOIN virtual_redirect USING(vid) | |
263 | WHERE (redirect={?} OR redirect={?}) | |
eaf30d86 | 264 | AND alias LIKE '%@{$globals->mail->alias_dom}'", |
81b5b746 | 265 | $forlife.'@'.$globals->mail->domain, $forlife.'@'.$globals->mail->domain2); |
266 | $melix = $res->fetchOneCell(); | |
267 | if ($melix) { | |
268 | list($melix) = explode('@', $melix); | |
269 | $page->assign('melix',$melix); | |
270 | } | |
271 | ||
08cce2ff | 272 | $res = XDB::query( |
81b5b746 | 273 | "SELECT alias,expire |
274 | FROM aliases | |
275 | WHERE id={?} AND (type='a_vie' OR type='alias') | |
276 | ORDER BY !FIND_IN_SET('usage',flags), LENGTH(alias)", $uid); | |
bb0727ea | 277 | |
81b5b746 | 278 | $page->assign('alias', $res->fetchAllAssoc()); |
279 | $page->assign('emails',$redirect->emails); | |
aab4661d | 280 | |
f5c4bf30 VZ |
281 | require_once 'googleapps.inc.php'; |
282 | $page->assign('googleapps', GoogleAppsAccount::account_status($uid)); | |
b715c1e1 SJ |
283 | |
284 | require_once 'emails.combobox.inc.php'; | |
285 | fill_email_combobox($page); | |
81b5b746 | 286 | } |
287 | ||
b7582015 | 288 | function handler_antispam(&$page, $statut_filtre = null) |
81b5b746 | 289 | { |
290 | require_once 'emails.inc.php'; | |
841cfb97 | 291 | require_once('wiki.inc.php'); |
292 | wiki_require_page('Xorg.Antispam'); | |
81b5b746 | 293 | |
294 | $page->changeTpl('emails/antispam.tpl'); | |
295 | ||
cab08090 | 296 | $bogo = new Bogo(S::v('uid')); |
b7582015 | 297 | if (isset($statut_filtre)) { |
11ed26e5 | 298 | $bogo->change($statut_filtre + 0); |
81b5b746 | 299 | } |
300 | $page->assign('filtre',$bogo->level()); | |
81b5b746 | 301 | } |
302 | ||
62ce6356 | 303 | function handler_submit(&$page) |
304 | { | |
4b9ba601 | 305 | require_once('wiki.inc.php'); |
306 | wiki_require_page('Xorg.Mails'); | |
62ce6356 | 307 | $page->changeTpl('emails/submit_spam.tpl'); |
308 | ||
40d428d8 VZ |
309 | if (Post::has('send_email')) { |
310 | S::assert_xsrf_token(); | |
311 | ||
15603084 | 312 | $upload = PlUpload::get($_FILES['mail'], S::v('forlife'), 'spam.submit', true); |
313 | if (!$upload) { | |
a7d35093 | 314 | $page->trigError('Une erreur a été rencontrée lors du transfert du fichier'); |
62ce6356 | 315 | return; |
316 | } | |
15603084 | 317 | $mime = $upload->contentType(); |
62ce6356 | 318 | if ($mime != 'text/x-mail' && $mime != 'message/rfc822') { |
15603084 | 319 | $upload->clear(); |
a7d35093 | 320 | $page->trigError('Le fichier ne contient pas un mail complet'); |
62ce6356 | 321 | return; |
322 | } | |
323 | global $globals; | |
324 | $box = Post::v('type') . '@' . $globals->mail->domain; | |
325 | $mailer = new PlMailer(); | |
326 | $mailer->addTo($box); | |
327 | $mailer->setFrom('"' . S::v('prenom') . ' ' . S::v('nom') . '" <web@' . $globals->mail->domain . '>'); | |
328 | $mailer->setTxtBody(Post::v('type') . ' soumis par ' . S::v('forlife') . ' via le web'); | |
15603084 | 329 | $mailer->addUploadAttachment($upload, Post::v('type') . '.mail'); |
62ce6356 | 330 | $mailer->send(); |
a7d35093 | 331 | $page->trigSuccess('Le message a été transmis à ' . $box); |
15603084 | 332 | $upload->clear(); |
62ce6356 | 333 | } |
334 | } | |
335 | ||
81b5b746 | 336 | function handler_send(&$page) |
337 | { | |
338 | global $globals; | |
81b5b746 | 339 | $page->changeTpl('emails/send.tpl'); |
da419622 | 340 | $page->addJsLink('ajax.js'); |
81b5b746 | 341 | |
342 | $page->assign('xorg_title','Polytechnique.org - Envoyer un email'); | |
343 | ||
344 | // action si on recoit un formulaire | |
3360c04f | 345 | if (Post::has('save')) { |
46504fb3 VZ |
346 | if (!S::has_xsrf_token()) { |
347 | return PL_FORBIDDEN; | |
348 | } | |
349 | ||
3360c04f FB |
350 | unset($_POST['save']); |
351 | if (trim(preg_replace('/-- .*/', '', Post::v('contenu'))) != "") { | |
352 | $_POST['to_contacts'] = explode(';', @$_POST['to_contacts']); | |
353 | $_POST['cc_contacts'] = explode(';', @$_POST['cc_contacts']); | |
354 | $data = serialize($_POST); | |
355 | XDB::execute("REPLACE INTO email_send_save | |
356 | VALUES ({?}, {?})", S::i('uid'), $data); | |
357 | } | |
358 | exit; | |
40d428d8 VZ |
359 | } else if (Env::v('submit') == 'Envoyer') { |
360 | S::assert_xsrf_token(); | |
361 | ||
91a14f73 | 362 | function getEmails($aliases) |
363 | { | |
364 | if (!is_array($aliases)) { | |
365 | return null; | |
366 | } | |
367 | $rel = Env::v('contacts'); | |
368 | $ret = array(); | |
369 | foreach ($aliases as $alias) { | |
370 | $ret[$alias] = $rel[$alias]; | |
371 | } | |
372 | return join(', ', $ret); | |
373 | } | |
374 | ||
5e68682e | 375 | $error = false; |
da419622 | 376 | foreach ($_FILES as &$file) { |
f3fb8eda | 377 | if ($file['name'] && !PlUpload::get($file, S::v('forlife'), 'emails.send', false)) { |
a7d35093 | 378 | $page->trigError(PlUpload::$lastError); |
5e68682e FB |
379 | $error = true; |
380 | break; | |
da419622 | 381 | } |
382 | } | |
383 | ||
5e68682e FB |
384 | if (!$error) { |
385 | XDB::execute("DELETE FROM email_send_save | |
386 | WHERE uid = {?}", S::i('uid')); | |
387 | ||
388 | $to2 = getEmails(Env::v('to_contacts')); | |
389 | $cc2 = getEmails(Env::v('cc_contacts')); | |
390 | $txt = str_replace('^M', '', Env::v('contenu')); | |
391 | $to = Env::v('to'); | |
392 | $subj = Env::v('sujet'); | |
393 | $from = Env::v('from'); | |
394 | $cc = trim(Env::v('cc')); | |
395 | $bcc = trim(Env::v('bcc')); | |
396 | ||
397 | if (empty($to) && empty($cc) && empty($to2) && empty($bcc) && empty($cc2)) { | |
a7d35093 | 398 | $page->trigError("Indique au moins un destinataire."); |
da419622 | 399 | $page->assign('uploaded_f', PlUpload::listFilenames(S::v('forlife'), 'emails.send')); |
5e68682e FB |
400 | } else { |
401 | $mymail = new PlMailer(); | |
402 | $mymail->setFrom($from); | |
403 | $mymail->setSubject($subj); | |
404 | if (!empty($to)) { $mymail->addTo($to); } | |
405 | if (!empty($cc)) { $mymail->addCc($cc); } | |
406 | if (!empty($bcc)) { $mymail->addBcc($bcc); } | |
407 | if (!empty($to2)) { $mymail->addTo($to2); } | |
408 | if (!empty($cc2)) { $mymail->addCc($cc2); } | |
409 | $files =& PlUpload::listFiles(S::v('forlife'), 'emails.send'); | |
410 | foreach ($files as $name=>&$upload) { | |
411 | $mymail->addUploadAttachment($upload, $name); | |
412 | } | |
413 | if (Env::v('nowiki')) { | |
414 | $mymail->setTxtBody(wordwrap($txt, 78, "\n")); | |
415 | } else { | |
416 | $mymail->setWikiBody($txt); | |
417 | } | |
418 | if ($mymail->send()) { | |
a7d35093 | 419 | $page->trigSuccess("Ton mail a bien été envoyé."); |
5e68682e FB |
420 | $_REQUEST = array('bcc' => S::v('bestalias').'@'.$globals->mail->domain); |
421 | PlUpload::clear(S::v('forlife'), 'emails.send'); | |
422 | } else { | |
a7d35093 | 423 | $page->trigError("Erreur lors de l'envoi du courriel, réessaye."); |
5e68682e FB |
424 | $page->assign('uploaded_f', PlUpload::listFilenames(S::v('forlife'), 'emails.send')); |
425 | } | |
81b5b746 | 426 | } |
427 | } | |
428 | } else { | |
3360c04f FB |
429 | $res = XDB::query("SELECT data |
430 | FROM email_send_save | |
431 | WHERE uid = {?}", S::i('uid')); | |
432 | if ($res->numRows() == 0) { | |
433 | PlUpload::clear(S::v('forlife'), 'emails.send'); | |
434 | $_REQUEST['bcc'] = S::v('bestalias').'@'.$globals->mail->domain; | |
435 | } else { | |
436 | $data = unserialize($res->fetchOneCell()); | |
437 | $_REQUEST = array_merge($_REQUEST, $data); | |
438 | } | |
81b5b746 | 439 | } |
440 | ||
08cce2ff | 441 | $res = XDB::query( |
81b5b746 | 442 | "SELECT u.prenom, u.nom, u.promo, a.alias as forlife |
443 | FROM auth_user_md5 AS u | |
444 | INNER JOIN contacts AS c ON (u.user_id = c.contact) | |
445 | INNER JOIN aliases AS a ON (u.user_id=a.id AND FIND_IN_SET('bestalias',a.flags)) | |
446 | WHERE c.uid = {?} | |
cab08090 | 447 | ORDER BY u.nom, u.prenom", S::v('uid')); |
81b5b746 | 448 | $page->assign('contacts', $res->fetchAllAssoc()); |
5e68682e | 449 | $page->assign('maxsize', ini_get('upload_max_filesize') . 'o'); |
81b5b746 | 450 | } |
451 | ||
5ff3f06b FB |
452 | function handler_test(&$page, $forlife = null) |
453 | { | |
454 | global $globals; | |
e4ecada4 VZ |
455 | require_once 'emails.inc.php'; |
456 | ||
46504fb3 VZ |
457 | if (!S::has_xsrf_token()) { |
458 | return PL_FORBIDDEN; | |
459 | } | |
5ff3f06b FB |
460 | if (!S::has_perms() || !$forlife) { |
461 | $forlife = S::v('bestalias'); | |
462 | } | |
e4ecada4 VZ |
463 | |
464 | $res = XDB::query("SELECT FIND_IN_SET('femme', u.flags), prenom, user_id | |
5ff3f06b FB |
465 | FROM auth_user_md5 AS u |
466 | INNER JOIN aliases AS a ON (a.id = u.user_id) | |
467 | WHERE a.alias = {?}", $forlife); | |
e4ecada4 VZ |
468 | list($sexe, $prenom, $uid) = $res->fetchOneRow(); |
469 | $redirect = new Redirect($uid); | |
470 | ||
471 | $mailer = new PlMailer('emails/test.mail.tpl'); | |
472 | $mailer->assign('email', $forlife . '@' . $globals->mail->domain); | |
473 | $mailer->assign('redirects', $redirect->active_emails()); | |
5ff3f06b FB |
474 | $mailer->assign('sexe', $sexe); |
475 | $mailer->assign('prenom', $prenom); | |
476 | $mailer->send(); | |
477 | exit; | |
478 | } | |
479 | ||
2ee43273 FB |
480 | function handler_imap_in(&$page, $hash = null, $login = null) |
481 | { | |
482 | $page->changeTpl('emails/imap_register.tpl'); | |
483 | $id = null; | |
484 | if (!empty($hash) || !empty($login)) { | |
e2cea47d | 485 | $req = XDB::query("SELECT u.prenom, FIND_IN_SET('femme', u.flags) AS sexe, a.id |
2ee43273 FB |
486 | FROM aliases AS a |
487 | INNER JOIN newsletter_ins AS ni ON (a.id = ni.user_id) | |
488 | INNER JOIN auth_user_md5 AS u ON (u.user_id = a.id) | |
489 | WHERE a.alias = {?} AND ni.hash = {?}", $login, $hash); | |
e2cea47d | 490 | list($prenom, $sexe, $id) = $req->fetchOneRow(); |
2ee43273 FB |
491 | } |
492 | ||
493 | require_once('emails.inc.php'); | |
494 | $page->assign('ok', false); | |
495 | if (S::logged() && (is_null($id) || $id == S::i('uid'))) { | |
496 | $storage = new EmailStorage(S::i('uid'), 'imap'); | |
497 | $storage->activate(); | |
498 | $page->assign('ok', true); | |
499 | $page->assign('prenom', S::v('prenom')); | |
e2cea47d | 500 | $page->assign('sexe', S::v('femme')); |
2ee43273 FB |
501 | } else if (!S::logged() && $id) { |
502 | $storage = new EmailStorage($id, 'imap'); | |
503 | $storage->activate(); | |
504 | $page->assign('ok', true); | |
505 | $page->assign('prenom', $prenom); | |
e2cea47d | 506 | $page->assign('sexe', $sexe); |
2ee43273 FB |
507 | } |
508 | } | |
509 | ||
81b5b746 | 510 | function handler_broken(&$page, $warn = null, $email = null) |
511 | { | |
512 | require_once 'emails.inc.php'; | |
4b9ba601 | 513 | require_once('wiki.inc.php'); |
a7de4ef7 | 514 | wiki_require_page('Xorg.PatteCassée'); |
81b5b746 | 515 | |
516 | global $globals; | |
517 | ||
518 | $page->changeTpl('emails/broken.tpl'); | |
519 | ||
40d428d8 VZ |
520 | if ($warn == 'warn' && $email) { |
521 | S::assert_xsrf_token(); | |
522 | ||
81b5b746 | 523 | $email = valide_email($email); |
a7de4ef7 | 524 | // vérifications d'usage |
08cce2ff | 525 | $sel = XDB::query( |
81b5b746 | 526 | "SELECT e.uid, a.alias |
527 | FROM emails AS e | |
81b5b746 | 528 | INNER JOIN aliases AS a ON (e.uid = a.id AND type!='homonyme' |
529 | AND FIND_IN_SET('bestalias',a.flags)) | |
530 | WHERE e.email={?}", $email); | |
531 | ||
532 | if (list($uid, $dest) = $sel->fetchOneRow()) { | |
533 | // envoi du mail | |
534 | $message = "Bonjour ! | |
535 | ||
a7de4ef7 | 536 | Ce mail a été généré automatiquement par le service de patte cassée de |
cab08090 | 537 | Polytechnique.org car un autre utilisateur, ".S::v('prenom').' '.S::v('nom').", |
a7de4ef7 | 538 | nous a signalé qu'en t'envoyant un mail, il avait reçu un message d'erreur |
81b5b746 | 539 | indiquant que ton adresse de redirection $email |
540 | ne fonctionnait plus ! | |
541 | ||
a7de4ef7 | 542 | Nous te suggérons de vérifier cette adresse, et le cas échéant de mettre |
543 | à jour sur le site <{$globals->baseurl}/emails> tes adresses | |
81b5b746 | 544 | de redirection... |
545 | ||
661e78f7 | 546 | Pour plus de renseignements sur le service de patte cassée, n'hésite pas à |
2c388954 | 547 | consulter la page <{$globals->baseurl}/emails/broken>. |
81b5b746 | 548 | |
549 | ||
661e78f7 | 550 | À bientôt sur Polytechnique.org ! |
1d55fe45 | 551 | L'équipe d'administration <support@" . $globals->mail->domain . '>'; |
81b5b746 | 552 | |
1e33266a | 553 | $mail = new PlMailer(); |
1d55fe45 | 554 | $mail->setFrom('"Polytechnique.org" <support@' . $globals->mail->domain . '>'); |
555 | $mail->addTo("$dest@" . $globals->mail->domain); | |
81b5b746 | 556 | $mail->setSubject("Une de tes adresse de redirection Polytechnique.org ne marche plus !!"); |
557 | $mail->setTxtBody($message); | |
558 | $mail->send(); | |
a7d35093 | 559 | $page->trigSuccess("Mail envoyé !"); |
81b5b746 | 560 | } |
40d428d8 VZ |
561 | } elseif (Post::has('email')) { |
562 | S::assert_xsrf_token(); | |
563 | ||
5e2307dc | 564 | $email = valide_email(Post::v('email')); |
81b5b746 | 565 | |
566 | list(,$fqdn) = explode('@', $email); | |
567 | $fqdn = strtolower($fqdn); | |
40d428d8 | 568 | if ($fqdn == 'polytechnique.org' || $fqdn == 'melix.org' || $fqdn == 'm4x.org' || $fqdn == 'melix.net') { |
81b5b746 | 569 | $page->assign('neuneu', true); |
570 | } else { | |
571 | $page->assign('email',$email); | |
08cce2ff | 572 | $sel = XDB::query( |
b1797f70 VZ |
573 | "SELECT e1.uid, e1.panne != 0 AS panne, |
574 | (count(e2.uid) + IF(FIND_IN_SET('googleapps', u.mail_storage), 1, 0)) AS nb_mails, | |
4b9ba601 | 575 | u.nom, u.prenom, u.promo, a.alias AS forlife |
81b5b746 | 576 | FROM emails as e1 |
eaf30d86 | 577 | LEFT JOIN emails as e2 ON(e1.uid = e2.uid |
81b5b746 | 578 | AND FIND_IN_SET('active', e2.flags) |
579 | AND e1.email != e2.email) | |
580 | INNER JOIN auth_user_md5 as u ON(e1.uid = u.user_id) | |
4b9ba601 | 581 | INNER JOIN aliases AS a ON (a.id = e1.uid AND a.type = 'a_vie') |
81b5b746 | 582 | WHERE e1.email = {?} |
583 | GROUP BY e1.uid", $email); | |
584 | if ($x = $sel->fetchOneAssoc()) { | |
a7de4ef7 | 585 | // on écrit dans la base que l'adresse est cassée |
81b5b746 | 586 | if (!$x['panne']) { |
74938c82 | 587 | XDB::execute("UPDATE emails |
588 | SET panne=NOW(), | |
589 | last=NOW(), | |
590 | panne_level = 1 | |
591 | WHERE email = {?}", $email); | |
592 | } else { | |
593 | XDB::execute("UPDATE emails | |
594 | SET panne_level = 1 | |
4b9ba601 | 595 | WHERE email = {?} AND panne_level = 0", $email); |
81b5b746 | 596 | } |
597 | $page->assign_by_ref('x', $x); | |
598 | } | |
599 | } | |
600 | } | |
601 | } | |
9e570fe0 | 602 | |
603 | function handler_duplicated(&$page, $action = 'list', $email = null) | |
604 | { | |
605 | $page->changeTpl('emails/duplicated.tpl'); | |
606 | ||
607 | $states = array('pending' => 'En attente...', | |
a7de4ef7 | 608 | 'safe' => 'Pas d\'inquiétude', |
9e570fe0 | 609 | 'unsafe' => 'Recherches en cours', |
610 | 'dangerous' => 'Usurpations par cette adresse'); | |
611 | $page->assign('states', $states); | |
612 | ||
40d428d8 VZ |
613 | if (Post::has('action')) { |
614 | S::assert_xsrf_token(); | |
46504fb3 | 615 | } |
9e570fe0 | 616 | switch (Post::v('action')) { |
46504fb3 | 617 | case 'create': |
9e570fe0 | 618 | if (trim(Post::v('emailN')) != '') { |
619 | Xdb::execute('INSERT IGNORE INTO emails_watch (email, state, detection, last, uid, description) | |
620 | VALUES ({?}, {?}, CURDATE(), NOW(), {?}, {?})', | |
621 | trim(Post::v('emailN')), Post::v('stateN'), S::i('uid'), Post::v('descriptionN')); | |
622 | }; | |
623 | break; | |
624 | ||
46504fb3 | 625 | case 'edit': |
9e570fe0 | 626 | Xdb::execute('UPDATE emails_watch |
627 | SET state = {?}, last = NOW(), uid = {?}, description = {?} | |
628 | WHERE email = {?}', Post::v('stateN'), S::i('uid'), Post::v('descriptionN'), Post::v('emailN')); | |
629 | break; | |
630 | ||
46504fb3 | 631 | default: |
9e570fe0 | 632 | if ($action == 'delete' && !is_null($email)) { |
633 | Xdb::execute('DELETE FROM emails_watch WHERE email = {?}', $email); | |
634 | } | |
635 | } | |
636 | if ($action != 'create' && $action != 'edit') { | |
637 | $action = 'list'; | |
638 | } | |
639 | $page->assign('action', $action); | |
640 | ||
641 | if ($action == 'list') { | |
642 | $sql = "SELECT w.email, w.detection, w.state, a.alias AS forlife | |
643 | FROM emails_watch AS w | |
ca6d07f4 | 644 | LEFT JOIN emails AS e USING(email) |
645 | LEFT JOIN aliases AS a ON (a.id = e.uid AND a.type = 'a_vie') | |
9e570fe0 | 646 | ORDER BY w.state, w.email, a.alias"; |
647 | $it = Xdb::iterRow($sql); | |
648 | ||
649 | $table = array(); | |
650 | $props = array(); | |
651 | while (list($email, $date, $state, $forlife) = $it->next()) { | |
652 | if (count($props) == 0 || $props['mail'] != $email) { | |
653 | if (count($props) > 0) { | |
654 | $table[] = $props; | |
655 | } | |
656 | $props = array('mail' => $email, | |
657 | 'detection' => $date, | |
658 | 'state' => $state, | |
659 | 'users' => array($forlife)); | |
660 | } else { | |
661 | $props['users'][] = $forlife; | |
662 | } | |
663 | } | |
664 | if (count($props) > 0) { | |
665 | $table[] = $props; | |
666 | } | |
667 | $page->assign('table', $table); | |
668 | } elseif ($action == 'edit') { | |
669 | $sql = "SELECT w.detection, w.state, w.last, w.description, | |
670 | a1.alias AS edit, a2.alias AS forlife | |
671 | FROM emails_watch AS w | |
eaf30d86 | 672 | LEFT JOIN aliases AS a1 ON (a1.id = w.uid AND a1.type = 'a_vie') |
9615c895 | 673 | LEFT JOIN emails AS e ON (w.email = e.email) |
ca6d07f4 | 674 | LEFT JOIN aliases AS a2 ON (a2.id = e.uid AND a2.type = 'a_vie') |
9e570fe0 | 675 | WHERE w.email = {?} |
676 | ORDER BY a2.alias"; | |
677 | $it = Xdb::iterRow($sql, $email); | |
678 | ||
679 | $props = array(); | |
680 | while (list($detection, $state, $last, $description, $edit, $forlife) = $it->next()) { | |
681 | if (count($props) == 0) { | |
682 | $props = array('mail' => $email, | |
683 | 'detection' => $detection, | |
684 | 'state' => $state, | |
685 | 'last' => $last, | |
686 | 'description' => $description, | |
687 | 'edit' => $edit, | |
688 | 'users' => array($forlife)); | |
689 | } else { | |
690 | $props['users'][] = $forlife; | |
691 | } | |
692 | } | |
693 | $page->assign('doublon', $props); | |
694 | } | |
695 | } | |
7727ffc7 | 696 | function handler_lost(&$page, $action = 'list', $email = null) |
697 | { | |
698 | $page->changeTpl('emails/lost.tpl'); | |
eaf30d86 | 699 | |
7727ffc7 | 700 | $page->assign('lost_emails', XDB::iterator(' |
0e5ec860 VZ |
701 | SELECT u.user_id, a.alias |
702 | FROM auth_user_md5 AS u | |
703 | INNER JOIN aliases AS a ON (a.id = u.user_id AND a.type = "a_vie") | |
704 | LEFT JOIN emails AS e ON (u.user_id=e.uid AND FIND_IN_SET("active",e.flags)) | |
705 | WHERE e.uid IS NULL AND | |
706 | FIND_IN_SET("googleapps", u.mail_storage) = 0 AND | |
707 | u.deces = 0 | |
708 | ORDER BY u.promo DESC, u.nom, u.prenom')); | |
7727ffc7 | 709 | } |
81b5b746 | 710 | } |
711 | ||
a7de4ef7 | 712 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
81b5b746 | 713 | ?> |