From: Vsevolod Stakhov Date: Mon, 29 Apr 2019 11:27:48 +0000 (+0100) Subject: [Minor] Some more additions to least actions processing logic X-Git-Tag: 1.9.3~56 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=622bad3d8a52fc810070bb000025c642e5a0695f;p=rspamd.git [Minor] Some more additions to least actions processing logic --- diff --git a/src/libmime/filter.c b/src/libmime/filter.c index a454cb8df..3550370ed 100644 --- a/src/libmime/filter.c +++ b/src/libmime/filter.c @@ -495,7 +495,7 @@ rspamd_check_action_metric (struct rspamd_task *task) { struct rspamd_action_result *action_lim, *noaction = NULL; - struct rspamd_action *selected_action = NULL; + struct rspamd_action *selected_action = NULL, *least_action = NULL; struct rspamd_passthrough_result *pr; double max_score = -(G_MAXDOUBLE), sc; int i; @@ -522,12 +522,32 @@ rspamd_check_action_metric (struct rspamd_task *task) } else { seen_least = true; + least_action = selected_action; if (isnan (sc)) { - sc = selected_action->threshold; - } - max_score = sc; + if (selected_action->flags & RSPAMD_ACTION_NO_THRESHOLD) { + /* + * In this case, we have a passthrough action that + * is `least` action, however, there is no threshold + * on it. + * + * Hence, we imply the following logic: + * + * - we leave score unchanged + * - we apply passthrough no threshold action unless + * score based action *is not* reject, otherwise + * we apply reject action + */ + } + else { + sc = selected_action->threshold; + max_score = sc; + } + } + else { + max_score = sc; + } } } } @@ -563,7 +583,18 @@ rspamd_check_action_metric (struct rspamd_task *task) if (selected_action) { if (seen_least) { - mres->score = MAX (max_score, mres->score); + + if (least_action->flags & RSPAMD_ACTION_NO_THRESHOLD) { + if (selected_action->action_type != METRIC_ACTION_REJECT && + selected_action->action_type != METRIC_ACTION_DISCARD) { + /* Override score based action with least action */ + selected_action = least_action; + } + } + else { + /* Adjust score if needed */ + mres->score = MAX (max_score, mres->score); + } } return selected_action; diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index fc61eae6b..278a0a466 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -285,11 +285,11 @@ enum rspamd_action_type { }; enum rspamd_action_flags { - RSPAMD_ACTION_NORMAL = 0, - RSPAMD_ACTION_NO_THRESHOLD = (1u << 0), - RSPAMD_ACTION_THRESHOLD_ONLY = (1u << 1), - RSPAMD_ACTION_HAM = (1u << 2), - RSPAMD_ACTION_MILTER = (1u << 3), + RSPAMD_ACTION_NORMAL = 0u, + RSPAMD_ACTION_NO_THRESHOLD = (1u << 0u), + RSPAMD_ACTION_THRESHOLD_ONLY = (1u << 1u), + RSPAMD_ACTION_HAM = (1u << 2u), + RSPAMD_ACTION_MILTER = (1u << 3u), };