Преглед изворни кода

[Minor] Add function lua_util.get_task_verdict

tags/1.8.1
Vsevolod Stakhov пре 5 година
родитељ
комит
6120200396
1 измењених фајлова са 44 додато и 0 уклоњено
  1. 44
    0
      lualib/lua_util.lua

+ 44
- 0
lualib/lua_util.lua Прегледај датотеку

@@ -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

Loading…
Откажи
Сачувај