Commit | Line | Data |
---|---|---|
81b5b746 | 1 | <?php |
2 | /*************************************************************************** | |
8d84c630 | 3 | * Copyright (C) 2003-2009 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( | |
eb5a266d SJ |
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), | |
9e570fe0 | 35 | |
eb5a266d SJ |
36 | 'emails/rewrite/in' => $this->make_hook('rewrite_in', AUTH_PUBLIC), |
37 | 'emails/rewrite/out' => $this->make_hook('rewrite_out', AUTH_PUBLIC), | |
3d17e48f | 38 | |
eb5a266d | 39 | 'emails/imap/in' => $this->make_hook('imap_in', AUTH_PUBLIC), |
2ee43273 | 40 | |
eb5a266d SJ |
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'), | |
67e06366 | 44 | 'admin/emails/broken' => $this->make_hook('broken_addr', AUTH_MDP, 'admin'), |
81b5b746 | 45 | ); |
46 | } | |
47 | ||
b7582015 | 48 | function handler_emails(&$page, $action = null, $email = null) |
81b5b746 | 49 | { |
50 | global $globals; | |
e97e9b8f | 51 | require_once 'emails.inc.php'; |
81b5b746 | 52 | |
53 | $page->changeTpl('emails/index.tpl'); | |
46f272fe | 54 | $page->setTitle('Mes emails'); |
81b5b746 | 55 | |
2d997414 | 56 | $user = S::user(); |
81b5b746 | 57 | |
2d997414 | 58 | // Apply the bestalias change request. |
b7582015 | 59 | if ($action == 'best' && $email) { |
46504fb3 VZ |
60 | if (!S::has_xsrf_token()) { |
61 | return PL_FORBIDDEN; | |
62 | } | |
63 | ||
2d997414 VZ |
64 | XDB::execute("UPDATE aliases |
65 | SET flags = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', flags, ','), ',bestalias,', ',')) | |
66 | WHERE id = {?}", $user->id()); | |
67 | XDB::execute("UPDATE aliases | |
68 | SET flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'bestalias') | |
69 | WHERE id = {?} AND alias = {?}", $user->id(), $email); | |
70 | ||
71 | // As having a non-null bestalias value is critical in | |
72 | // plat/al's code, we do an a posteriori check on the | |
73 | // validity of the bestalias. | |
74 | fix_bestalias($user); | |
81b5b746 | 75 | } |
76 | ||
2d997414 | 77 | // Fetch and display aliases. |
81b5b746 | 78 | $sql = "SELECT alias, (type='a_vie') AS a_vie, |
79 | (alias REGEXP '\\\\.[0-9]{2}$') AS cent_ans, | |
80 | FIND_IN_SET('bestalias',flags) AS best, expire | |
81 | FROM aliases | |
82 | WHERE id = {?} AND type!='homonyme' | |
83 | ORDER BY LENGTH(alias)"; | |
2d997414 | 84 | $page->assign('aliases', XDB::iterator($sql, $user->id())); |
81b5b746 | 85 | |
2d997414 VZ |
86 | // Check for homonyms. |
87 | $homonyme = XDB::query( | |
88 | "SELECT alias | |
89 | FROM aliases | |
90 | INNER JOIN homonymes ON (id = homonyme_id) | |
91 | WHERE user_id = {?} AND type = 'homonyme'", $user->id()); | |
e97e9b8f | 92 | $page->assign('homonyme', $homonyme->fetchOneCell()); |
e1547442 | 93 | |
2d997414 VZ |
94 | // Display active redirections. |
95 | $redirect = new Redirect($user); | |
e97e9b8f | 96 | $page->assign('mails', $redirect->active_emails()); |
81b5b746 | 97 | |
2d997414 | 98 | // Display, when available, the @alias_dom email alias. |
08cce2ff | 99 | $res = XDB::query( |
81b5b746 | 100 | "SELECT alias |
101 | FROM virtual AS v | |
102 | INNER JOIN virtual_redirect AS vr USING(vid) | |
eaf30d86 | 103 | WHERE (redirect={?} OR redirect={?}) |
81b5b746 | 104 | AND alias LIKE '%@{$globals->mail->alias_dom}'", |
2d997414 VZ |
105 | $user->forlifeEmail(), |
106 | // TODO: remove this über-ugly hack. The issue is that you need | |
107 | // to remove all @m4x.org addresses in virtual_redirect first. | |
108 | $user->login() . '@' . $globals->mail->domain2); | |
81b5b746 | 109 | $page->assign('melix', $res->fetchOneCell()); |
81b5b746 | 110 | } |
111 | ||
112 | function handler_alias(&$page, $action = null, $value = null) | |
113 | { | |
114 | require_once 'validations.inc.php'; | |
115 | ||
116 | global $globals; | |
117 | ||
118 | $page->changeTpl('emails/alias.tpl'); | |
46f272fe | 119 | $page->setTitle('Alias melix.net'); |
81b5b746 | 120 | |
2d997414 VZ |
121 | $user = S::user(); |
122 | $page->assign('demande', AliasReq::get_request($user->id())); | |
81b5b746 | 123 | |
2d997414 | 124 | // Remove the email alias. |
40d428d8 VZ |
125 | if ($action == 'delete' && $value) { |
126 | S::assert_xsrf_token(); | |
127 | ||
08cce2ff | 128 | XDB::execute( |
2d997414 VZ |
129 | "DELETE virtual, virtual_redirect |
130 | FROM virtual | |
131 | INNER JOIN virtual_redirect USING (vid) | |
132 | WHERE alias = {?} AND (redirect = {?} OR redirect = {?})", | |
133 | $value, $user->forlifeEmail(), | |
134 | // TODO: remove this über-ugly hack. The issue is that you need | |
135 | // to remove all @m4x.org addresses in virtual_redirect first. | |
136 | $user->login() . '@' . $globals->mail->domain2); | |
81b5b746 | 137 | } |
138 | ||
2d997414 | 139 | // Fetch existing @alias_dom aliases. |
08cce2ff | 140 | $res = XDB::query( |
81b5b746 | 141 | "SELECT alias, emails_alias_pub |
142 | FROM auth_user_quick, virtual | |
143 | INNER JOIN virtual_redirect USING(vid) | |
2d997414 | 144 | WHERE (redirect = {?} OR redirect = {?}) |
eaf30d86 | 145 | AND alias LIKE '%@{$globals->mail->alias_dom}' AND user_id = {?}", |
2d997414 VZ |
146 | $user->forlifeEmail(), |
147 | // TODO: remove this über-ugly hack. The issue is that you need | |
148 | // to remove all @m4x.org addresses in virtual_redirect first. | |
149 | $user->login() . '@' . $globals->mail->domain2, $user->id()); | |
81b5b746 | 150 | list($alias, $visibility) = $res->fetchOneRow(); |
151 | $page->assign('actuel', $alias); | |
152 | ||
40d428d8 VZ |
153 | if ($action == 'ask' && Env::has('alias') && Env::has('raison')) { |
154 | S::assert_xsrf_token(); | |
81b5b746 | 155 | |
40d428d8 | 156 | //Si l'utilisateur vient de faire une damande |
5e2307dc | 157 | $alias = Env::v('alias'); |
158 | $raison = Env::v('raison'); | |
159 | $public = (Env::v('public', 'off') == 'on')?"public":"private"; | |
81b5b746 | 160 | |
161 | $page->assign('r_alias', $alias); | |
162 | $page->assign('r_raison', $raison); | |
163 | if ($public == 'public') { | |
164 | $page->assign('r_public', true); | |
165 | } | |
166 | ||
a7de4ef7 | 167 | //Quelques vérifications sur l'alias (caractères spéciaux) |
81b5b746 | 168 | if (!preg_match( "/^[a-zA-Z0-9\-.]{3,20}$/", $alias)) { |
a7d35093 FB |
169 | $page->trigError("L'adresse demandée n'est pas valide." |
170 | . " Vérifie qu'elle comporte entre 3 et 20 caractères" | |
171 | . " et qu'elle ne contient que des lettres non accentuées," | |
172 | . " des chiffres ou les caractères - et ."); | |
fd8f77de | 173 | return; |
81b5b746 | 174 | } else { |
a7de4ef7 | 175 | //vérifier que l'alias n'est pas déja pris |
08cce2ff | 176 | $res = XDB::query('SELECT COUNT(*) FROM virtual WHERE alias={?}', |
81b5b746 | 177 | $alias.'@'.$globals->mail->alias_dom); |
178 | if ($res->fetchOneCell() > 0) { | |
a7d35093 | 179 | $page->trigError("L'alias $alias@{$globals->mail->alias_dom} a déja été attribué. |
81b5b746 | 180 | Tu ne peux donc pas l'obtenir."); |
fd8f77de | 181 | return; |
81b5b746 | 182 | } |
183 | ||
a7de4ef7 | 184 | //vérifier que l'alias n'est pas déja en demande |
81b5b746 | 185 | $it = new ValidateIterator (); |
186 | while($req = $it->next()) { | |
1f07f6c2 | 187 | if ($req->type == "alias" and $req->alias == $alias . '@' . $globals->mail->alias_dom) { |
a7d35093 | 188 | $page->trigError("L'alias $alias@{$globals->mail->alias_dom} a déja été demandé. |
81b5b746 | 189 | Tu ne peux donc pas l'obtenir pour l'instant."); |
fd8f77de | 190 | return ; |
81b5b746 | 191 | } |
192 | } | |
193 | ||
a7de4ef7 | 194 | //Insertion de la demande dans la base, écrase les requêtes précédente |
2d997414 | 195 | $myalias = new AliasReq($user, $alias, $raison, $public); |
81b5b746 | 196 | $myalias->submit(); |
197 | $page->assign('success',$alias); | |
fd8f77de | 198 | return; |
81b5b746 | 199 | } |
46504fb3 VZ |
200 | } elseif ($action == 'set' && ($value == 'public' || $value == 'private')) { |
201 | if (!S::has_xsrf_token()) { | |
202 | return PL_FORBIDDEN; | |
203 | } | |
204 | ||
81b5b746 | 205 | if ($value == 'public') { |
08cce2ff | 206 | XDB::execute("UPDATE auth_user_quick SET emails_alias_pub = 'public' |
2d997414 | 207 | WHERE user_id = {?}", $user->id()); |
81b5b746 | 208 | } else { |
08cce2ff | 209 | XDB::execute("UPDATE auth_user_quick SET emails_alias_pub = 'private' |
2d997414 | 210 | WHERE user_id = {?}", $user->id()); |
81b5b746 | 211 | } |
212 | ||
213 | $visibility = $value; | |
214 | } | |
215 | ||
216 | $page->assign('mail_public', ($visibility == 'public')); | |
81b5b746 | 217 | } |
218 | ||
219 | function handler_redirect(&$page, $action = null, $email = null) | |
220 | { | |
221 | global $globals; | |
222 | ||
223 | require_once 'emails.inc.php'; | |
224 | ||
225 | $page->changeTpl('emails/redirect.tpl'); | |
226 | ||
2d997414 VZ |
227 | $user = S::user(); |
228 | $page->assign_by_ref('user', $user); | |
229 | $page->assign('eleve', $user->promo() >= date("Y") - 5); | |
3b83212e | 230 | |
2d997414 | 231 | $redirect = new Redirect($user); |
81b5b746 | 232 | |
6d6b65bf | 233 | // FS#703 : $_GET is urldecoded twice, hence |
234 | // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding) | |
235 | // Since there can be no spaces in emails, we can fix this with : | |
236 | $email = str_replace(' ', '+', $email); | |
237 | ||
2d997414 | 238 | // Apply email redirection change requests. |
1060c854 | 239 | $result = SUCCESS; |
81b5b746 | 240 | if ($action == 'remove' && $email) { |
1060c854 | 241 | $result = $redirect->delete_email($email); |
81b5b746 | 242 | } |
e1547442 FB |
243 | |
244 | if ($action == 'active' && $email) { | |
245 | $redirect->modify_one_email($email, true); | |
246 | } | |
247 | ||
248 | if ($action == 'inactive' && $email) { | |
249 | $redirect->modify_one_email($email, false); | |
250 | } | |
251 | ||
252 | if ($action == 'rewrite' && $email) { | |
253 | $rewrite = @func_get_arg(3); | |
254 | $redirect->modify_one_email_redirect($email, $rewrite); | |
255 | } | |
256 | ||
40d428d8 VZ |
257 | if (Env::has('emailop')) { |
258 | S::assert_xsrf_token(); | |
259 | ||
5e2307dc | 260 | $actifs = Env::v('emails_actifs', Array()); |
b7582015 | 261 | print_r(Env::v('emails_rewrite')); |
5e2307dc | 262 | if (Env::v('emailop') == "ajouter" && Env::has('email')) { |
1060c854 | 263 | $result = $redirect->add_email(Env::v('email')); |
81b5b746 | 264 | } elseif (empty($actifs)) { |
1060c854 | 265 | $result = ERROR_INACTIVE_REDIRECTION; |
81b5b746 | 266 | } elseif (is_array($actifs)) { |
1060c854 | 267 | $result = $redirect->modify_email($actifs, Env::v('emails_rewrite', Array())); |
81b5b746 | 268 | } |
269 | } | |
270 | ||
1060c854 | 271 | switch ($result) { |
44b071c2 SJ |
272 | case ERROR_INACTIVE_REDIRECTION: |
273 | $page->trigError('Tu ne peux pas avoir aucune adresse de redirection active, sinon ton adresse ' | |
4478f95e | 274 | . $user->forlifeEmail() . ' ne fonctionnerait plus.'); |
44b071c2 SJ |
275 | break; |
276 | case ERROR_INVALID_EMAIL: | |
277 | $page->trigError('Erreur: l\'email n\'est pas valide.'); | |
278 | break; | |
279 | case ERROR_LOOP_EMAIL: | |
4478f95e | 280 | $page->trigError('Erreur : ' . $user->forlifeEmail() |
44b071c2 SJ |
281 | . ' ne doit pas être renvoyé vers lui-même, ni vers son équivalent en ' |
282 | . $globals->mail->domain2 . ' ni vers polytechnique.edu.'); | |
283 | break; | |
284 | } | |
285 | ||
2d997414 | 286 | // Fetch the @alias_dom email alias, if any. |
08cce2ff | 287 | $res = XDB::query( |
81b5b746 | 288 | "SELECT alias |
289 | FROM virtual | |
290 | INNER JOIN virtual_redirect USING(vid) | |
291 | WHERE (redirect={?} OR redirect={?}) | |
eaf30d86 | 292 | AND alias LIKE '%@{$globals->mail->alias_dom}'", |
2d997414 VZ |
293 | $user->forlifeEmail(), |
294 | // TODO: remove this über-ugly hack. The issue is that you need | |
295 | // to remove all @m4x.org addresses in virtual_redirect first. | |
296 | $user->login() . '@' . $globals->mail->domain2); | |
81b5b746 | 297 | $melix = $res->fetchOneCell(); |
298 | if ($melix) { | |
299 | list($melix) = explode('@', $melix); | |
300 | $page->assign('melix',$melix); | |
301 | } | |
302 | ||
2d997414 | 303 | // Fetch existing email aliases. |
08cce2ff | 304 | $res = XDB::query( |
81b5b746 | 305 | "SELECT alias,expire |
306 | FROM aliases | |
307 | WHERE id={?} AND (type='a_vie' OR type='alias') | |
2d997414 | 308 | ORDER BY !FIND_IN_SET('usage',flags), LENGTH(alias)", $user->id()); |
81b5b746 | 309 | $page->assign('alias', $res->fetchAllAssoc()); |
2d997414 | 310 | $page->assign('emails', $redirect->emails); |
aab4661d | 311 | |
2d997414 | 312 | // Display GoogleApps acount information. |
f5c4bf30 | 313 | require_once 'googleapps.inc.php'; |
2d997414 | 314 | $page->assign('googleapps', GoogleAppsAccount::account_status($user->id())); |
81b5b746 | 315 | } |
316 | ||
b7582015 | 317 | function handler_antispam(&$page, $statut_filtre = null) |
81b5b746 | 318 | { |
319 | require_once 'emails.inc.php'; | |
8f201b69 FB |
320 | $wp = new PlWikiPage('Xorg.Antispam'); |
321 | $wp->buildCache(); | |
81b5b746 | 322 | |
323 | $page->changeTpl('emails/antispam.tpl'); | |
324 | ||
12a587df | 325 | $bogo = new Bogo(S::user()); |
b7582015 | 326 | if (isset($statut_filtre)) { |
11ed26e5 | 327 | $bogo->change($statut_filtre + 0); |
81b5b746 | 328 | } |
2d997414 | 329 | $page->assign('filtre', $bogo->level()); |
81b5b746 | 330 | } |
331 | ||
62ce6356 | 332 | function handler_submit(&$page) |
333 | { | |
8f201b69 FB |
334 | $wp = new PlWikiPage('Xorg.Mails'); |
335 | $wp->buildCache(); | |
62ce6356 | 336 | $page->changeTpl('emails/submit_spam.tpl'); |
337 | ||
40d428d8 VZ |
338 | if (Post::has('send_email')) { |
339 | S::assert_xsrf_token(); | |
340 | ||
f3df6d38 | 341 | $upload = PlUpload::get($_FILES['mail'], S::user()->login(), 'spam.submit', true); |
15603084 | 342 | if (!$upload) { |
a7d35093 | 343 | $page->trigError('Une erreur a été rencontrée lors du transfert du fichier'); |
62ce6356 | 344 | return; |
345 | } | |
15603084 | 346 | $mime = $upload->contentType(); |
62ce6356 | 347 | if ($mime != 'text/x-mail' && $mime != 'message/rfc822') { |
15603084 | 348 | $upload->clear(); |
faefdbb7 | 349 | $page->trigError('Le fichier ne contient pas un email complet'); |
62ce6356 | 350 | return; |
351 | } | |
2d997414 VZ |
352 | $type = (Post::v('type') == 'spam' ? 'spam' : 'nonspam'); |
353 | ||
62ce6356 | 354 | global $globals; |
2d997414 | 355 | $box = $type . '@' . $globals->mail->domain; |
62ce6356 | 356 | $mailer = new PlMailer(); |
357 | $mailer->addTo($box); | |
2d997414 VZ |
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'); | |
62ce6356 | 361 | $mailer->send(); |
a7d35093 | 362 | $page->trigSuccess('Le message a été transmis à ' . $box); |
15603084 | 363 | $upload->clear(); |
62ce6356 | 364 | } |
365 | } | |
366 | ||
81b5b746 | 367 | function handler_send(&$page) |
368 | { | |
81b5b746 | 369 | $page->changeTpl('emails/send.tpl'); |
da419622 | 370 | $page->addJsLink('ajax.js'); |
81b5b746 | 371 | |
46f272fe | 372 | $page->setTitle('Envoyer un email'); |
81b5b746 | 373 | |
374 | // action si on recoit un formulaire | |
3360c04f | 375 | if (Post::has('save')) { |
46504fb3 VZ |
376 | if (!S::has_xsrf_token()) { |
377 | return PL_FORBIDDEN; | |
378 | } | |
379 | ||
3360c04f FB |
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); | |
387 | } | |
388 | exit; | |
40d428d8 VZ |
389 | } else if (Env::v('submit') == 'Envoyer') { |
390 | S::assert_xsrf_token(); | |
391 | ||
91a14f73 | 392 | function getEmails($aliases) |
393 | { | |
394 | if (!is_array($aliases)) { | |
395 | return null; | |
396 | } | |
397 | $rel = Env::v('contacts'); | |
398 | $ret = array(); | |
399 | foreach ($aliases as $alias) { | |
400 | $ret[$alias] = $rel[$alias]; | |
401 | } | |
402 | return join(', ', $ret); | |
403 | } | |
404 | ||
5e68682e | 405 | $error = false; |
da419622 | 406 | foreach ($_FILES as &$file) { |
f3df6d38 | 407 | if ($file['name'] && !PlUpload::get($file, S::user()->login(), 'emails.send', false)) { |
a7d35093 | 408 | $page->trigError(PlUpload::$lastError); |
5e68682e FB |
409 | $error = true; |
410 | break; | |
da419622 | 411 | } |
412 | } | |
413 | ||
5e68682e FB |
414 | if (!$error) { |
415 | XDB::execute("DELETE FROM email_send_save | |
416 | WHERE uid = {?}", S::i('uid')); | |
417 | ||
418 | $to2 = getEmails(Env::v('to_contacts')); | |
419 | $cc2 = getEmails(Env::v('cc_contacts')); | |
420 | $txt = str_replace('^M', '', Env::v('contenu')); | |
421 | $to = Env::v('to'); | |
422 | $subj = Env::v('sujet'); | |
423 | $from = Env::v('from'); | |
424 | $cc = trim(Env::v('cc')); | |
425 | $bcc = trim(Env::v('bcc')); | |
426 | ||
427 | if (empty($to) && empty($cc) && empty($to2) && empty($bcc) && empty($cc2)) { | |
a7d35093 | 428 | $page->trigError("Indique au moins un destinataire."); |
f3df6d38 | 429 | $page->assign('uploaded_f', PlUpload::listFilenames(S::user()->login(), 'emails.send')); |
5e68682e FB |
430 | } else { |
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); } | |
f3df6d38 | 439 | $files =& PlUpload::listFiles(S::user()->login(), 'emails.send'); |
5e68682e FB |
440 | foreach ($files as $name=>&$upload) { |
441 | $mymail->addUploadAttachment($upload, $name); | |
442 | } | |
443 | if (Env::v('nowiki')) { | |
444 | $mymail->setTxtBody(wordwrap($txt, 78, "\n")); | |
445 | } else { | |
446 | $mymail->setWikiBody($txt); | |
447 | } | |
448 | if ($mymail->send()) { | |
faefdbb7 | 449 | $page->trigSuccess("Ton email a bien été envoyé."); |
2d997414 | 450 | $_REQUEST = array('bcc' => S::user()->bestEmail()); |
f3df6d38 | 451 | PlUpload::clear(S::user()->login(), 'emails.send'); |
5e68682e | 452 | } else { |
a7d35093 | 453 | $page->trigError("Erreur lors de l'envoi du courriel, réessaye."); |
f3df6d38 | 454 | $page->assign('uploaded_f', PlUpload::listFilenames(S::user()->login(), 'emails.send')); |
5e68682e | 455 | } |
81b5b746 | 456 | } |
457 | } | |
458 | } else { | |
3360c04f FB |
459 | $res = XDB::query("SELECT data |
460 | FROM email_send_save | |
461 | WHERE uid = {?}", S::i('uid')); | |
462 | if ($res->numRows() == 0) { | |
f3df6d38 | 463 | PlUpload::clear(S::user()->login(), 'emails.send'); |
2d997414 | 464 | $_REQUEST['bcc'] = S::user()->bestEmail(); |
3360c04f FB |
465 | } else { |
466 | $data = unserialize($res->fetchOneCell()); | |
467 | $_REQUEST = array_merge($_REQUEST, $data); | |
468 | } | |
81b5b746 | 469 | } |
470 | ||
08cce2ff | 471 | $res = XDB::query( |
81b5b746 | 472 | "SELECT u.prenom, u.nom, u.promo, a.alias as forlife |
473 | FROM auth_user_md5 AS u | |
474 | INNER JOIN contacts AS c ON (u.user_id = c.contact) | |
475 | INNER JOIN aliases AS a ON (u.user_id=a.id AND FIND_IN_SET('bestalias',a.flags)) | |
476 | WHERE c.uid = {?} | |
cab08090 | 477 | ORDER BY u.nom, u.prenom", S::v('uid')); |
81b5b746 | 478 | $page->assign('contacts', $res->fetchAllAssoc()); |
5e68682e | 479 | $page->assign('maxsize', ini_get('upload_max_filesize') . 'o'); |
2d997414 | 480 | $page->assign('user', S::user()); |
81b5b746 | 481 | } |
482 | ||
d0c3e04d | 483 | function handler_test(&$page, $hruid = null) |
5ff3f06b | 484 | { |
e4ecada4 VZ |
485 | require_once 'emails.inc.php'; |
486 | ||
46504fb3 VZ |
487 | if (!S::has_xsrf_token()) { |
488 | return PL_FORBIDDEN; | |
489 | } | |
d0c3e04d VZ |
490 | |
491 | // Retrieves the User object for the test email recipient. | |
dd70cd28 | 492 | if (S::admin() && $hruid) { |
d0c3e04d VZ |
493 | $user = User::getSilent($hruid); |
494 | } else { | |
495 | $user = S::user(); | |
496 | } | |
497 | if (!$user) { | |
498 | return PL_NOT_FOUND; | |
5ff3f06b | 499 | } |
e4ecada4 | 500 | |
d0c3e04d | 501 | // Sends the test email. |
12a587df | 502 | $redirect = new Redirect($user); |
e4ecada4 VZ |
503 | |
504 | $mailer = new PlMailer('emails/test.mail.tpl'); | |
d0c3e04d | 505 | $mailer->assign('email', $user->bestEmail()); |
e4ecada4 | 506 | $mailer->assign('redirects', $redirect->active_emails()); |
d0c3e04d VZ |
507 | $mailer->assign('display_name', $user->displayName()); |
508 | $mailer->assign('sexe', $user->isFemale()); | |
509 | $mailer->send($user->isEmailFormatHtml()); | |
5ff3f06b FB |
510 | exit; |
511 | } | |
512 | ||
3d17e48f FB |
513 | function handler_rewrite_in(&$page, $mail, $hash) |
514 | { | |
515 | $page->changeTpl('emails/rewrite.tpl'); | |
516 | $page->assign('option', 'in'); | |
517 | if (empty($mail) || empty($hash)) { | |
518 | return PL_NOT_FOUND; | |
519 | } | |
520 | $pos = strrpos($mail, '_'); | |
521 | if ($pos === false) { | |
522 | return PL_NOT_FOUND; | |
523 | } | |
524 | $mail{$pos} = '@'; | |
525 | $res = XDB::query("SELECT COUNT(*) | |
526 | FROM emails | |
527 | WHERE email = {?} AND hash = {?}", | |
528 | $mail, $hash); | |
529 | $count = intval($res->fetchOneCell()); | |
530 | if ($count > 0) { | |
531 | XDB::query("UPDATE emails | |
532 | SET allow_rewrite = true, hash = NULL | |
533 | WHERE email = {?} AND hash = {?}", | |
534 | $mail, $hash); | |
535 | $page->trigSuccess("Réécriture activée pour l'adresse " . $mail); | |
536 | return; | |
537 | } | |
538 | return PL_NOT_FOUND; | |
539 | } | |
540 | ||
541 | function handler_rewrite_out(&$page, $mail, $hash) | |
542 | { | |
543 | $page->changeTpl('emails/rewrite.tpl'); | |
544 | $page->assign('option', 'out'); | |
545 | if (empty($mail) || empty($hash)) { | |
546 | return PL_NOT_FOUND; | |
547 | } | |
548 | $pos = strrpos($mail, '_'); | |
549 | if ($pos === false) { | |
550 | return PL_NOT_FOUND; | |
551 | } | |
552 | $mail{$pos} = '@'; | |
553 | $res = XDB::query("SELECT COUNT(*) | |
554 | FROM emails | |
555 | WHERE email = {?} AND hash = {?}", | |
556 | $mail, $hash); | |
557 | $count = intval($res->fetchOneCell()); | |
558 | if ($count > 0) { | |
559 | global $globals; | |
560 | $res = XDB::query("SELECT e.email, e.rewrite, a.alias | |
561 | FROM emails AS e | |
562 | INNER JOIN aliases AS a ON (a.id = e.uid AND a.type = 'a_vie') | |
563 | WHERE e.email = {?} AND e.hash = {?}", | |
564 | $mail, $hash); | |
565 | XDB::query("UPDATE emails | |
566 | SET allow_rewrite = false, hash = NULL | |
567 | WHERE email = {?} AND hash = {?}", | |
568 | $mail, $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"); | |
575 | $mail->send(); | |
576 | $page->trigWarning("Un mail d'alerte a été envoyé à l'équipe de " . $globals->core->sitename); | |
577 | return; | |
578 | } | |
579 | return PL_NOT_FOUND; | |
580 | } | |
581 | ||
2ee43273 FB |
582 | function handler_imap_in(&$page, $hash = null, $login = null) |
583 | { | |
584 | $page->changeTpl('emails/imap_register.tpl'); | |
12a587df | 585 | $user = null; |
2ee43273 | 586 | if (!empty($hash) || !empty($login)) { |
12a587df VZ |
587 | $user = User::getSilent($login); |
588 | if ($user) { | |
589 | $req = XDB::query("SELECT 1 FROM newsletter_ins WHERE user_id = {?} AND hash = {?}", $user->id(), $hash); | |
590 | if ($req->numRows() == 0) { | |
591 | $user = null; | |
592 | } | |
593 | } | |
2ee43273 FB |
594 | } |
595 | ||
596 | require_once('emails.inc.php'); | |
597 | $page->assign('ok', false); | |
12a587df VZ |
598 | if (S::logged() && (is_null($user) || $user->id() == S::i('uid'))) { |
599 | $storage = new EmailStorage(S::user(), 'imap'); | |
2ee43273 FB |
600 | $storage->activate(); |
601 | $page->assign('ok', true); | |
602 | $page->assign('prenom', S::v('prenom')); | |
e2cea47d | 603 | $page->assign('sexe', S::v('femme')); |
12a587df VZ |
604 | } else if (!S::logged() && $user) { |
605 | $storage = new EmailStorage($user, 'imap'); | |
2ee43273 FB |
606 | $storage->activate(); |
607 | $page->assign('ok', true); | |
12a587df VZ |
608 | $page->assign('prenom', $user->displayName()); |
609 | $page->assign('sexe', $user->isFemale()); | |
2ee43273 FB |
610 | } |
611 | } | |
612 | ||
81b5b746 | 613 | function handler_broken(&$page, $warn = null, $email = null) |
614 | { | |
615 | require_once 'emails.inc.php'; | |
8f201b69 FB |
616 | $wp = new PlWikiPage('Xorg.PatteCassée'); |
617 | $wp->buildCache(); | |
81b5b746 | 618 | |
619 | global $globals; | |
620 | ||
621 | $page->changeTpl('emails/broken.tpl'); | |
622 | ||
40d428d8 VZ |
623 | if ($warn == 'warn' && $email) { |
624 | S::assert_xsrf_token(); | |
625 | ||
81b5b746 | 626 | $email = valide_email($email); |
a7de4ef7 | 627 | // vérifications d'usage |
2d997414 VZ |
628 | $sel = XDB::query("SELECT uid FROM emails WHERE email = {?}", $email); |
629 | if (($uid = $sel->fetchOneCell())) { | |
630 | $dest = User::getSilent($uid); | |
631 | ||
81b5b746 | 632 | // envoi du mail |
633 | $message = "Bonjour ! | |
634 | ||
faefdbb7 | 635 | Cet email a été généré automatiquement par le service de patte cassée de |
2d997414 | 636 | Polytechnique.org car un autre utilisateur, " . S::user()->fullName() . ", |
faefdbb7 | 637 | nous a signalé qu'en t'envoyant un email, il avait reçu un message d'erreur |
81b5b746 | 638 | indiquant que ton adresse de redirection $email |
639 | ne fonctionnait plus ! | |
640 | ||
a7de4ef7 | 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 | |
81b5b746 | 643 | de redirection... |
644 | ||
661e78f7 | 645 | Pour plus de renseignements sur le service de patte cassée, n'hésite pas à |
2c388954 | 646 | consulter la page <{$globals->baseurl}/emails/broken>. |
81b5b746 | 647 | |
648 | ||
661e78f7 | 649 | À bientôt sur Polytechnique.org ! |
1d55fe45 | 650 | L'équipe d'administration <support@" . $globals->mail->domain . '>'; |
81b5b746 | 651 | |
1e33266a | 652 | $mail = new PlMailer(); |
1d55fe45 | 653 | $mail->setFrom('"Polytechnique.org" <support@' . $globals->mail->domain . '>'); |
2d997414 | 654 | $mail->addTo($dest->bestEmail()); |
81b5b746 | 655 | $mail->setSubject("Une de tes adresse de redirection Polytechnique.org ne marche plus !!"); |
656 | $mail->setTxtBody($message); | |
657 | $mail->send(); | |
faefdbb7 | 658 | $page->trigSuccess("Email envoyé !"); |
81b5b746 | 659 | } |
40d428d8 VZ |
660 | } elseif (Post::has('email')) { |
661 | S::assert_xsrf_token(); | |
662 | ||
5e2307dc | 663 | $email = valide_email(Post::v('email')); |
81b5b746 | 664 | |
665 | list(,$fqdn) = explode('@', $email); | |
666 | $fqdn = strtolower($fqdn); | |
40d428d8 | 667 | if ($fqdn == 'polytechnique.org' || $fqdn == 'melix.org' || $fqdn == 'm4x.org' || $fqdn == 'melix.net') { |
81b5b746 | 668 | $page->assign('neuneu', true); |
669 | } else { | |
670 | $page->assign('email',$email); | |
08cce2ff | 671 | $sel = XDB::query( |
b1797f70 VZ |
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, | |
2d997414 | 674 | u.nom, u.prenom, u.promo, u.hruid |
81b5b746 | 675 | FROM emails as e1 |
eaf30d86 | 676 | LEFT JOIN emails as e2 ON(e1.uid = e2.uid |
81b5b746 | 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) | |
680 | WHERE e1.email = {?} | |
681 | GROUP BY e1.uid", $email); | |
682 | if ($x = $sel->fetchOneAssoc()) { | |
a7de4ef7 | 683 | // on écrit dans la base que l'adresse est cassée |
81b5b746 | 684 | if (!$x['panne']) { |
74938c82 | 685 | XDB::execute("UPDATE emails |
686 | SET panne=NOW(), | |
687 | last=NOW(), | |
688 | panne_level = 1 | |
689 | WHERE email = {?}", $email); | |
690 | } else { | |
691 | XDB::execute("UPDATE emails | |
692 | SET panne_level = 1 | |
4b9ba601 | 693 | WHERE email = {?} AND panne_level = 0", $email); |
81b5b746 | 694 | } |
695 | $page->assign_by_ref('x', $x); | |
696 | } | |
697 | } | |
698 | } | |
699 | } | |
9e570fe0 | 700 | |
701 | function handler_duplicated(&$page, $action = 'list', $email = null) | |
702 | { | |
703 | $page->changeTpl('emails/duplicated.tpl'); | |
704 | ||
705 | $states = array('pending' => 'En attente...', | |
a7de4ef7 | 706 | 'safe' => 'Pas d\'inquiétude', |
9e570fe0 | 707 | 'unsafe' => 'Recherches en cours', |
708 | 'dangerous' => 'Usurpations par cette adresse'); | |
709 | $page->assign('states', $states); | |
710 | ||
40d428d8 VZ |
711 | if (Post::has('action')) { |
712 | S::assert_xsrf_token(); | |
46504fb3 | 713 | } |
9e570fe0 | 714 | switch (Post::v('action')) { |
46504fb3 | 715 | case 'create': |
9e570fe0 | 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')); | |
720 | }; | |
721 | break; | |
722 | ||
46504fb3 | 723 | case 'edit': |
9e570fe0 | 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')); | |
727 | break; | |
728 | ||
46504fb3 | 729 | default: |
9e570fe0 | 730 | if ($action == 'delete' && !is_null($email)) { |
731 | Xdb::execute('DELETE FROM emails_watch WHERE email = {?}', $email); | |
732 | } | |
733 | } | |
734 | if ($action != 'create' && $action != 'edit') { | |
735 | $action = 'list'; | |
736 | } | |
737 | $page->assign('action', $action); | |
738 | ||
739 | if ($action == 'list') { | |
740 | $sql = "SELECT w.email, w.detection, w.state, a.alias AS forlife | |
741 | FROM emails_watch AS w | |
ca6d07f4 | 742 | LEFT JOIN emails AS e USING(email) |
743 | LEFT JOIN aliases AS a ON (a.id = e.uid AND a.type = 'a_vie') | |
9e570fe0 | 744 | ORDER BY w.state, w.email, a.alias"; |
745 | $it = Xdb::iterRow($sql); | |
746 | ||
747 | $table = array(); | |
748 | $props = array(); | |
749 | while (list($email, $date, $state, $forlife) = $it->next()) { | |
750 | if (count($props) == 0 || $props['mail'] != $email) { | |
751 | if (count($props) > 0) { | |
752 | $table[] = $props; | |
753 | } | |
754 | $props = array('mail' => $email, | |
755 | 'detection' => $date, | |
756 | 'state' => $state, | |
757 | 'users' => array($forlife)); | |
758 | } else { | |
759 | $props['users'][] = $forlife; | |
760 | } | |
761 | } | |
762 | if (count($props) > 0) { | |
763 | $table[] = $props; | |
764 | } | |
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 | |
eaf30d86 | 770 | LEFT JOIN aliases AS a1 ON (a1.id = w.uid AND a1.type = 'a_vie') |
9615c895 | 771 | LEFT JOIN emails AS e ON (w.email = e.email) |
ca6d07f4 | 772 | LEFT JOIN aliases AS a2 ON (a2.id = e.uid AND a2.type = 'a_vie') |
9e570fe0 | 773 | WHERE w.email = {?} |
774 | ORDER BY a2.alias"; | |
775 | $it = Xdb::iterRow($sql, $email); | |
776 | ||
777 | $props = array(); | |
778 | while (list($detection, $state, $last, $description, $edit, $forlife) = $it->next()) { | |
779 | if (count($props) == 0) { | |
780 | $props = array('mail' => $email, | |
781 | 'detection' => $detection, | |
782 | 'state' => $state, | |
783 | 'last' => $last, | |
784 | 'description' => $description, | |
785 | 'edit' => $edit, | |
786 | 'users' => array($forlife)); | |
787 | } else { | |
788 | $props['users'][] = $forlife; | |
789 | } | |
790 | } | |
791 | $page->assign('doublon', $props); | |
792 | } | |
793 | } | |
67e06366 | 794 | |
7727ffc7 | 795 | function handler_lost(&$page, $action = 'list', $email = null) |
796 | { | |
797 | $page->changeTpl('emails/lost.tpl'); | |
eaf30d86 | 798 | |
2d997414 VZ |
799 | $page->assign('lost_emails', XDB::iterator(" |
800 | SELECT u.user_id, u.hruid | |
0e5ec860 | 801 | FROM auth_user_md5 AS u |
2d997414 VZ |
802 | LEFT JOIN emails AS e ON (u.user_id = e.uid AND FIND_IN_SET('active', e.flags)) |
803 | WHERE e.uid IS NULL AND FIND_IN_SET('googleapps', u.mail_storage) = 0 AND | |
804 | u.deces = 0 AND u.perms IN ('user', 'admin', 'disabled') | |
805 | ORDER BY u.promo DESC, u.nom, u.prenom")); | |
7727ffc7 | 806 | } |
67e06366 SJ |
807 | |
808 | function handler_broken_addr(&$page) | |
809 | { | |
810 | require_once 'emails.inc.php'; | |
811 | $page->changeTpl('emails/broken_addr.tpl'); | |
812 | ||
813 | if (Env::has('sort_broken')) { | |
814 | S::assert_xsrf_token(); | |
815 | ||
816 | $list = trim(Env::v('list')); | |
817 | if ($list == '') { | |
818 | $page->trigError('La liste est vide.'); | |
819 | } else { | |
820 | $valid_emails = array(); | |
821 | $invalid_emails = array(); | |
822 | $broken_list = explode("\n", $list); | |
823 | sort($broken_list); | |
824 | foreach ($broken_list as $orig_email) { | |
825 | $email = valide_email(trim($orig_email)); | |
826 | if (empty($email) || $email == '@') { | |
827 | $invalid_emails[] = "$orig_email: invalid email"; | |
828 | } else { | |
829 | $res = XDB::query('SELECT COUNT(*) | |
830 | FROM emails | |
831 | WHERE email = {?}', $email); | |
832 | if ($res->fetchOneCell() > 0) { | |
833 | $valid_emails[] = $email; | |
834 | } else { | |
835 | $invalid_emails[] = "$orig_email: no such redirection"; | |
836 | } | |
837 | } | |
838 | } | |
839 | ||
840 | $page->assign('valid_emails', $valid_emails); | |
841 | $page->assign('invalid_emails', $invalid_emails); | |
842 | } | |
843 | } | |
844 | ||
845 | if (Env::has('process_broken')) { | |
846 | S::assert_xsrf_token(); | |
847 | ||
848 | $list = trim(Env::v('list')); | |
849 | if ($list == '') { | |
850 | $page->trigError('La liste est vide.'); | |
851 | } else { | |
852 | global $platal; | |
853 | ||
854 | $broken_user_list = array(); | |
855 | $broken_list = explode("\n", $list); | |
856 | sort($broken_list); | |
857 | foreach ($broken_list as $orig_email) { | |
858 | $email = valide_email(trim($orig_email)); | |
859 | if (empty($email) || $email == '@') { | |
860 | continue; | |
861 | } | |
862 | ||
863 | $sel = XDB::query( | |
864 | "SELECT e1.uid, e1.panne != 0 AS panne, count(e2.uid) AS nb_mails, | |
865 | u.nom, u.prenom, u.promo, a.alias | |
866 | FROM emails AS e1 | |
867 | LEFT JOIN emails AS e2 ON (e1.uid = e2.uid AND FIND_IN_SET('active', e2.flags) | |
868 | AND e1.email != e2.email) | |
869 | INNER JOIN auth_user_md5 AS u ON (e1.uid = u.user_id) | |
870 | INNER JOIN aliases AS a ON (u.user_id = a.id AND FIND_IN_SET('bestalias', a.flags)) | |
871 | WHERE e1.email = {?} | |
872 | GROUP BY e1.uid", $email); | |
873 | ||
874 | if ($x = $sel->fetchOneAssoc()) { | |
875 | if (!$x['panne']) { | |
876 | XDB::execute('UPDATE emails | |
877 | SET panne=NOW(), last=NOW(), panne_level = 1 | |
878 | WHERE email = {?}', | |
879 | $email); | |
880 | } else { | |
881 | XDB::execute('UPDATE emails | |
882 | SET last = CURDATE(), panne_level = panne_level + 1 | |
883 | WHERE email = {?} | |
884 | AND DATE_ADD(last, INTERVAL 14 DAY) < CURDATE()', | |
885 | $email); | |
886 | } | |
887 | ||
888 | if (!empty($x['nb_mails'])) { | |
889 | $mail = new PlMailer('emails/broken.mail.tpl'); | |
890 | $mail->addTo("\"{$x['prenom']} {$x['nom']}\" <{$x['alias']}@" | |
891 | . $globals->mail->domain . '>'); | |
892 | $mail->assign('x', $x); | |
893 | $mail->assign('email', $email); | |
894 | $mail->send(); | |
895 | } | |
896 | ||
897 | if (!isset($broken_user_list[$x['alias']])) { | |
898 | $broken_user_list[$x['alias']] = array($email); | |
899 | } else { | |
900 | $broken_user_list[$x['alias']][] = $email; | |
901 | } | |
902 | } | |
903 | } | |
904 | ||
905 | XDB::execute("UPDATE emails | |
906 | SET panne_level = panne_level - 1 | |
907 | WHERE flags = 'active' AND panne_level > 1 | |
908 | AND DATE_ADD(last, INTERVAL 1 MONTH) < CURDATE()"); | |
909 | XDB::execute("UPDATE emails | |
910 | SET panne_level = 0 | |
911 | WHERE flags = 'active' AND panne_level = 1 | |
912 | AND DATE_ADD(last, INTERVAL 1 YEAR) < CURDATE()"); | |
913 | ||
914 | // Output the list of users with recently broken addresses, | |
915 | // along with the count of valid redirections. | |
916 | header('Content-Type: text/x-csv; charset=utf-8;'); | |
917 | header('Cache-Control: no-cache'); | |
918 | ||
919 | $csv = fopen('php://output', 'w'); | |
1c6b72d2 | 920 | fputcsv($csv, array('nom', 'prenom', 'alias', 'bounce', 'nbmails', 'url'), ';'); |
67e06366 SJ |
921 | foreach ($broken_user_list as $alias => $mails) { |
922 | $sel = Xdb::query( | |
923 | "SELECT u.user_id, count(e.email) AS nb_mails, u.nom, u.prenom, u.promo | |
924 | FROM aliases AS a | |
925 | INNER JOIN auth_user_md5 AS u ON a.id = u.user_id | |
926 | LEFT JOIN emails AS e ON (e.uid = u.user_id | |
927 | AND FIND_IN_SET('active', e.flags) AND e.panne = 0) | |
928 | WHERE a.alias = {?} | |
929 | GROUP BY u.user_id", $alias); | |
930 | ||
931 | if ($x = $sel->fetchOneAssoc()) { | |
932 | fputcsv($csv, array($x['nom'], $x['prenom'], $x['promo'], $alias, | |
1c6b72d2 SJ |
933 | join(',', $mails), $x['nb_mails']), |
934 | 'https://www.polytechnique.org/marketing/broken/' . $alias, ';'); | |
67e06366 SJ |
935 | } |
936 | } | |
937 | fclose($csv); | |
938 | exit; | |
939 | } | |
940 | } | |
941 | } | |
81b5b746 | 942 | } |
943 | ||
a7de4ef7 | 944 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
81b5b746 | 945 | ?> |