Commit | Line | Data |
---|---|---|
834fd0f6 | 1 | #!/usr/bin/php5 -q |
2 | <?php | |
3 | /*************************************************************************** | |
9f5bd98e | 4 | * Copyright (C) 2003-2010 Polytechnique.org * |
834fd0f6 | 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 | ||
60e3880a | 23 | require './connect.db.inc.php'; |
636987ce | 24 | ini_set('max_execution_time', '75'); |
dc3441ff | 25 | ini_set('memory_limit', '128M'); |
834fd0f6 | 26 | $sent_mails = 0; |
27 | $handler = time(); | |
28 | ||
29 | while ($sent_mails < $globals->lists->max_mail_per_min | |
30 | && time() - $handler < 60) { | |
31 | // take a lock on a mail | |
5ecaa68e | 32 | XDB::execute('UPDATE email_list_moderate |
834fd0f6 | 33 | SET handler = {?} |
34 | WHERE handler IS NULL | |
35 | ORDER BY ts | |
5ecaa68e | 36 | LIMIT 1', $handler); |
834fd0f6 | 37 | if (XDB::affectedRows() == 0) { |
38 | break; | |
39 | } | |
60e3880a SJ |
40 | $query = XDB::query('SELECT a.fullname, a.uid, a.password, |
41 | ml.ml, ml.domain, ml.mid, ml.action, ml.message | |
5ecaa68e | 42 | FROM accounts AS a |
60e3880a SJ |
43 | INNER JOIN email_list_moderate AS ml ON (a.uid = ml.uid) |
44 | WHERE ml.handler = {?}', $handler); | |
45 | list($fullname, $uid, $password, $list, $domain, $mid, $action, $reason) = $query->fetchOneRow(); | |
834fd0f6 | 46 | |
47 | // build the client | |
48 | $client = new MMList($uid, $password, $domain); | |
49 | ||
50 | // send the mail | |
5ecaa68e | 51 | $mail = $client->get_pending_mail($list, $mid); |
834fd0f6 | 52 | list($det,$mem,$own) = $client->get_members($list); |
53 | $count = 0; | |
54 | switch ($action) { | |
55 | case 'accept': | |
56 | $action = 1; /** 1 = ACCEPT **/ | |
57 | $subject = "Message accepté"; | |
60e3880a | 58 | $append = "a été accepté par $fullname.\n"; |
a7c55d51 | 59 | $type = 'nonspam'; |
834fd0f6 | 60 | $count += count($mem) + count($own); |
61 | break; | |
62 | case 'refuse': | |
63 | $action = 2; /** 2 = REJECT **/ | |
64 | $subject = "Message refusé"; | |
60e3880a | 65 | $append = "a été refusé par $fullname avec la raison :\n\n" . $reason; |
a7c55d51 | 66 | $type = 'nonspam'; |
834fd0f6 | 67 | $count += count($own) + 1; |
68 | break; | |
69 | case 'delete': | |
70 | $action = 3; /** 3 = DISCARD **/ | |
71 | $subject = "Message supprimé"; | |
60e3880a | 72 | $append = "a été supprimé par $fullname.\n\n" |
5ecaa68e | 73 | . "Rappel : il ne faut utiliser cette opération " |
834fd0f6 | 74 | . "que dans le cas de spams ou de virus !\n"; |
a7c55d51 | 75 | $type = 'spam'; |
ceb2a271 | 76 | $count += count($own); |
834fd0f6 | 77 | break; |
78 | } | |
79 | ||
a7c55d51 AA |
80 | // if the mail was classified as Unsure, feed bogo |
81 | $raw_mail = html_entity_decode($client->get_pending_mail($list, $mid, 1)); | |
82 | // search for the X-Spam-Flag header | |
83 | $end_of_headers = strpos($raw_mail, "\r\n\r\n"); | |
dc3441ff | 84 | if ($end_of_headers === false) { // sometimes headers are separated by \n |
a7c55d51 | 85 | $end_of_headers = strpos($raw_mail, "\n\n"); |
dc3441ff | 86 | } |
a7c55d51 | 87 | $x_spam_flag = ''; |
734e15dc | 88 | if (preg_match('/^X-Spam-Flag: ([a-zA-Z]+), tests=bogofilter/m', substr($raw_mail, 0, $end_of_headers + 1), $matches)) { |
a7c55d51 | 89 | $x_spam_flag = $matches[1]; |
dc3441ff | 90 | } |
a7c55d51 | 91 | if ($x_spam_flag == 'Unsure') { |
dc3441ff AA |
92 | $mailer = new PlMailer(); |
93 | $mailer->addTo($type . '@' . $globals->mail->domain); | |
60e3880a SJ |
94 | $mailer->setFrom('"' . $fullname . '" <web@' . $globals->mail->domain . '>'); |
95 | $mailer->setTxtBody($type . ' soumis par ' . $fullname . ' via la modération de la liste ' . $list . '@' . $domain); | |
dc3441ff AA |
96 | $mailer->addAttachment($raw_mail, 'message/rfc822', $type . '.mail', false); |
97 | $mailer->send(); | |
98 | } | |
a7c55d51 | 99 | |
85d7633f AA |
100 | // send feedback to the mailing list owners |
101 | if ($client->handle_request($list, $mid, $action, utf8_decode($reason))) { | |
102 | $sent_mails += $count; | |
3e9cfdad | 103 | $texte = "Le message suivant :\n\n" |
85d7633f AA |
104 | . " Auteur: {$mail['sender']}\n" |
105 | . " Sujet : « {$mail['subj']} »\n" | |
106 | . " Date : ".strftime("le %d %b %Y à %H:%M:%S", (int)$mail['stamp'])."\n\n" | |
107 | . $append; | |
108 | $mailer = new PlMailer(); | |
109 | $mailer->addTo("$list-owner@{$domain}"); | |
110 | $mailer->setFrom("$list-bounces@{$domain}"); | |
111 | $mailer->addHeader('Reply-To', "$list-owner@{$domain}"); | |
112 | $mailer->setSubject($subject); | |
113 | $mailer->setTxtBody($texte); | |
114 | $mailer->send(); | |
115 | } | |
116 | ||
834fd0f6 | 117 | // release the lock |
5ecaa68e SJ |
118 | XDB::execute('DELETE FROM email_list_moderate |
119 | WHERE handler = {?}', | |
834fd0f6 | 120 | $handler); |
121 | sleep(60 * $count / $globals->lists->max_mail_per_min); | |
122 | } | |
123 | ||
124 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
125 | ?> |