834fd0f6 |
1 | #!/usr/bin/php5 -q |
2 | <?php |
3 | /*************************************************************************** |
4 | * Copyright (C) 2003-2007 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 | require('./connect.db.inc.php'); |
24 | $sent_mails = 0; |
25 | $handler = time(); |
26 | |
27 | while ($sent_mails < $globals->lists->max_mail_per_min |
28 | && time() - $handler < 60) { |
29 | // take a lock on a mail |
30 | XDB::execute("UPDATE ml_moderate |
31 | SET handler = {?} |
32 | WHERE handler IS NULL |
33 | ORDER BY ts |
34 | LIMIT 1", $handler); |
35 | if (XDB::affectedRows() == 0) { |
36 | break; |
37 | } |
38 | $query = XDB::query("SELECT nom, prenom, user_id, password, |
39 | ml, domain, mid, action, message |
40 | FROM auth_user_md5 AS u |
41 | INNER JOIN ml_moderate AS ml ON (u.user_id = ml.uid) |
42 | WHERE ml.handler = {?}", $handler); |
43 | list($nom, $prenom, $uid, $password, $list, $domain, $mid, $action, $reason) = $query->fetchOneRow(); |
44 | |
45 | // build the client |
46 | $client = new MMList($uid, $password, $domain); |
47 | |
48 | // send the mail |
49 | $mail = $client->get_pending_mail($list, $mid); |
50 | list($det,$mem,$own) = $client->get_members($list); |
51 | $count = 0; |
52 | switch ($action) { |
53 | case 'accept': |
54 | $action = 1; /** 1 = ACCEPT **/ |
55 | $subject = "Message accepté"; |
56 | $append = "a été accepté par $prenom $nom.\n"; |
57 | $count += count($mem) + count($own); |
58 | break; |
59 | case 'refuse': |
60 | $action = 2; /** 2 = REJECT **/ |
61 | $subject = "Message refusé"; |
62 | $append = "a été refusé par $prenom $nom avec la raison :\n\n" . $reason; |
63 | $count += count($own) + 1; |
64 | break; |
65 | case 'delete': |
66 | $action = 3; /** 3 = DISCARD **/ |
67 | $subject = "Message supprimé"; |
68 | $append = "a été supprimé par $prenom $nom.\n\n" |
69 | . "Rappel: il ne faut utiliser cette opération " |
70 | . "que dans le cas de spams ou de virus !\n"; |
71 | $count += $count($own); |
72 | break; |
73 | } |
74 | |
75 | if ($client->handle_request($list, $mid, $action, $reason)) { |
76 | $sent_mails += $count; |
77 | $texte = "le message suivant :\n\n" |
78 | . " Auteur: {$mail['sender']}\n" |
79 | . " Sujet : « {$mail['subj']} »\n" |
80 | . " Date : ".strftime("le %d %b %Y à %H:%M:%S", (int)$mail['stamp'])."\n\n" |
81 | . $append; |
82 | $mailer = new PlMailer(); |
83 | $mailer->addTo("$list-owner@{$domain}"); |
84 | $mailer->setFrom("$list-bounces@{$domain}"); |
85 | $mailer->addHeader('Reply-To', "$list-owner@{$domain}"); |
86 | $mailer->setSubject($subject); |
87 | $mailer->setTxtBody($texte); |
88 | $mailer->send(); |
89 | } |
90 | |
91 | // release the lock |
92 | XDB::execute("DELETE FROM ml_moderate WHERE handler = {?}", |
93 | $handler); |
94 | sleep(60 * $count / $globals->lists->max_mail_per_min); |
95 | } |
96 | |
97 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
98 | ?> |