]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add function lua_util.get_task_verdict
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 15 Oct 2018 14:50:01 +0000 (15:50 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 15 Oct 2018 15:24:15 +0000 (16:24 +0100)
lualib/lua_util.lua

index 3c1a431cf22b46faa4c4b0e427a05bbe74b3783d..86f862f364158135d87b8281fb02071064ccd90e 100644 (file)
@@ -742,6 +742,10 @@ if type(rspamd_config) == 'userdata' then
   end
 end
 
+--[[[
+-- @function lua_util.debugm(module, [log_object], format, ...)
+-- Performs fast debug log for a specific module
+--]]
 exports.debugm = function(mod, obj_or_fmt, fmt_or_something, ...)
   local logger = require "rspamd_logger"
   if unconditional_debug or debug_modules[mod] then
@@ -753,5 +757,45 @@ exports.debugm = function(mod, obj_or_fmt, fmt_or_something, ...)
   end
 end
 
+---[[[
+-- @function lua_util.get_task_verdict(task)
+-- Returns verdict for a task, must be called from idempotent filters only
+-- Returns string:
+-- * `spam`: if message have over reject threshold and has more than one positive rule
+-- * `junk`: if a message has between score between [add_header/rewrite subject] to reject thresholds and has more than two positive rules
+-- * `passthrough`: if a message has been passed through some short-circuit rule
+-- * `ham`: if a message has overall score below junk level **and** more than three negative rule, or negative total score
+-- * `uncertain`: all other cases
+--]]
+exports.get_task_verdict = function(task)
+  local result = task:get_metric_result()
+
+  if result then
+
+    if result.passthrough then
+      return 'passthrough'
+    end
+
+    local action = result.action
+
+    if action == 'reject' and result.npositive > 1 then
+      return 'spam'
+    elseif action == 'no action' then
+      if result.score < 0 or result.nnegative > 3 then
+        return 'ham'
+      end
+    else
+      -- All colors of junk
+      if action == 'add header' or action == 'rewrite subject' then
+        if result.npositive > 2 then
+          return 'junk'
+        end
+      end
+    end
+  end
+
+  return 'uncertain'
+end
+
 
 return exports