aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Lewis <nerf@judo.za.org>2017-02-21 11:33:02 +0200
committerAndrew Lewis <nerf@judo.za.org>2017-02-21 11:33:02 +0200
commit501c5c72dc0478bc841d96fb79425865d64aa528 (patch)
treec759d42dedca396bd05993fac3a5d078fb313a3c
parent3480e172837207c3204a62405573250df9a8ef3f (diff)
downloadrspamd-501c5c72dc0478bc841d96fb79425865d64aa528.tar.gz
rspamd-501c5c72dc0478bc841d96fb79425865d64aa528.zip
[Minor] Rework force actions configuration
-rw-r--r--src/plugins/lua/force_actions.lua78
1 files changed, 50 insertions, 28 deletions
diff --git a/src/plugins/lua/force_actions.lua b/src/plugins/lua/force_actions.lua
index e5c309c24..3a76b9482 100644
--- a/src/plugins/lua/force_actions.lua
+++ b/src/plugins/lua/force_actions.lua
@@ -74,39 +74,61 @@ local function configure_module()
if not opts then
return false
end
- if type(opts.actions) ~= 'table' then
- return false
- end
- for action, expressions in pairs(opts.actions) do
- if type(expressions) == 'table' then
- for _, expr in ipairs(expressions) do
- local message, subject
- if type(expr) == 'table' then
- subject = expr[3]
- message = expr[2]
- expr = expr[1]
- else
- message = (opts.messages or E)[expr]
- end
- if type(expr) == 'string' then
- local cb, atoms = gen_cb(expr, action, rspamd_config:get_mempool(), message, subject)
- if cb and atoms then
- local h = rspamd_cryptobox_hash.create()
- h:update(expr)
- local name = 'FORCE_ACTION_' .. string.upper(string.sub(h:hex(), 1, 12))
- local id = rspamd_config:register_symbol({
- type = 'normal',
- name = name,
- callback = cb,
- })
- for _, a in ipairs(atoms) do
- rspamd_config:register_dependency(id, a)
+ if type(opts.actions) == 'table' then
+ rspamd_logger.warnx(rspamd_config, 'Processing legacy config')
+ for action, expressions in pairs(opts.actions) do
+ if type(expressions) == 'table' then
+ for _, expr in ipairs(expressions) do
+ local message, subject
+ if type(expr) == 'table' then
+ subject = expr[3]
+ message = expr[2]
+ expr = expr[1]
+ else
+ message = (opts.messages or E)[expr]
+ end
+ if type(expr) == 'string' then
+ local cb, atoms = gen_cb(expr, action, rspamd_config:get_mempool(), message, subject)
+ if cb and atoms then
+ local h = rspamd_cryptobox_hash.create()
+ h:update(expr)
+ local name = 'FORCE_ACTION_' .. string.upper(string.sub(h:hex(), 1, 12))
+ local id = rspamd_config:register_symbol({
+ type = 'normal',
+ name = name,
+ callback = cb,
+ })
+ for _, a in ipairs(atoms) do
+ rspamd_config:register_dependency(id, a)
+ end
+ rspamd_logger.infox(rspamd_config, 'Registered symbol %1 <%2> with dependencies [%3]', name, expr, table.concat(atoms, ','))
end
- rspamd_logger.infox(rspamd_config, 'Registered symbol %1 <%2> with dependencies [%3]', name, expr, table.concat(atoms, ','))
end
end
end
end
+ elseif type(opts.rules) == 'table' then
+ for name, sett in pairs(opts.rules) do
+ local action = sett.action
+ local expr = sett.expression
+ 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)
+ if cb and atoms then
+ local sname = 'FORCE_ACTION_' .. name
+ local id = rspamd_config:register_symbol({
+ type = 'normal',
+ name = sname,
+ callback = cb,
+ })
+ for _, a in ipairs(atoms) do
+ rspamd_config:register_dependency(id, a)
+ end
+ rspamd_logger.infox(rspamd_config, 'Registered symbol %1 <%2> with dependencies [%3]', name, expr, table.concat(atoms, ','))
+ end
+ end
+ end
end
end