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