]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Correctly work when there is no hard reject action
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 27 Jul 2016 14:02:20 +0000 (15:02 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 27 Jul 2016 14:02:20 +0000 (15:02 +0100)
src/libmime/message.c
src/libserver/protocol.c
src/libserver/roll_history.c
src/libserver/symbols_cache.c
src/libserver/task.c
src/libserver/task.h
src/libstat/stat_process.c
src/lua/lua_task.c

index 89ccff68bf6484e7b29c822fa735c6421fbd2da1..17680d3cdc4ebcaf12ca270fa7f071688bddc61b 100644 (file)
@@ -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;
                }
 
index e7192dff278ac017f13b1219de34a956b7381e3b..cb1e3dc308290ea0ac594e970e6411e21b5c4c99 100644 (file)
@@ -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);
index 812df927e03daee1a3f9a49d3571388fecb0797f..7cc0490c1a4578251f7982f6fddd6464a6a09aaa 100644 (file)
@@ -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,
index b4a3275d8ea3b9e701e7ad49233d34741276a774..2e32c9c6c055fff404793b1f5ca7cf76a73e4663 100644 (file)
@@ -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;
index 2e250eaaa0ef17ca01c9e30b72e80d543341254a..086a25e7d449b259f2c32768bfc05c2a4cd5a3bf 100644 (file)
@@ -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;
+}
index 4fb2ba3e3b1cda6af692670ce80e6bc305cb3875..80fdb82a368a3e44dd9e124b37e3993a29f22799 100644 (file)
@@ -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
  */
index 5c39cd8d88e07d6fe1b17209a6d2ca0b0df15558..00e7ded4c150df6becac22da5c8a45506664b182 100644 (file)
@@ -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;
index e11c3e5c181a1ef7ff3d6a244e037d1985c22bfe..a475162033f4a8af9dc46d7067e2af5fcf9f5d46 100644 (file)
@@ -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 {