From 3b346b99fd10a34dc4ac85af9da1abb778db8154 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Thu, 3 Mar 2011 19:15:52 +0100 Subject: [PATCH] Allows antispam level choice for each redirection. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- ChangeLog | 3 ++ configs/platal.ini | 3 ++ include/emails.inc.php | 58 ++++++++++++++++++++------ modules/email.php | 15 +++++-- templates/emails/antispam.tpl | 95 +++++++++++++++++++++++++++++++++++-------- 5 files changed, 139 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 51a1b29..e697fe5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,9 @@ Bug/Wish: - #1399: Displays all similar entreprises only on demand -JAC - #1403: Displays grade if any in medal validation process -JAC + * Emails: + - Allows antispam level choice for each redirection -JAC + * Payments: - #1398: Creates csv for payments -JAC diff --git a/configs/platal.ini b/configs/platal.ini index 458ef35..c7e159e 100644 --- a/configs/platal.ini +++ b/configs/platal.ini @@ -288,6 +288,9 @@ blacklist_host_resolution_limit = ; domain is blacklisted by a spam filter. domain_whitelist = "" +; $globals->mail->antispam +; Default antispam level. +antispam = "" ; The mailstorage section contains parameters describing the availability of email storage services [MailStorage] diff --git a/include/emails.inc.php b/include/emails.inc.php index a48da50..c09a7b4 100644 --- a/include/emails.inc.php +++ b/include/emails.inc.php @@ -296,10 +296,19 @@ function ids_from_mails(array $emails) // The Bogo class represents a spam filtering level in plat/al architecture. class Bogo { - private static $states = array('let_spams', 'tag_spams', 'tag_and_drop_spams', 'drop_spams'); + private static $states = array( + 0 => 'default', + 1 => 'let_spams', + 2 => 'tag_spams', + 3 => 'tag_and_drop_spams', + 4 => 'drop_spams' + ); private $user; - private $state; + public $state; + public $single_state; + public $redirections; + public $single_redirection; public function __construct(User $user) { @@ -308,28 +317,51 @@ class Bogo } $this->user = &$user; - $res = XDB::query('SELECT action - FROM email_redirect_account - WHERE uid = {?} AND (type = \'smtp\' OR type = \'googleapps\')', - $user->id()); - if ($res->numRows() == 0) { + $res = XDB::fetchOneAssoc('SELECT COUNT(DISTINCT(action)) AS action_count, COUNT(redirect) AS redirect_count, action + FROM email_redirect_account + WHERE uid = {?} AND (type = \'smtp\' OR type = \'googleapps\') AND flags = \'active\'', + $user->id()); + if ($res['redirect_count'] == 0) { return; } - $this->state = $res->fetchOneCell(); + + $this->single_redirection = ($res['redirect_count'] == 1); + $this->redirections = XDB::fetchAllAssoc('SELECT IF(type = \'googleapps\', type, redirect) AS redirect, type, action + FROM email_redirect_account + WHERE uid = {?} AND (type = \'smtp\' OR type = \'googleapps\') + ORDER BY type, redirect', + $user->id()); + + foreach ($this->redirections AS &$redirection) { + $redirection['filter'] = array_search($redirection['action'], self::$states); + } + if ($res['action_count'] == 1) { + $this->state = array_search($res['action'], self::$states); + $this->single_state = true; + } else { + $this->single_state = $this->state = false; + } } - public function change($state) + public function changeAll($state) { - $this->state = is_int($state) ? self::$states[$state] : $state; + Platal::assert($state >= 0 && $state < count(self::$states), 'Unknown antispam level.'); + + $this->state = $state; XDB::execute('UPDATE email_redirect_account SET action = {?} WHERE uid = {?} AND (type = \'smtp\' OR type = \'googleapps\')', - $this->state, $this->user->id()); + self::$states[$this->state], $this->user->id()); } - public function level() + public function change($redirection, $state) { - return array_search($this->state, self::$states); + Platal::assert($state >= 0 && $state < count(self::$states), 'Unknown antispam level.'); + + XDB::execute('UPDATE email_redirect_account + SET action = {?} + WHERE uid = {?} AND (type = {?} OR redirect = {?})', + self::$states[$state], $this->user->id(), $redirection, $redirection); } } diff --git a/modules/email.php b/modules/email.php index d70da2c..e080e48 100644 --- a/modules/email.php +++ b/modules/email.php @@ -298,7 +298,7 @@ class EmailModule extends PLModule fill_email_combobox($page); } - function handler_antispam($page, $filter_status = null) + function handler_antispam($page, $filter_status = null, $redirection = null) { require_once 'emails.inc.php'; $wp = new PlWikiPage('Xorg.Antispam'); @@ -308,10 +308,17 @@ class EmailModule extends PLModule $user = S::user(); $bogo = new Bogo($user); - if (isset($filter_status)) { - $bogo->change($filter_status + 0); + if (!is_null($filter_status)) { + if (is_null($redirection)) { + $bogo->changeAll($filter_status); + } else { + $bogo->change($redirection, $filter_status); + } } - $page->assign('filter', $bogo->level()); + $page->assign('filter', $bogo->state); + $page->assign('single_state', $bogo->single_state); + $page->assign('single_redirection', $bogo->single_redirection); + $page->assign('redirections', $bogo->redirections); } function handler_submit($page) diff --git a/templates/emails/antispam.tpl b/templates/emails/antispam.tpl index e2af941..0c5e38b 100644 --- a/templates/emails/antispam.tpl +++ b/templates/emails/antispam.tpl @@ -26,29 +26,88 @@ {literal} $(function() { var url = '{/literal}{$globals->baseurl}/emails/antispam/{literal}'; - var msg = "Le changement de réglage de l'antispam a bien été effectué."; + var msg = "Le changement de réglage de l'antispam a bien été effectué pour toutes tes redirections."; $(':radio[name=filter_status]').change(function() { - $("#bogo-msg").successMessage(url + $(this).val(), msg); + var val = $(this).val(); + $(':radio[name*=filter_status_]').removeAttr('checked'); + $(':radio[name*=filter_status_]').attr('checked', function(i, v) { + if ($(this).val() == val) { + return 'checked'; + } + }); + $("#bogo-msg").successMessage(url + val, msg); + }); + }); + $(function() { + var url = '{/literal}{$globals->baseurl}/emails/antispam/{literal}'; + var msg = "Le changement de réglage de l'antispam a bien été effectué pour "; + $(':radio[name*=filter_status_]').change(function() { + var id = $(this).attr('name').replace('filter_status_', ''); + var redirection = $('#bogo_' + id).val(); + $(':radio[name=filter_status]').removeAttr('checked'); + $("#bogo-msg-mult").successMessage(url + $(this).val() + "/" + redirection, msg + redirection.replace('googleapps', 'ton compte Google Apps') + "."); }); }); {/literal} //]]> -
- Choisis ton propre réglage : - - -
- - -
- - -
- - -
- -

+
+ Choisis ton propre réglage : + {if !$single_state} + Attention, tu as actuellement un réglage spécifique pour chacune de tes redirections. + Les modifications dans ce cadre sont globales et entraineront une uniformisation de + l'antispam pour toutes tes redirections au niveau demandé. +
{/if} + + +
+ + +
+ + +
+ + +
+ + +
+ +

+ +{if !$single_redirection} +

Réglages avancés

+

+ Si tu le souhaites, tu peux adapter le niveau de ton antispam pour chacune de tes redirections. Par exemple, + tu peux éliminer tous les spams (niveau 4) vers ton adresse professionnelle, mais ne faire que marquer comme + spams (niveau 2) de tels emails vers ton adresse personnelle. +

+ +

+ +{foreach from=$redirections key=i item=redirection} +
+ {$redirection.redirect|replace:'googleapps':'Compte Google Apps'} : + + + +
+ + +
+ + +
+ + +
+ + +
+{/foreach} +{/if} {include wiki=Xorg.Antispam part=2} -- 2.1.4