nettoyage wiki
[platal.git] / bin / emails.broken.php
... / ...
CommitLineData
1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
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
22ini_set('include_path', '../include:/usr/share/php');
23
24require_once('../include/xorg.inc.php');
25require_once('../include/emails.inc.php');
26
27$opts = getopt('i:o:');
28if (($opts['i'] && $opts['i'] == '-') || empty($opts['i'])) {
29 $file = 'php://stdin';
30} else {
31 $file = $opts['i'];
32}
33if (($opts['o'] && $opts['o'] == '-') || empty($opts['o'])) {
34 $output = 'php://stdout';
35} else {
36 $output = $opts['o'];
37}
38
39$emails = explode("\n", file_get_contents($file));
40$list = array();
41foreach ($emails as $_email) {
42 $email = valide_email($_email);
43 if (empty($email) || $email=='@') {
44 continue;
45 }
46
47 $sel = XDB::query(
48 "SELECT e1.uid, e1.panne != 0 AS panne, count(e2.uid) AS nb_mails, u.nom, u.prenom, u.promo, a.alias
49 FROM emails AS e1
50 LEFT JOIN emails AS e2 ON (e1.uid = e2.uid AND FIND_IN_SET('active', e2.flags) AND e1.email != e2.email)
51 INNER JOIN auth_user_md5 AS u ON (e1.uid = u.user_id)
52 INNER JOIN aliases AS a ON (u.user_id = a.id AND FIND_IN_SET('bestalias',a.flags))
53 WHERE e1.email = {?}
54 GROUP BY e1.uid", $email);
55 if ($x = $sel->fetchOneAssoc()) {
56 if (!$x['panne']) {
57 XDB::execute("UPDATE emails SET panne=NOW() WHERE email = {?}", $email);
58 }
59
60 if (empty($x['nb_mails'])) {
61 echo "$email : seule adresse active de {$x['prenom']} {$x['nom']}\n";
62 } else {
63 $message = " Bonjour !
64
65 Nous t'écrivons car lors de l'envoi de la lettre d'information mensuelle
66de Polytechnique.org à ton adresse polytechnicienne :
67
68 {$x['alias']}@polytechnique.org,
69
70l'adresse {$email}, sur laquelle tu rediriges ton courrier, ne
71fonctionnait pas.
72
73 Estimant que cette information serait susceptible de t'intéresser, nous
74avons préféré t'en informer. Il n'est pas impossible qu'il ne s'agisse que
75d'une panne temporaire. Si tu souhaites changer la liste des adresses sur
76lesquelles tu reçois le courrier qui t'es envoyé à ton adresse
77polytechnicienne, il te suffit de te rendre sur la page :
78
79 {$globals->baseurl}/emails/redirect
80
81
82 A bientôt sur Polytechnique.org !
83 L'équipe d'administration <support@polytechnique.org>
84
85---------------------------------------------------------------------------
86
87 PS : si jamais tu ne disposes plus du mot de passe te permettant
88d'accéder au site, rends toi sur la page
89
90 {$globals->baseurl}/recovery
91
92elle te permettra de créer un nouveau mot de passe après avoir rentré ton
93login ({$x['alias']}) et ta date de naissance !";
94
95 require_once("diogenes/diogenes.hermes.inc.php");
96 $mail = new HermesMailer();
97 $mail->setFrom('"Polytechnique.org" <support@polytechnique.org>');
98 $mail->addTo("\"{$x['prenom']} {$x['nom']}\" <{$x['alias']}@polytechnique.org>");
99 $mail->setSubject("Une de tes adresse de redirection Polytechnique.org ne marche plus !!");
100 $mail->setTxtBody($message);
101 $mail->send();
102 echo "$email : mail envoyé\n";
103 }
104
105 if (!isset($list[$x['alias']])) {
106 $list[$x['alias']] = array($email);
107 } else {
108 $list[$x['alias']][] = $email;
109 }
110 } else {
111 echo "$email : cette addresse n'est pas dans la base\n";
112 }
113}
114
115$csv = "nom;prenom;promo;alias;bounce;nbmails\n";
116foreach ($list as $alias=>$mails) {
117 $sel = Xdb::query(
118 "SELECT u.user_id, count(e.email) AS nb_mails, u.nom, u.prenom, u.promo
119 FROM aliases AS a
120 INNER JOIN auth_user_md5 AS u ON a.id = u.user_id
121 LEFT JOIN emails AS e ON (e.uid = u.user_id AND FIND_IN_SET('active', e.flags) AND e.panne = 0)
122 WHERE a.alias = {?}
123 GROUP BY u.user_id", $alias);
124 if ($x = $sel->fetchOneAssoc()) {
125 $csv .= $x['nom'].';'.$x['prenom'].';' .$x['promo'].';'.$alias.';' . join(',', $mails) . ';'.$x['nb_mails']."\n";
126 }
127}
128
129$fo = fopen($output, 'w+');
130fwrite($fo, $csv);
131fclose($fo);
132
133?>