]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Stat greylisted messages as greylisted not soft-rejected
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 25 Mar 2017 14:37:42 +0000 (14:37 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 25 Mar 2017 14:37:42 +0000 (14:37 +0000)
src/libserver/protocol.c
src/libserver/task.h
src/lua/lua_task.c
src/plugins/lua/greylist.lua

index b209cdecd8b6ba250d4407411b4ee1dc96215964..c1ed4fc9c4fe386ecc1d4ae66036d572bbc79e4c 100644 (file)
@@ -1341,7 +1341,13 @@ end:
                                action = rspamd_check_action_metric (task, metric_res);
                        }
 
-                       if (action <= METRIC_ACTION_NOACTION) {
+                       if (action == METRIC_ACTION_SOFT_REJECT &&
+                                       (task->flags & RSPAMD_TASK_FLAG_GREYLISTED)) {
+                               /* Set stat action to greylist to display greylisted messages */
+                               action = METRIC_ACTION_GREYLIST;
+                       }
+
+                       if (action < METRIC_ACTION_MAX) {
 #ifndef HAVE_ATOMIC_BUILTINS
                                task->worker->srv->stat->actions_stat[action]++;
 #else
index 97329ce3ba54da6cead28c7560b99210fb017410..db86a9ac98a99748cc650dcfb21e7201a45d45b3 100644 (file)
@@ -104,6 +104,7 @@ enum rspamd_task_stage {
 #define RSPAMD_TASK_FLAG_LOCAL_CLIENT (1 << 23)
 #define RSPAMD_TASK_FLAG_COMPRESSED (1 << 24)
 #define RSPAMD_TASK_FLAG_PROFILE (1 << 25)
+#define RSPAMD_TASK_FLAG_GREYLISTED (1 << 26)
 
 #define RSPAMD_TASK_IS_SKIPPED(task) (((task)->flags & RSPAMD_TASK_FLAG_SKIP))
 #define RSPAMD_TASK_IS_JSON(task) (((task)->flags & RSPAMD_TASK_FLAG_JSON))
@@ -124,7 +125,7 @@ struct rspamd_task {
        guint processed_stages;                                                 /**< bits of stages that are processed                          */
        enum rspamd_command cmd;                                                /**< command                                                                            */
        gint sock;                                                                              /**< socket descriptor                                                          */
-       guint flags;                                                                    /**< Bit flags                                                                          */
+       guint32 flags;                                                                  /**< Bit flags                                                                          */
        guint32 dns_requests;                                                   /**< number of DNS requests per this task                       */
        gulong message_len;                                                             /**< Message length                                                                     */
        gchar *helo;                                                                    /**< helo header value                                                          */
index 43b6b281e8903c2849e673980bf8810c5f9af05c..d8df34e1e0bb91a8f2a04b117c478ab75d5fbc2a 100644 (file)
@@ -3239,6 +3239,7 @@ lua_task_set_flag (lua_State *L)
                LUA_TASK_SET_FLAG (flag, "learn_ham", RSPAMD_TASK_FLAG_LEARN_HAM, set);
                LUA_TASK_SET_FLAG (flag, "broken_headers",
                                RSPAMD_TASK_FLAG_BROKEN_HEADERS, set);
+               LUA_TASK_SET_FLAG (flag, "gerylisted", RSPAMD_TASK_FLAG_GREYLISTED, set);
 
                if (!found) {
                        msg_warn_task ("unknown flag requested: %s", flag);
@@ -3266,6 +3267,7 @@ lua_task_has_flag (lua_State *L)
                LUA_TASK_GET_FLAG (flag, "extended_urls", RSPAMD_TASK_FLAG_EXT_URLS);
                LUA_TASK_GET_FLAG (flag, "learn_spam", RSPAMD_TASK_FLAG_LEARN_SPAM);
                LUA_TASK_GET_FLAG (flag, "learn_ham", RSPAMD_TASK_FLAG_LEARN_HAM);
+               LUA_TASK_GET_FLAG (flag, "greylisted", RSPAMD_TASK_FLAG_GREYLISTED);
                LUA_TASK_GET_FLAG (flag, "broken_headers",
                                RSPAMD_TASK_FLAG_BROKEN_HEADERS);
 
@@ -3330,6 +3332,10 @@ lua_task_get_flags (lua_State *L)
                                        lua_pushstring (L, "learn_ham");
                                        lua_rawseti (L, -2, idx++);
                                        break;
+                               case RSPAMD_TASK_FLAG_GREYLISTED:
+                                       lua_pushstring (L, "greylisted");
+                                       lua_rawseti (L, -2, idx++);
+                                       break;
                                default:
                                        break;
                                }
index 04d9115451cde3b698afe9f1c6d59b8a2cfea209..f1dd34953d39edfa2501e3fae42b9ab26ee3ce10 100644 (file)
@@ -206,6 +206,7 @@ local function greylist_check(task)
         else
           task:set_pre_result('soft reject', settings['message'])
         end
+        task:set_flags('greylisted')
       end
     elseif err then
       rspamd_logger.errx(task, 'got error while getting greylisting keys: %1', err)
@@ -333,6 +334,7 @@ local function greylist_set(task)
       'new record')
     if not qid then return end
     task:set_pre_result(settings['action'], settings['message'])
+    task:set_flags('greylisted')
     -- Create new record
     ret,conn,upstream = rspamd_redis_make_request(task,
       redis_params, -- connect params
@@ -372,6 +374,7 @@ local function greylist_set(task)
       task:set_metric_action('default', settings['action'])
       if not qid then return end
       task:set_pre_result(settings['action'], settings['message'])
+      task:set_flags('greylisted')
     else
       task:insert_result(settings['symbol'], 0.0, 'greylisted', 'passed')
     end