]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Use `scores` in apply section
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 14 Aug 2019 15:03:24 +0000 (16:03 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 14 Aug 2019 15:03:24 +0000 (16:03 +0100)
lualib/lua_settings.lua
src/libmime/scan_result.c
src/plugins/lua/settings.lua

index 1c121147cb9ebca9b075f15318f7a921de1c2205..d03e63e7d5a5333bf811bff4196aa8fcd82724a4 100644 (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)
index 428a2da71d9899b43c49f5fd9226cf2c7162142d..6e6b30826950ac28bde65c072cce44691af259f8 100644 (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)) {
index f8b12b086d58c0b5b25d27240375c1c69361d52b..b1d7b5b0cd035462f7a1d994b143ce7068383b31 100644 (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