diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-04-18 10:19:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-18 10:19:05 +0100 |
commit | e81fe0882df81045ef43f9741546b5a60752b115 (patch) | |
tree | 0aab0f89071efbec3299a53587012029842e1009 /src/plugins/lua/force_actions.lua | |
parent | 892383a5a2fe19a4da4ad7862e087eed3618d11d (diff) | |
parent | 00b2ecaa3b1ec5629a1c37781af80b7afa23913b (diff) | |
download | rspamd-e81fe0882df81045ef43f9741546b5a60752b115.tar.gz rspamd-e81fe0882df81045ef43f9741546b5a60752b115.zip |
Merge pull request #3336 from rm-minus-rf/master
[Feature] allow variables in force_actions messages
Diffstat (limited to 'src/plugins/lua/force_actions.lua')
-rw-r--r-- | src/plugins/lua/force_actions.lua | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/plugins/lua/force_actions.lua b/src/plugins/lua/force_actions.lua index 108c0b76e..eda87ead0 100644 --- a/src/plugins/lua/force_actions.lua +++ b/src/plugins/lua/force_actions.lua @@ -23,12 +23,14 @@ end local E = {} local N = 'force_actions' +local selector_cache = {} local fun = require "fun" local lua_util = require "lua_util" local rspamd_cryptobox_hash = require "rspamd_cryptobox_hash" local rspamd_expression = require "rspamd_expression" local rspamd_logger = require "rspamd_logger" +local lua_selectors = require "lua_selectors" local function gen_cb(expr, act, pool, message, subject, raction, honor, limit, least) @@ -63,6 +65,29 @@ local function gen_cb(expr, act, pool, message, subject, raction, honor, limit, return function(task) + local function process_message_selectors(repl, selector_expr) + -- create/reuse selector to extract value for this placeholder + local selector = selector_cache[selector_expr] + if not selector then + selector_cache[selector_expr] = lua_selectors.create_selector_closure(rspamd_config, selector_expr, '', true) + selector = selector_cache[selector_expr] + if not selector then + rspamd_logger.errx(task, 'could not create selector [%1]', selector_expr) + return "((could not create selector))" + end + end + local extracted = selector(task) + if extracted then + if type(extracted) == 'table' then + extracted = table.concat(extracted, ',') + end + else + rspamd_logger.errx(task, 'could not extract value with selector [%1]', selector_expr) + extracted = '((error extracting value))' + end + return extracted + end + local cact = task:get_metric_action('default') if cact == act then return false @@ -83,8 +108,9 @@ local function gen_cb(expr, act, pool, message, subject, raction, honor, limit, if least then flags = "least" end if type(message) == 'string' then + -- process selector expressions in the message + message = string.gsub(message, '(${(.-)})', process_message_selectors) task:set_pre_result(act, message, N, nil, nil, flags) - else task:set_pre_result(act, nil, N, nil, nil, flags) end |