commit 104e947: [Feature] Use `scores` in apply section
Vsevolod Stakhov
vsevolod at highsecure.ru
Wed Aug 14 15:14:07 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-08-14 16:03:24 +0100
URL: https://github.com/rspamd/rspamd/commit/104e9476a61286ea9a55e3a975d5049f6a129e60
[Feature] Use `scores` in apply section
---
lualib/lua_settings.lua | 8 ++++----
src/libmime/scan_result.c | 10 +++++++++-
src/plugins/lua/settings.lua | 36 ++++++++++++++++++++++--------------
3 files changed, 35 insertions(+), 19 deletions(-)
diff --git a/lualib/lua_settings.lua b/lualib/lua_settings.lua
index 1c121147c..d03e63e7d 100644
--- a/lualib/lua_settings.lua
+++ b/lualib/lua_settings.lua
@@ -183,13 +183,13 @@ local function transform_settings_maybe(settings, name)
if not senabled[1] then
-- Transform map to a list
local nlist = {}
- if not settings.symbols then
- settings.symbols = {}
+ if not apply.scores then
+ apply.scores = {}
end
for k,v in pairs(senabled) do
if tonumber(v) then
-- Move to symbols as well
- settings.symbols[k] = tonumber(v)
+ apply.scores[k] = tonumber(v)
lua_util.debugm('settings', rspamd_config,
'set symbol %s -> %s for settings %s', k, v, name)
end
@@ -203,7 +203,7 @@ local function transform_settings_maybe(settings, name)
if apply.symbols then
-- Check if added symbols are enabled
- for _,s in ipairs(apply.symbols) do
+ for _,s in pairs(apply.symbols) do
if not symhash[s] then
lua_util.debugm('settings', rspamd_config,
'added symbol %s to symbols_enabled for %s', s, name)
diff --git a/src/libmime/scan_result.c b/src/libmime/scan_result.c
index 428a2da71..6e6b30826 100644
--- a/src/libmime/scan_result.c
+++ b/src/libmime/scan_result.c
@@ -247,8 +247,16 @@ insert_metric_result (struct rspamd_task *task,
}
if (task->settings) {
- mobj = task->settings;
gdouble corr;
+ mobj = ucl_object_lookup (task->settings, "scores");
+
+ if (!mobj) {
+ /* Legacy */
+ mobj = task->settings;
+ }
+ else {
+ msg_debug_metric ("found scores in the settings");
+ }
sobj = ucl_object_lookup (mobj, symbol);
if (sobj != NULL && ucl_object_todouble_safe (sobj, &corr)) {
diff --git a/src/plugins/lua/settings.lua b/src/plugins/lua/settings.lua
index f8b12b086..b1d7b5b0c 100644
--- a/src/plugins/lua/settings.lua
+++ b/src/plugins/lua/settings.lua
@@ -65,18 +65,19 @@ local function apply_settings(task, to_apply, id)
if to_apply.symbols then
-- Add symbols, specified in the settings
if #to_apply.symbols > 0 then
- fun.each(function(val)
+ -- Array like symbols
+ for _,val in ipairs(to_apply.symbols) do
task:insert_result(val, 1.0)
- end,
- fun.filter(function(elt) return type(elt) == 'string' end,
- to_apply.symbols))
+ end
else
-- Object like symbols
- fun.each(function(k, val)
- task:insert_result(k, val.score or 1.0, val.options or {})
- end,
- fun.filter(function(_, elt) return type(elt) == 'table' end,
- to_apply.symbols))
+ for k,v in pairs(to_apply.symbols) do
+ if type(v) == 'table' then
+ task:insert_result(k, v.score or 1.0, v.options or {})
+ elseif tonumber(v) then
+ task:insert_result(k, tonumber(v))
+ end
+ end
end
end
@@ -919,11 +920,18 @@ local function process_settings_table(tbl, allow_ids, mempool)
if elt.apply.symbols then
-- Register virtual symbols
- for _,sym in ipairs(elt.apply.symbols) do
- rspamd_config:register_symbol{
- name = sym,
- type = 'virtual,ghost',
- }
+ for k,v in pairs(elt.apply.symbols) do
+ if type(k) == 'number' and type(v) == 'string' then
+ rspamd_config:register_symbol{
+ name = v,
+ type = 'virtual,ghost',
+ }
+ elseif type(k) == 'string' then
+ rspamd_config:register_symbol{
+ name = k,
+ type = 'virtual,ghost',
+ }
+ end
end
end
else
More information about the Commits
mailing list