Browse Source

[Feature] Use `scores` in apply section

tags/2.0
Vsevolod Stakhov 4 years ago
parent
commit
104e9476a6
3 changed files with 35 additions and 19 deletions
  1. 4
    4
      lualib/lua_settings.lua
  2. 9
    1
      src/libmime/scan_result.c
  3. 22
    14
      src/plugins/lua/settings.lua

+ 4
- 4
lualib/lua_settings.lua View File

@@ -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)

+ 9
- 1
src/libmime/scan_result.c View File

@@ -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)) {

+ 22
- 14
src/plugins/lua/settings.lua View File

@@ -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

Loading…
Cancel
Save