From: Andrew Lewis Date: Tue, 21 Feb 2017 09:33:02 +0000 (+0200) Subject: [Minor] Rework force actions configuration X-Git-Tag: 1.5.0~68^2~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=501c5c72dc0478bc841d96fb79425865d64aa528;p=rspamd.git [Minor] Rework force actions configuration --- 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