From: Vsevolod Stakhov Date: Wed, 12 Dec 2018 14:59:24 +0000 (+0000) Subject: [Feature] Settings: Allow to inverse conditions X-Git-Tag: 1.9.0~442 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70076b2ebb592b46fc7b9de912d60e1560fcc0f8;p=thirdparty%2Frspamd.git [Feature] Settings: Allow to inverse conditions --- diff --git a/src/plugins/lua/settings.lua b/src/plugins/lua/settings.lua index 62fd63ec7d..a6ce955c1e 100644 --- a/src/plugins/lua/settings.lua +++ b/src/plugins/lua/settings.lua @@ -214,7 +214,6 @@ local function check_settings(task) if ip:is_local() then matched[#matched + 1] = 'local' res = true - break else return nil end @@ -414,18 +413,19 @@ local function check_settings(task) local rule = check_specific_setting(s.name, s.rule, ip, client_ip, from, rcpt, user, uname, hostname, matched) - if rule then + -- Can use xor here but more complicated for reading + if (rule and not s.rule.inverse) or (not rule and s.rule.inverse) then rspamd_logger.infox(task, "<%s> apply settings according to rule %s (%s matched)", task:get_message_id(), s.name, table.concat(matched, ',')) - if rule['apply'] then - apply_settings(task, rule['apply']) + if s.rule['apply'] then + apply_settings(task, s.rule['apply']) applied = true end - if rule['symbols'] then + if s.rule['symbols'] then -- Add symbols, specified in the settings fun.each(function(val) task:insert_result(val, 1.0) - end, rule['symbols']) + end, s.rule['symbols']) end end end @@ -601,6 +601,9 @@ local function process_settings_table(tbl) if elt['local'] then out['local'] = true end + if elt['inverse'] then + out['inverse'] = true + end if elt['request_header'] then local rho = {} for k, v in pairs(elt['request_header']) do