X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=bin%2Fcron%2Fcron_ml_moderate.php;h=52864d5b726e4b37cac10ca3a900852beda15786;hb=3424387cde6c635ff16c3b5459c4caa88bb76e2e;hp=e91d6e0825eac3eb36486fe42a82f7863e672487;hpb=1f58ccb1e75eca08fbd04971d617ea372bc77b5a;p=platal.git diff --git a/bin/cron/cron_ml_moderate.php b/bin/cron/cron_ml_moderate.php index e91d6e0..52864d5 100755 --- a/bin/cron/cron_ml_moderate.php +++ b/bin/cron/cron_ml_moderate.php @@ -1,7 +1,7 @@ #!/usr/bin/php5 -q lists->max_mail_per_min && time() - $handler < 60) { // take a lock on a mail - XDB::execute("UPDATE ml_moderate + XDB::execute('UPDATE email_list_moderate SET handler = {?} WHERE handler IS NULL ORDER BY ts - LIMIT 1", $handler); + LIMIT 1', $handler); if (XDB::affectedRows() == 0) { break; } - $query = XDB::query("SELECT nom, prenom, user_id, password, - ml, domain, mid, action, message - FROM auth_user_md5 AS u - INNER JOIN ml_moderate AS ml ON (u.user_id = ml.uid) - WHERE ml.handler = {?}", $handler); - list($nom, $prenom, $uid, $password, $list, $domain, $mid, $action, $reason) = $query->fetchOneRow(); - - // build the client - $client = new MMList($uid, $password, $domain); + $query = XDB::query('SELECT uid, ml, domain, mid, action, message + FROM email_list_moderate + WHERE handler = {?}', $handler); + list($uid, $list, $domain, $mid, $action, $reason) = $query->fetchOneRow(); + $user = User::get($uid); + $fullname = $user->fullName(); + $mlist = new MailingList($list, $domain, $user); // send the mail - $mail = $client->get_pending_mail($list, $mid); - list($det,$mem,$own) = $client->get_members($list); + $mail = $mlist->getPendingMail($mid); + list($det,$mem,$own) = $mlist->getMembers(); $count = 0; switch ($action) { case 'accept': - $action = 1; /** 1 = ACCEPT **/ + $action = MailingList::REQ_ACCEPT; $subject = "Message accepté"; - $append = "a été accepté par $prenom $nom.\n"; + $append = "a été accepté par $fullname.\n"; $type = 'nonspam'; $count += count($mem) + count($own); break; case 'refuse': - $action = 2; /** 2 = REJECT **/ + $action = MailingList::REQ_REJECT; $subject = "Message refusé"; - $append = "a été refusé par $prenom $nom avec la raison :\n\n" . $reason; + $append = "a été refusé par $fullname avec la raison :\n\n" . $reason; $type = 'nonspam'; $count += count($own) + 1; break; case 'delete': - $action = 3; /** 3 = DISCARD **/ + $action = MailingList::REQ_DISCARD; $subject = "Message supprimé"; - $append = "a été supprimé par $prenom $nom.\n\n" - . "Rappel: il ne faut utiliser cette opération " + $append = "a été supprimé par $fullname.\n\n" + . "Rappel : il ne faut utiliser cette opération " . "que dans le cas de spams ou de virus !\n"; $type = 'spam'; $count += count($own); @@ -78,7 +81,7 @@ while ($sent_mails < $globals->lists->max_mail_per_min } // if the mail was classified as Unsure, feed bogo - $raw_mail = html_entity_decode($client->get_pending_mail($list, $mid, 1)); + $raw_mail = html_entity_decode($mlist->getPendingMail($mid, 1)); // search for the X-Spam-Flag header $end_of_headers = strpos($raw_mail, "\r\n\r\n"); if ($end_of_headers === false) { // sometimes headers are separated by \n @@ -91,14 +94,14 @@ while ($sent_mails < $globals->lists->max_mail_per_min if ($x_spam_flag == 'Unsure') { $mailer = new PlMailer(); $mailer->addTo($type . '@' . $globals->mail->domain); - $mailer->setFrom('"' . $prenom . ' ' . $nom . '" mail->domain . '>'); - $mailer->setTxtBody($type . ' soumis par ' . $prenom . ' ' . $nom . ' via la modération de la liste ' . $list . '@' . $domain); + $mailer->setFrom('"' . $fullname . '" mail->domain . '>'); + $mailer->setTxtBody($type . ' soumis par ' . $fullname . ' via la modération de la liste ' . $list . '@' . $domain); $mailer->addAttachment($raw_mail, 'message/rfc822', $type . '.mail', false); $mailer->send(); } // send feedback to the mailing list owners - if ($client->handle_request($list, $mid, $action, utf8_decode($reason))) { + if ($mlist->handleRequest($action, $mid, $reason)) { $sent_mails += $count; $texte = "Le message suivant :\n\n" . " Auteur: {$mail['sender']}\n" @@ -115,10 +118,11 @@ while ($sent_mails < $globals->lists->max_mail_per_min } // release the lock - XDB::execute("DELETE FROM ml_moderate WHERE handler = {?}", + XDB::execute('DELETE FROM email_list_moderate + WHERE handler = {?}', $handler); sleep(60 * $count / $globals->lists->max_mail_per_min); } -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: ?>