]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Settings: Allow to inverse conditions
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 12 Dec 2018 14:59:24 +0000 (14:59 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 12 Dec 2018 14:59:24 +0000 (14:59 +0000)
src/plugins/lua/settings.lua

index 62fd63ec7da739b1e985a078a8f0658559b0272e..a6ce955c1e8d7986998b7bd9aa43e0ac5e084fbd 100644 (file)
@@ -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