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