From 51c3d5bd086c29f313abb5d7789f1f821c4452ce Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 11 Feb 2021 16:07:09 +0000 Subject: [PATCH] [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 {}, ',')) -- 2.39.5