Skip to content

Commit

Permalink
[Rework] Convert surbl rules to rbl rules
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Aug 27, 2019
1 parent 97d6e1e commit 259c79b
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions lualib/lua_cfg_transform.lua
Expand Up @@ -233,6 +233,46 @@ local function check_statistics_sanity()
end
end

-- Converts surbl module config to rbl module
local function surbl_section_convert(cfg, section)
local rbl_section = cfg.rbl.rbls
local wl = section.whitelist
for name,value in pairs(section.rules or {}) do
if not rbl_section[name] then
local converted = {
urls = true,
ignore_defaults = true,
}

if wl then
converted.whitelist = wl
end

for k,v in pairs(value) do
-- Rename
if k == 'suffix' then k = 'rbl' end
if k == 'ips' then k = 'returncodes' end
if k == 'bits' then k = 'returnbits' end
if k:match('check_') then
local n = k:match('check_(.*)')
k = n
end

if k == 'dkim' and v then
converted.dkim_domainonly = false
converted.dkim_match_from = true
end

converted[k] = lua_util.deepcopy(v)
end
rbl_section[name] = converted
else
logger.warnx(rspamd_config, 'conflicting names in surbl and rbl rules: %s, ignore surbl rule',
name)
end
end
end

return function(cfg)
local ret = false

Expand Down Expand Up @@ -402,5 +442,19 @@ return function(cfg)
end
end

if cfg.surbl then
if not cfg.rbl then
cfg.rbl = {
rbls = {}
}
end
if not cfg.rbl.rbls then
cfg.rbl.rbls = {}
end
surbl_section_convert(cfg, cfg.surbl)
logger.infox(rspamd_config, 'converted surbl rules to rbl rules')
cfg.surbl = {}
end

return ret, cfg
end

0 comments on commit 259c79b

Please sign in to comment.