]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Milter_headers: Allow to sort symbols
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 11 Feb 2021 16:07:09 +0000 (16:07 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 11 Feb 2021 16:07:09 +0000 (16:07 +0000)
Issue: #3642

src/plugins/lua/milter_headers.lua

index 3b0037a094045836928b3894f9b5f5c2779e463f..305cc6411ade1d16b115d7c9cfe9eca02c22d816 100644 (file)
@@ -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 {}, ','))