Browse Source

[Feature] Correctly work when there is no hard reject action

pull/767/head
Vsevolod Stakhov 9 years ago
parent
commit
1b152c5db8
  1. 2
      src/libmime/message.c
  2. 26
      src/libserver/protocol.c
  3. 2
      src/libserver/roll_history.c
  4. 3
      src/libserver/symbols_cache.c
  5. 24
      src/libserver/task.c
  6. 10
      src/libserver/task.h
  7. 2
      src/libstat/stat_process.c
  8. 8
      src/lua/lua_task.c

2
src/libmime/message.c

@ -1012,7 +1012,7 @@ process_text_part (struct rspamd_task *task,
mres = rspamd_create_metric_result (task, DEFAULT_METRIC);
if (mres != NULL) {
mres->score = mres->metric->actions[METRIC_ACTION_REJECT].score;
mres->score = rspamd_task_get_required_score (task, mres);
mres->action = METRIC_ACTION_REJECT;
}

26
src/libserver/protocol.c

@ -853,22 +853,25 @@ rspamd_metric_result_ucl (struct rspamd_task *task,
is_spam = (action < METRIC_ACTION_GREYLIST);
obj = ucl_object_typed_new (UCL_OBJECT);
ucl_object_insert_key (obj, ucl_object_frombool (is_spam),
"is_spam", 0, false);
ucl_object_insert_key (obj, ucl_object_frombool (RSPAMD_TASK_IS_SKIPPED (task)),
"is_skipped", 0, false);
ucl_object_insert_key (obj,
ucl_object_frombool (is_spam),
"is_spam", 0, false);
ucl_object_insert_key (obj,
ucl_object_frombool (RSPAMD_TASK_IS_SKIPPED (task)),
"is_skipped", 0, false);
ucl_object_insert_key (obj, ucl_object_fromdouble (mres->score),
"score", 0, false);
ucl_object_insert_key (obj, ucl_object_fromdouble (mres->actions_limits[METRIC_ACTION_REJECT]),
"required_score", 0, false);
"score", 0, false);
ucl_object_insert_key (obj,
ucl_object_fromdouble (rspamd_task_get_required_score (task, mres)),
"required_score", 0, false);
ucl_object_insert_key (obj,
ucl_object_fromstring (rspamd_action_to_str (action)),
"action", 0, false);
ucl_object_fromstring (rspamd_action_to_str (action)),
"action", 0, false);
if (action == METRIC_ACTION_REWRITE_SUBJECT) {
subject = make_rewritten_subject (m, task);
ucl_object_insert_key (obj, ucl_object_fromstring (subject),
"subject", 0, false);
"subject", 0, false);
}
/* Now handle symbols */
g_hash_table_iter_init (&hiter, mres->symbols);
@ -1162,7 +1165,8 @@ rspamd_protocol_write_log_pipe (struct rspamd_worker_ctx *ctx,
}
ls->score = mres->score;
ls->required_score = mres->actions_limits[METRIC_ACTION_REJECT];
ls->required_score = rspamd_task_get_required_score (task,
mres);
ls->nresults = g_hash_table_size (mres->symbols);
g_hash_table_iter_init (&it, mres->symbols);

2
src/libserver/roll_history.c

@ -125,7 +125,7 @@ rspamd_roll_history_update (struct roll_history *history,
else {
row->score = metric_res->score;
row->action = rspamd_check_action_metric (task, metric_res);
row->required_score = metric_res->actions_limits[METRIC_ACTION_REJECT];
row->required_score = rspamd_task_get_required_score (task, metric_res);
cbdata.pos = row->symbols;
cbdata.remain = sizeof (row->symbols);
g_hash_table_foreach (metric_res->symbols,

3
src/libserver/symbols_cache.c

@ -1049,8 +1049,7 @@ rspamd_symbols_cache_metric_limit (struct rspamd_task *task,
res = g_hash_table_lookup (task->results, metric->name);
if (res) {
ms = res->actions_limits[METRIC_ACTION_REJECT];
ms = rspamd_task_get_required_score (task, res);
if (!isnan (ms) && cp->lim < ms) {
cp->rs = res;

24
src/libserver/task.c

@ -900,7 +900,7 @@ rspamd_task_log_metric_res (struct rspamd_task *task,
break;
case RSPAMD_LOG_SCORES:
res.len = rspamd_snprintf (scorebuf, sizeof (scorebuf), "%.2f/%.2f",
mres->score, mres->actions_limits[METRIC_ACTION_REJECT]);
mres->score, rspamd_task_get_required_score (task, mres));
res.begin = scorebuf;
break;
case RSPAMD_LOG_SYMBOLS:
@ -1291,3 +1291,25 @@ rspamd_task_write_log (struct rspamd_task *task)
rspamd_fstring_free (logbuf);
}
gdouble
rspamd_task_get_required_score (struct rspamd_task *task, struct metric_result *m)
{
guint i;
if (m == NULL) {
m = g_hash_table_lookup (task->results, DEFAULT_METRIC);
if (m == NULL) {
return NAN;
}
}
for (i = METRIC_ACTION_REJECT; i < METRIC_ACTION_MAX; i ++) {
if (!isnan (m->actions_limits[i])) {
return m->actions_limits[i];
}
}
return NAN;
}

10
src/libserver/task.h

@ -266,6 +266,16 @@ gboolean rspamd_learn_task_spam (struct rspamd_task *task,
const gchar *classifier,
GError **err);
/**
* Returns required score for a message (usually reject score)
* @param task
* @param m
* @return
*/
struct metric_result;
gdouble rspamd_task_get_required_score (struct rspamd_task *task,
struct metric_result *m);
/**
* Write log line about the specified task if needed
*/

2
src/libstat/stat_process.c

@ -850,7 +850,7 @@ rspamd_stat_check_autolearn (struct rspamd_task *task)
mres->action = rspamd_check_action_metric (task, mres);
}
if (mres->action == METRIC_ACTION_REJECT) {
if (mres->score > rspamd_task_get_required_score (task, mres)) {
task->flags |= RSPAMD_TASK_FLAG_LEARN_SPAM;
ret = TRUE;

8
src/lua/lua_task.c

@ -3009,6 +3009,7 @@ lua_task_get_metric_score (lua_State *L)
{
struct rspamd_task *task = lua_check_task (L, 1);
const gchar *metric_name;
gdouble rs;
struct metric_result *metric_res;
metric_name = luaL_checkstring (L, 2);
@ -3018,12 +3019,11 @@ lua_task_get_metric_score (lua_State *L)
g_hash_table_lookup (task->results, metric_name)) != NULL) {
lua_newtable (L);
lua_pushnumber (L, metric_res->score);
rs = rspamd_task_get_required_score (task, metric_res);
lua_rawseti (L, -2, 1);
lua_pushnumber (L,
metric_res->metric->actions[METRIC_ACTION_REJECT].score);
lua_pushnumber (L, rs);
lua_rawseti (L, -2, 2);
lua_pushnumber (L,
metric_res->metric->actions[METRIC_ACTION_REJECT].score);
lua_pushnumber (L, rs);
lua_rawseti (L, -2, 3);
}
else {

Loading…
Cancel
Save