From 9836fe5686a3e439655753930d2e4fb7decd3309 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 25 Mar 2017 14:37:42 +0000 Subject: [PATCH] [Feature] Stat greylisted messages as greylisted not soft-rejected --- src/libserver/protocol.c | 8 +++++++- src/libserver/task.h | 3 ++- src/lua/lua_task.c | 6 ++++++ src/plugins/lua/greylist.lua | 3 +++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c index b209cdecd..c1ed4fc9c 100644 --- a/src/libserver/protocol.c +++ b/src/libserver/protocol.c @@ -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 diff --git a/src/libserver/task.h b/src/libserver/task.h index 97329ce3b..db86a9ac9 100644 --- a/src/libserver/task.h +++ b/src/libserver/task.h @@ -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 */ diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 43b6b281e..d8df34e1e 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -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; } diff --git a/src/plugins/lua/greylist.lua b/src/plugins/lua/greylist.lua index 04d911545..f1dd34953 100644 --- a/src/plugins/lua/greylist.lua +++ b/src/plugins/lua/greylist.lua @@ -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 -- 2.39.5