commit 55bc63e: [Feature] Spamassassin: Allow to set the default priority for SA scores

Vsevolod Stakhov vsevolod at highsecure.ru
Sun Apr 18 19:28:04 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-04-18 20:26:41 +0100
URL: https://github.com/rspamd/rspamd/commit/55bc63e1e841292aca245ce3e2c44d5582580c8a (HEAD -> master)

[Feature] Spamassassin: Allow to set the default priority for SA scores
Issue: #3720

---
 src/plugins/lua/spamassassin.lua | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/src/plugins/lua/spamassassin.lua b/src/plugins/lua/spamassassin.lua
index 911661ed9..b19ad9a0d 100644
--- a/src/plugins/lua/spamassassin.lua
+++ b/src/plugins/lua/spamassassin.lua
@@ -130,6 +130,10 @@ local meta_score_alpha = 0.5
 -- Maximum size of regexp checked
 local match_limit = 0
 
+-- Default priority of the scores registered in the metric
+-- Historically this is set to 2 allowing SA scores to override Rspamd scores
+local scores_priority = 2
+
 local function split(str, delim)
   local result = {}
 
@@ -1547,7 +1551,7 @@ local function post_process()
           rspamd_config:set_metric_symbol{
             name = k, score = r['score'],
             description = r['description'],
-            priority = 2,
+            priority = scores_priority,
             one_shot = true
           }
           scores_added[k] = 1
@@ -1670,18 +1674,19 @@ end
 local has_rules = false
 
 if type(section) == "table" then
-  if type(section.pcre_only) == 'table' then
-    pcre_only_regexps = lua_util.list_to_hash(section.pcre_only)
-  end
-  if type(section.alpha) == 'number' then
-    meta_score_alpha = section.alpha
-  end
-  if type(section.match_limit) == 'number' then
-    match_limit = section.match_limit
-  end
+  local keywords = {
+    pcre_only = {'table', function(v) pcre_only_regexps = lua_util.list_to_hash(v) end},
+    alpha = {'number', function(v) meta_score_alpha = tonumber(v) end},
+    match_limit = {'number', function(v) match_limit = tonumber(v) end},
+    scores_priority = {'number', function(v) scores_priority = tonumber(v) end},
+  }
 
   for k, fn in pairs(section) do
-    if k ~= 'pcre_only' and k ~= 'alpha' and k ~= 'match_limit' then
+    local kw = keywords[k]
+    if kw and type(fn) == kw[1] then
+      kw[2](fn)
+    else
+      -- SA rule file
       if type(fn) == 'table' then
         for _, elt in ipairs(fn) do
           local files = util.glob(elt)
@@ -1718,7 +1723,6 @@ if type(section) == "table" then
               rspamd_logger.errx(rspamd_config, "cannot open %1", matched)
             end
           end
-
         end
       end
     end


More information about the Commits mailing list