From 30925d34729952d1093bf91c6a1f7367ee81ff3a Mon Sep 17 00:00:00 2001 From: Alexander Moisseev Date: Sun, 2 Oct 2016 12:39:03 +0300 Subject: [PATCH] [Feature] Check settings with equal priopities in alphabetical order --- src/plugins/lua/settings.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/plugins/lua/settings.lua b/src/plugins/lua/settings.lua index bf403d5bd..5b173e18c 100644 --- a/src/plugins/lua/settings.lua +++ b/src/plugins/lua/settings.lua @@ -22,11 +22,7 @@ local rspamd_logger = require "rspamd_logger" local rspamd_redis = require 'rspamd_redis' local redis_params -local settings = { - [1] = {}, - [2] = {}, - [3] = {} -} +local settings = {} local settings_ids = {} local settings_initialized = false local max_pri = 0 @@ -274,8 +270,8 @@ local function check_settings(task) for pri = max_pri,1,-1 do if not applied and settings[pri] then - for name, r in pairs(settings[pri]) do - local rule = check_specific_setting(name, r, ip, client_ip, from, rcpt, user, uname) + for _,s in ipairs(settings[pri]) do + local rule = check_specific_setting(s.name, s.rule, ip, client_ip, from, rcpt, user, uname) if rule then rspamd_logger.infox(task, "<%1> apply settings according to rule %2", task:get_message_id(), name) @@ -494,10 +490,14 @@ local function process_settings_table(tbl) end local s = process_setting_elt(k, v) if s then - settings[pri][k] = s + table.insert(settings[pri], {name = k, rule = s}) nrules = nrules + 1 end end, ft) + -- sort settings with equal priopities in alphabetical order + for pri,_ in pairs(settings) do + table.sort(settings[pri], function(a,b) return a.name < b.name end) + end settings_initialized = true rspamd_logger.infox(rspamd_config, 'loaded %1 elements of settings', nrules) -- 2.39.5