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;
}
}
msg_debug_task ("symbol %s, score %.2f, factor: %f",
- symbol,
- s->score,
- w);
- metric_res->changes ++;
+ symbol,
+ s->score,
+ w);
return s;
}
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++) {
}
if (selected_action) {
- if (set_action) {
- mres->action = selected_action->action;
- }
-
return selected_action->action;
}
* @param {number} score the current score of the metric
*/
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
*/
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}
};
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),
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}
};
{
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;
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;
}
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");
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
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
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
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)