diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libmime/filter.c | 22 | ||||
-rw-r--r-- | src/libmime/filter.h | 2 | ||||
-rw-r--r-- | src/libmime/message.c | 2 | ||||
-rw-r--r-- | src/libserver/composites.c | 2 | ||||
-rw-r--r-- | src/libserver/task.c | 7 | ||||
-rw-r--r-- | src/lua/lua_task.c | 59 | ||||
-rw-r--r-- | src/plugins/lua/greylist.lua | 8 | ||||
-rw-r--r-- | src/plugins/lua/metadata_exporter.lua | 2 |
8 files changed, 34 insertions, 70 deletions
diff --git a/src/libmime/filter.c b/src/libmime/filter.c index 5fd202f2a..1efe898ce 100644 --- a/src/libmime/filter.c +++ b/src/libmime/filter.c @@ -50,14 +50,11 @@ rspamd_create_metric_result (struct rspamd_task *task) metric_res->sym_groups); metric_res->grow_factor = 0; metric_res->score = 0; - metric_res->changes = 0; for (i = 0; i < METRIC_ACTION_MAX; i++) { metric_res->actions_limits[i] = task->cfg->actions[i].score; } - metric_res->action = METRIC_ACTION_MAX; - return metric_res; } @@ -244,10 +241,9 @@ insert_metric_result (struct rspamd_task *task, } msg_debug_task ("symbol %s, score %.2f, factor: %f", - symbol, - s->score, - w); - metric_res->changes ++; + symbol, + s->score, + w); return s; } @@ -355,14 +351,6 @@ rspamd_check_action_metric (struct rspamd_task *task, struct rspamd_metric_resul 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++) { @@ -413,10 +401,6 @@ 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/libmime/filter.h b/src/libmime/filter.h index 53d47a769..391441392 100644 --- a/src/libmime/filter.h +++ b/src/libmime/filter.h @@ -40,8 +40,6 @@ struct rspamd_metric_result { GHashTable *symbols; /**< symbols of metric */ GHashTable *sym_groups; /**< groups of symbols */ gdouble actions_limits[METRIC_ACTION_MAX]; /**< set of actions for this metric */ - guint changes; - enum rspamd_action_type action; /**< the current action */ }; /** diff --git a/src/libmime/message.c b/src/libmime/message.c index 5e1118fc2..756cd9b47 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -801,8 +801,6 @@ rspamd_message_process_text_part (struct rspamd_task *task, else { mres->score = mres->actions_limits[act]; } - - mres->action = act; } task->result = mres; diff --git a/src/libserver/composites.c b/src/libserver/composites.c index 6b6776f47..a90b5c032 100644 --- a/src/libserver/composites.c +++ b/src/libserver/composites.c @@ -433,8 +433,6 @@ composites_remove_symbols (gpointer key, gpointer value, gpointer data) cd->metric_res->score -= rd->ms->score; rd->ms->score = 0.0; } - - cd->metric_res->changes ++; } } diff --git a/src/libserver/task.c b/src/libserver/task.c index ce21523e7..71e38ed4c 100644 --- a/src/libserver/task.c +++ b/src/libserver/task.c @@ -1033,10 +1033,11 @@ rspamd_task_log_metric_res (struct rspamd_task *task, rspamd_fstring_t *symbuf; struct rspamd_symbol_result *sym; GPtrArray *sorted_symbols; + enum rspamd_action_type act; guint i, j; mres = task->result; - rspamd_check_action_metric (task, mres); + act = rspamd_check_action_metric (task, mres); if (mres != NULL) { switch (lf->type) { @@ -1044,7 +1045,7 @@ rspamd_task_log_metric_res (struct rspamd_task *task, if (RSPAMD_TASK_IS_SKIPPED (task)) { res.begin = "S"; } - else if (mres->action == METRIC_ACTION_REJECT) { + else if (act == METRIC_ACTION_REJECT) { res.begin = "T"; } else { @@ -1054,7 +1055,7 @@ rspamd_task_log_metric_res (struct rspamd_task *task, res.len = 1; break; case RSPAMD_LOG_ACTION: - res.begin = rspamd_action_to_str (mres->action); + res.begin = rspamd_action_to_str (act); res.len = strlen (res.begin); break; case RSPAMD_LOG_SCORES: diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index b0c7c8fd5..643737086 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -599,13 +599,6 @@ LUA_FUNCTION_DEF (task, get_metric_action); */ LUA_FUNCTION_DEF (task, set_metric_score); /*** - * @method task:set_metric_action(name, action) - * Set the current action of metric `name`. Should be used in post-filters only. - * @param {string} name name of a metric - * @param {string} action name to set - */ -LUA_FUNCTION_DEF (task, set_metric_action); -/*** * @method task:set_metric_subject(subject) * Set the subject in the default metric * @param {string} subject subject to set @@ -841,6 +834,15 @@ LUA_FUNCTION_DEF (task, get_protocol_reply); */ LUA_FUNCTION_DEF (task, headers_foreach); +/*** + * @method task:disable_action(action) + * Disables some action for this task (e.g. 'greylist') + * + * @param {string} action action to disable + * @return {boolean} true if an action was enabled and is disabled after the method call + */ +LUA_FUNCTION_DEF (task, disable_action); + static const struct luaL_reg tasklib_f[] = { {NULL, NULL} }; @@ -914,7 +916,6 @@ static const struct luaL_reg tasklib_m[] = { LUA_INTERFACE_DEF (task, get_metric_score), LUA_INTERFACE_DEF (task, get_metric_action), LUA_INTERFACE_DEF (task, set_metric_score), - LUA_INTERFACE_DEF (task, set_metric_action), LUA_INTERFACE_DEF (task, set_metric_subject), LUA_INTERFACE_DEF (task, learn), LUA_INTERFACE_DEF (task, set_settings), @@ -934,6 +935,7 @@ static const struct luaL_reg tasklib_m[] = { LUA_INTERFACE_DEF (task, store_in_file), LUA_INTERFACE_DEF (task, get_protocol_reply), LUA_INTERFACE_DEF (task, headers_foreach), + LUA_INTERFACE_DEF (task, disable_action), {"__tostring", rspamd_lua_class_tostring}, {NULL, NULL} }; @@ -1344,7 +1346,6 @@ lua_task_set_pre_result (lua_State * L) { struct rspamd_task *task = lua_check_task (L, 1); struct rspamd_config *cfg; - struct rspamd_metric_result *mres; gchar *action_str; gint action = METRIC_ACTION_MAX; @@ -1361,14 +1362,7 @@ lua_task_set_pre_result (lua_State * L) if (action < METRIC_ACTION_MAX && action >= METRIC_ACTION_REJECT) { /* We also need to set the default metric to that result */ if (!task->result) { - mres = rspamd_create_metric_result (task); - if (mres != NULL) { - mres->score = cfg->actions[action].score; - mres->action = action; - } - } - else { - task->result->action = action; + task->result = rspamd_create_metric_result (task); } task->pre_result.action = action; @@ -4227,35 +4221,26 @@ lua_task_set_metric_score (lua_State *L) } static gint -lua_task_set_metric_action (lua_State *L) +lua_task_disable_action (lua_State *L) { struct rspamd_task *task = lua_check_task (L, 1); - const gchar *metric_name, *action_name; + const gchar *action_name; struct rspamd_metric_result *metric_res; gint action; - metric_name = luaL_checkstring (L, 2); - - if (metric_name == NULL) { - metric_name = DEFAULT_METRIC; - } - - action_name = luaL_checkstring (L, 3); - - if (task && metric_name && action_name) { - if ((metric_res = task->result) != NULL) { + action_name = luaL_checkstring (L, 2); - if (rspamd_action_from_str (action_name, &action)) { - metric_res->action = action; - lua_pushboolean (L, true); - } - else { - lua_pushboolean (L, false); - } + if (task && action_name && rspamd_action_from_str (action_name, &action)) { + if (!task->result) { + task->result = rspamd_create_metric_result (task); } - else { + if (isnan (task->result->actions_limits[action])) { lua_pushboolean (L, false); } + else { + task->result->actions_limits[action] = NAN; + lua_pushboolean (L, true); + } } else { return luaL_error (L, "invalid arguments"); diff --git a/src/plugins/lua/greylist.lua b/src/plugins/lua/greylist.lua index a555fcfc8..8de4f69c8 100644 --- a/src/plugins/lua/greylist.lua +++ b/src/plugins/lua/greylist.lua @@ -256,7 +256,7 @@ local function greylist_set(task) if action == 'greylist' then -- We are going to accept message rspamd_logger.infox(task, 'Downgrading metric action from "greylist" to "no action"') - task:set_metric_action('default', 'no action') + task:disable_action('greylist') end return end @@ -266,7 +266,7 @@ local function greylist_set(task) if action == 'greylist' then -- We are going to accept message rspamd_logger.infox(task, 'Downgrading metric action from "greylist" to "no action"') - task:set_metric_action('default', 'no action') + task:disable_action('greylist') end return end @@ -276,7 +276,7 @@ local function greylist_set(task) if action == 'greylist' then -- We are going to accept message rspamd_logger.infox(task, 'Downgrading metric action from "greylist" to "no action"') - task:set_metric_action('default', 'no action') + task:disable_action('greylist') end return end @@ -320,7 +320,7 @@ local function greylist_set(task) if action == 'greylist' then -- We are going to accept message rspamd_logger.infox(task, 'Downgrading metric action from "greylist" to "no action"') - task:set_metric_action('default', 'no action') + task:disable_action('greylist') end task:insert_result(settings['symbol'], 0.0, 'pass', is_whitelisted) diff --git a/src/plugins/lua/metadata_exporter.lua b/src/plugins/lua/metadata_exporter.lua index 3569650ab..523b4251c 100644 --- a/src/plugins/lua/metadata_exporter.lua +++ b/src/plugins/lua/metadata_exporter.lua @@ -229,7 +229,7 @@ local selectors = { local function maybe_defer(task, rule) if rule.defer then rspamd_logger.warnx(task, 'deferring message') - task:set_metric_action('default', 'soft reject') + task:set_pre_result('soft reject', 'deferred') end end |