3 /***************************************************************************
4 * Copyright (C) 2003-2013 Polytechnique.org *
5 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
21 ***************************************************************************/
23 /* Number of consecutive month of bounce before deactivating a redirection
27 require './connect.db.inc.php';
28 require 'Console/Getopt.php';
31 * Parse the command-line options.
33 $opts = Console_GetOpt
::getopt($argv, 'v');
36 if (PEAR
::isError($opts)) {
37 echo $opts->getMessage();
40 foreach ($opts as $opt) {
48 * Check duplicated addresses
50 $it = Xdb
::iterRow("SELECT s1.email, s2.email, r1.redirect
51 FROM email_redirect_account AS r1
52 INNER JOIN email_redirect_account AS r2 ON (r1.redirect = r2.redirect AND r1.uid != r2.uid)
53 INNER JOIN email_source_account AS s1 ON (s1.uid = r1.uid AND s1.type = 'forlife')
54 INNER JOIN email_source_account AS s2 ON (s2.uid = r2.uid AND s2.type = 'forlife')
55 LEFT JOIN email_watch AS w ON (r1.redirect = w.email)
58 ORDER BY r1.redirect, s1.email");
62 while (list($alias1, $alias2, $mail) = $it->next()) {
63 $insert[] = "('$mail', 'pending', CURDATE(), NOW())";
64 $conflits[] = "* $mail sur $alias1 et $alias2";
67 if (count($conflits) > 0) {
68 echo "Nouvelles adresses en doublon détectées :\n" . join("\n", $conflits)
69 . "\n\nVous pouvez entrer les informations collectées à ce sujet sur la page :\n"
70 . "https://www.polytechnique.org/admin/emails/duplicated";
73 $sql = "INSERT IGNORE INTO email_watch (email, state, detection, last)
74 VALUES " . join(", ", $insert);
76 if (XDB
::errno() != 0) {
77 echo 'Error : ' . XDB
::error() . "\n$sql";
84 if ($panne_level > 0) {
85 $res = XDB
::fetchAllAssoc("SELECT r.redirect, a.hruid
86 FROM email_redirect_account AS r
87 INNER JOIN accounts AS a ON (a.uid = r.uid)
88 WHERE r.broken_level = {?} AND r.flags != 'broken'
93 echo "Nouvelles adresses en panne detectees :\n";
94 foreach ($res as $assoc) {
95 echo '* ' . $assoc['redirect'] . ' pour ' . $assoc['hruid'] . "\n";
99 Xdb
::execute("UPDATE email_redirect_account
101 WHERE broken_level = 3");
104 Xdb
::execute('UPDATE email_redirect_account
105 SET broken_level = {?}
106 WHERE broken_level > {?}',
107 $panne_level, $panne_level);
111 * Retrieve the users with no active redirection, but still one working
112 * inactive redirection.
115 $res = XDB
::fetchAllAssoc("SELECT a.hruid, r2.redirect
117 LEFT JOIN email_redirect_account AS r1 ON (a.uid = r1.uid AND r1.flags = 'active')
118 INNER JOIN email_redirect_account AS r2 ON (a.uid = r2.uid AND r2.flags = 'inactive'
119 AND r2.type != 'imap' AND r2.type != 'homonym')
124 echo "Camarades n'ayant plus d'adresses actives, mais ayant une adresse inactive :\n";
125 foreach ($res as $user) {
126 echo '* ' . $user['redirect'] . ' pour ' . $user['hruid'] . "\n";
133 * Updates imap settings for users with no active redirection. Their emails
134 * must go to imap and bounce.
136 XDB
::execute("UPDATE email_redirect_account AS r
137 LEFT JOIN email_redirect_account AS a ON (r.uid = a.uid AND a.flags = 'active' AND a.type != 'imap')
138 SET r.action = 'imap_and_bounce'
139 WHERE r.type = 'imap' AND a.redirect IS NULL");
142 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: