Mailman don't understand UTF8 (Closes #761)
[platal.git] / bin / emails.broken.helper.php
1 #!/usr/bin/php5 -q
2 <?php
3 /***************************************************************************
4 * Copyright (C) 2003-2008 Polytechnique.org *
5 * http://opensource.polytechnique.org/ *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., *
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
21 ***************************************************************************/
22
23 ini_set('include_path', '.:../include:/usr/share/php');
24
25 require_once('connect.db.inc.php');
26 require_once('xorg.inc.php');
27 require_once('emails.inc.php');
28
29 $opts = getopt('o:');
30 if (($opts['o'] && $opts['o'] == '-') || empty($opts['o'])) {
31 printf("Usage: emails.broken.helper.php -o <file>\n");
32 exit(1);
33 } else {
34 $output = $opts['o'];
35 }
36
37 $input_fd = fopen("php://stdin", "r");
38 $output_fd = fopen($output, "a");
39
40 while ($_email = fgets($input_fd)) {
41 $_email = trim($_email);
42 $email = valide_email($_email);
43 if (empty($email) || $email=='@') {
44 printf(">> %s: invalid email\n", $_email);
45 continue;
46 }
47
48 $sel = XDB::query(
49 "SELECT e1.uid, e1.panne != 0 AS panne, count(e2.uid) AS nb_mails, u.nom, u.prenom, u.promo, a.alias
50 FROM emails AS e1
51 LEFT JOIN emails AS e2 ON (e1.uid = e2.uid AND FIND_IN_SET('active', e2.flags) AND e1.email != e2.email)
52 INNER JOIN auth_user_md5 AS u ON (e1.uid = u.user_id)
53 INNER JOIN aliases AS a ON (u.user_id = a.id AND FIND_IN_SET('bestalias',a.flags))
54 WHERE e1.email = {?}
55 GROUP BY e1.uid", $email);
56 if ($sel->numRows() > 0) {
57 fwrite($output_fd, $email . "\n");
58 } else {
59 printf(">> %s: email not in the database\n", $_email);
60 }
61 }
62
63 fclose($input_fd);
64 fclose($output_fd);
65
66 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
67 ?>