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