diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-08-14 15:09:22 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-08-14 15:09:22 +0100 |
commit | 92beb82231f459ec5b761edb43576670d7b2ae97 (patch) | |
tree | 533c8a89020ce0c4b831c88f1df842c8e629471e /lualib/lua_settings.lua | |
parent | 4f1f869748207d12c2deda80e12aeb206ce37fcb (diff) | |
download | rspamd-92beb82231f459ec5b761edb43576670d7b2ae97.tar.gz rspamd-92beb82231f459ec5b761edb43576670d7b2ae97.zip |
[Feature] Improve settings processing
Diffstat (limited to 'lualib/lua_settings.lua')
-rw-r--r-- | lualib/lua_settings.lua | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/lualib/lua_settings.lua b/lualib/lua_settings.lua index 1f4dd5a7c..1c121147c 100644 --- a/lualib/lua_settings.lua +++ b/lualib/lua_settings.lua @@ -170,6 +170,52 @@ local function numeric_settings_id(str) return ret end +-- Used to do the following: +-- If there is a group of symbols_allowed, it checks if that is an array +-- If that is a hash table then we transform it to a normal list, probably adding symbols to adjust scores +local function transform_settings_maybe(settings, name) + if settings.apply then + local apply = settings.apply + + if apply.symbols_enabled then + local senabled = apply.symbols_enabled + + if not senabled[1] then + -- Transform map to a list + local nlist = {} + if not settings.symbols then + settings.symbols = {} + end + for k,v in pairs(senabled) do + if tonumber(v) then + -- Move to symbols as well + settings.symbols[k] = tonumber(v) + lua_util.debugm('settings', rspamd_config, + 'set symbol %s -> %s for settings %s', k, v, name) + end + nlist[#nlist + 1] = k + end + -- Convert + apply.symbols_enabled = nlist + end + + local symhash = lua_util.list_to_hash(apply.symbols_enabled) + + if apply.symbols then + -- Check if added symbols are enabled + for _,s in ipairs(apply.symbols) do + if not symhash[s] then + lua_util.debugm('settings', rspamd_config, + 'added symbol %s to symbols_enabled for %s', s, name) + end + end + end + end + end + + return settings +end + local function register_settings_id(str, settings) local numeric_id = numeric_settings_id(str) @@ -186,7 +232,7 @@ local function register_settings_id(str, settings) else known_ids[numeric_id] = { name = str, - settings = settings, + settings = transform_settings_maybe(settings, str), symbols = {} } end |