From c2d2d794c0737c8287d9662f723c60445842ff55 Mon Sep 17 00:00:00 2001 From: Andrew Lewis Date: Tue, 21 Feb 2017 12:52:59 +0200 Subject: [PATCH] [Minor] Add require_action/honor_action settings to force actions module --- src/plugins/lua/force_actions.lua | 34 +++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/plugins/lua/force_actions.lua b/src/plugins/lua/force_actions.lua index 3a76b9482..4a0e61ab9 100644 --- a/src/plugins/lua/force_actions.lua +++ b/src/plugins/lua/force_actions.lua @@ -25,7 +25,7 @@ local rspamd_cryptobox_hash = require "rspamd_cryptobox_hash" local rspamd_expression = require "rspamd_expression" local rspamd_logger = require "rspamd_logger" -local function gen_cb(expr, act, pool, message, subject) +local function gen_cb(expr, act, pool, message, subject, raction, honor) local function parse_atom(str) local atom = table.concat(fun.totable(fun.take_while(function(c) @@ -53,6 +53,16 @@ local function gen_cb(expr, act, pool, message, subject) return function(task) + local cact = task:get_metric_action('default') + if cact == act then + return false + end + if honor and honor[cact] then + return false + elseif raction and not raction[cact] then + return false + end + if e:process(task) == 1 then if subject then task:set_metric_subject(subject) @@ -69,6 +79,24 @@ local function gen_cb(expr, act, pool, message, subject) end +local function list_to_hash(list) + if type(list) == 'table' then + if list[1] then + local h = {} + for _, e in ipairs(list) do + h[e] = true + end + return h + else + return list + end + elseif type(list) == 'string' then + local h = {} + h[list] = true + return h + end +end + local function configure_module() local opts = rspamd_config:get_all_opt(N) if not opts then @@ -114,7 +142,9 @@ local function configure_module() if action and expr then local subject = sett.subject local message = sett.message - local cb, atoms = gen_cb(expr, action, rspamd_config:get_mempool(), message, subject) + local raction = list_to_hash(sett.require_action) + local honor = list_to_hash(sett.honor_action) + local cb, atoms = gen_cb(expr, action, rspamd_config:get_mempool(), message, subject, raction, honor) if cb and atoms then local sname = 'FORCE_ACTION_' .. name local id = rspamd_config:register_symbol({ -- 2.39.5