commit 51c3d5b: [Minor] Milter_headers: Allow to sort symbols

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Feb 11 16:14:09 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-02-11 16:07:09 +0000
URL: https://github.com/rspamd/rspamd/commit/51c3d5bd086c29f313abb5d7789f1f821c4452ce (HEAD -> master)

[Minor] Milter_headers: Allow to sort symbols
Issue: #3642

---
 src/plugins/lua/milter_headers.lua | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/plugins/lua/milter_headers.lua b/src/plugins/lua/milter_headers.lua
index 3b0037a09..305cc6411 100644
--- a/src/plugins/lua/milter_headers.lua
+++ b/src/plugins/lua/milter_headers.lua
@@ -53,7 +53,7 @@ local settings = {
       header = 'X-Spamd-Result',
       remove = 0,
       stop_chars = ' ',
-      sort_by = 'name',
+      sort_by = 'score',
     },
     ['x-rspamd-server'] = {
       header = 'X-Rspamd-Server',
@@ -249,6 +249,18 @@ local function milter_headers(task)
     table.insert(buf, verdict)
 
     -- Deal with symbols
+    table.sort(common.symbols, function(s1, s2)
+      local res
+      if local_mod.sort_by == 'name' then
+        res = s1.name < s2.name
+      else
+        -- inverse order to show important symbols first
+        res = math.abs(s1.score) > math.abs(s2.score)
+      end
+
+      return res
+    end)
+
     for _, s in ipairs(common.symbols) do
       local sym_str = string.format('%s(%.2f)[%s]',
           s.name, s.score,  table.concat(s.options or {}, ','))


More information about the Commits mailing list