aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/lua/force_actions.lua
diff options
context:
space:
mode:
authorAndrew Lewis <nerf@judo.za.org>2017-02-21 12:52:59 +0200
committerAndrew Lewis <nerf@judo.za.org>2017-02-21 12:52:59 +0200
commitc2d2d794c0737c8287d9662f723c60445842ff55 (patch)
treedafbba6e956d8480e846618914b8a3657bfb18dc /src/plugins/lua/force_actions.lua
parent501c5c72dc0478bc841d96fb79425865d64aa528 (diff)
downloadrspamd-c2d2d794c0737c8287d9662f723c60445842ff55.tar.gz
rspamd-c2d2d794c0737c8287d9662f723c60445842ff55.zip
[Minor] Add require_action/honor_action settings to force actions module
Diffstat (limited to 'src/plugins/lua/force_actions.lua')
-rw-r--r--src/plugins/lua/force_actions.lua34
1 files 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({