summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-07-27 15:02:20 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-07-27 15:02:20 +0100
commit1b152c5db87f6bc306e51a24b5024d0083f9b1bb (patch)
treedf603d47ab1df7d87c1de112d91da5cc87c2f6bd /src
parent874af6856f4362ab6077b37a5defa8f3aa13d395 (diff)
downloadrspamd-1b152c5db87f6bc306e51a24b5024d0083f9b1bb.tar.gz
rspamd-1b152c5db87f6bc306e51a24b5024d0083f9b1bb.zip
[Feature] Correctly work when there is no hard reject action
Diffstat (limited to 'src')
-rw-r--r--src/libmime/message.c2
-rw-r--r--src/libserver/protocol.c26
-rw-r--r--src/libserver/roll_history.c2
-rw-r--r--src/libserver/symbols_cache.c3
-rw-r--r--src/libserver/task.c24
-rw-r--r--src/libserver/task.h10
-rw-r--r--src/libstat/stat_process.c2
-rw-r--r--src/lua/lua_task.c8
8 files changed, 56 insertions, 21 deletions
diff --git a/src/libmime/message.c b/src/libmime/message.c
index 89ccff68b..17680d3cd 100644
--- a/src/libmime/message.c
+++ b/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;
}
diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c
index e7192dff2..cb1e3dc30 100644
--- a/src/libserver/protocol.c
+++ b/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);
diff --git a/src/libserver/roll_history.c b/src/libserver/roll_history.c
index 812df927e..7cc0490c1 100644
--- a/src/libserver/roll_history.c
+++ b/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,
diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c
index b4a3275d8..2e32c9c6c 100644
--- a/src/libserver/symbols_cache.c
+++ b/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;
diff --git a/src/libserver/task.c b/src/libserver/task.c
index 2e250eaaa..086a25e7d 100644
--- a/src/libserver/task.c
+++ b/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;
+}
diff --git a/src/libserver/task.h b/src/libserver/task.h
index 4fb2ba3e3..80fdb82a3 100644
--- a/src/libserver/task.h
+++ b/src/libserver/task.h
@@ -267,6 +267,16 @@ gboolean rspamd_learn_task_spam (struct rspamd_task *task,
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
*/
void rspamd_task_write_log (struct rspamd_task *task);
diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c
index 5c39cd8d8..00e7ded4c 100644
--- a/src/libstat/stat_process.c
+++ b/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;
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index e11c3e5c1..a47516203 100644
--- a/src/lua/lua_task.c
+++ b/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 {