From 7a580591aabfda1fc1474c8baba45b8b9a679195 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 15 Mar 2018 14:00:10 +0000 Subject: [PATCH] [Fix] Improve cached action interaction --- src/libmime/filter.c | 14 ++++++++++++++ src/libserver/protocol.c | 7 +------ src/libserver/roll_history.c | 2 +- src/libserver/task.c | 1 + src/libstat/stat_process.c | 3 --- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/libmime/filter.c b/src/libmime/filter.c index 59765ea59..08a589189 100644 --- a/src/libmime/filter.c +++ b/src/libmime/filter.c @@ -353,7 +353,17 @@ rspamd_check_action_metric (struct rspamd_task *task, struct rspamd_metric_resul struct rspamd_action *action, *selected_action = NULL; double max_score = -(G_MAXDOUBLE), sc; int i; + gboolean set_action = FALSE; + if (task->processed_stages | (RSPAMD_TASK_STAGE_DONE|RSPAMD_TASK_STAGE_IDEMPOTENT)) { + if (mres->action != METRIC_ACTION_MAX) { + return mres->action; + } + + set_action = TRUE; + } + + /* We are not certain about the results during processing */ if (task->pre_result.action == METRIC_ACTION_MAX) { for (i = METRIC_ACTION_REJECT; i < METRIC_ACTION_MAX; i++) { action = &task->cfg->actions[i]; @@ -399,6 +409,10 @@ rspamd_check_action_metric (struct rspamd_task *task, struct rspamd_metric_resul } if (selected_action) { + if (set_action) { + mres->action = selected_action->action; + } + return selected_action->action; } diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c index d9bcecb63..103ad8588 100644 --- a/src/libserver/protocol.c +++ b/src/libserver/protocol.c @@ -1376,12 +1376,7 @@ end: if (metric_res != NULL) { - if (metric_res->action != METRIC_ACTION_MAX) { - action = metric_res->action; - } - else { - action = rspamd_check_action_metric (task, metric_res); - } + action = rspamd_check_action_metric (task, metric_res); if (action == METRIC_ACTION_SOFT_REJECT && (task->flags & RSPAMD_TASK_FLAG_GREYLISTED)) { diff --git a/src/libserver/roll_history.c b/src/libserver/roll_history.c index 01aa9f88a..4d1d34bd9 100644 --- a/src/libserver/roll_history.c +++ b/src/libserver/roll_history.c @@ -151,7 +151,7 @@ rspamd_roll_history_update (struct roll_history *history, } else { row->score = metric_res->score; - row->action = metric_res->action; + row->action = rspamd_check_action_metric (task, metric_res); row->required_score = rspamd_task_get_required_score (task, metric_res); cbdata.pos = row->symbols; cbdata.remain = sizeof (row->symbols); diff --git a/src/libserver/task.c b/src/libserver/task.c index 55a00649d..ce21523e7 100644 --- a/src/libserver/task.c +++ b/src/libserver/task.c @@ -1036,6 +1036,7 @@ rspamd_task_log_metric_res (struct rspamd_task *task, guint i, j; mres = task->result; + rspamd_check_action_metric (task, mres); if (mres != NULL) { switch (lf->type) { diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c index 2284907a1..aed9d383d 100644 --- a/src/libstat/stat_process.c +++ b/src/libstat/stat_process.c @@ -1121,9 +1121,6 @@ rspamd_stat_check_autolearn (struct rspamd_task *task) mres = task->result; if (mres) { - - mres->action = rspamd_check_action_metric (task, mres); - if (mres->score > rspamd_task_get_required_score (task, mres)) { task->flags |= RSPAMD_TASK_FLAG_LEARN_SPAM; -- 2.39.5