]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add require_action/honor_action settings to force actions module 1444/head
authorAndrew Lewis <nerf@judo.za.org>
Tue, 21 Feb 2017 10:52:59 +0000 (12:52 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Tue, 21 Feb 2017 10:52:59 +0000 (12:52 +0200)
src/plugins/lua/force_actions.lua

index 3a76b94822c34f6355ddabcdd53a9b87a53ed2b9..4a0e61ab99b7bab8799da18846788609544cc9bd 100644 (file)
@@ -25,7 +25,7 @@ local rspamd_cryptobox_hash = require "rspamd_cryptobox_hash"
 local rspamd_expression = require "rspamd_expression"
 local rspamd_logger = require "rspamd_logger"
 
-local function gen_cb(expr, act, pool, message, subject)
+local function gen_cb(expr, act, pool, message, subject, raction, honor)
 
   local function parse_atom(str)
     local atom = table.concat(fun.totable(fun.take_while(function(c)
@@ -53,6 +53,16 @@ local function gen_cb(expr, act, pool, message, subject)
 
   return function(task)
 
+    local cact = task:get_metric_action('default')
+    if cact == act then
+      return false
+    end
+    if honor and honor[cact] then
+      return false
+    elseif raction and not raction[cact] then
+      return false
+    end
+
     if e:process(task) == 1 then
       if subject then
         task:set_metric_subject(subject)
@@ -69,6 +79,24 @@ local function gen_cb(expr, act, pool, message, subject)
 
 end
 
+local function list_to_hash(list)
+  if type(list) == 'table' then
+    if list[1] then
+      local h = {}
+      for _, e in ipairs(list) do
+        h[e] = true
+      end
+      return h
+    else
+      return list
+    end
+  elseif type(list) == 'string' then
+    local h = {}
+    h[list] = true
+    return h
+  end
+end
+
 local function configure_module()
   local opts = rspamd_config:get_all_opt(N)
   if not opts then
@@ -114,7 +142,9 @@ local function configure_module()
       if action and expr then
         local subject = sett.subject
         local message = sett.message
-        local cb, atoms = gen_cb(expr, action, rspamd_config:get_mempool(), message, subject)
+        local raction = list_to_hash(sett.require_action)
+        local honor = list_to_hash(sett.honor_action)
+        local cb, atoms = gen_cb(expr, action, rspamd_config:get_mempool(), message, subject, raction, honor)
         if cb and atoms then
           local sname = 'FORCE_ACTION_' .. name
           local id = rspamd_config:register_symbol({