From: Vsevolod Stakhov Date: Sat, 11 Mar 2017 14:06:05 +0000 (+0000) Subject: [Fix] Rework HAS_X_PRIO rule to match symbols conventions X-Git-Tag: 1.5.3~52 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9013ade3162aca060ab2064c419a858282812794;p=thirdparty%2Frspamd.git [Fix] Rework HAS_X_PRIO rule to match symbols conventions --- diff --git a/rules/headers_checks.lua b/rules/headers_checks.lua index 18785234eb..b8d4bd8729 100644 --- a/rules/headers_checks.lua +++ b/rules/headers_checks.lua @@ -107,16 +107,71 @@ rspamd_config:register_symbol{ group = 'header', } -rspamd_config.HAS_X_PRIO = { +local prio_cb_id = rspamd_config:register_symbol { + name = 'HAS_X_PRIO', + type = 'callback', callback = function (task) + local cnts = { + [1] = 'ONE', + [2] = 'TWO', + [3] = 'THREE', + [5] = 'FIVE', + } + local def = 'ZERO' local xprio = task:get_header('X-Priority'); if not xprio then return false end local _,_,x = xprio:find('^%s?(%d+)'); if (x) then - task:insert_result('HAS_X_PRIO_' .. x, 1.0) + x = tonumber(x) + for k,v in pairs(cnts) do + if x >= tonumber(k) then + def = v + end + end + task:insert_result('HAS_X_PRIO_' .. def, 1.0, tostring(x)) end end } +rspamd_config:register_symbol{ + name = 'HAS_X_PRIO_ZERO', + score = 0.0, + parent = prio_cb_id, + type = 'virtual', + description = 'Priority 0', + group = 'header', +} +rspamd_config:register_symbol{ + name = 'HAS_X_PRIO_ONE', + score = 0.0, + parent = prio_cb_id, + type = 'virtual', + description = 'Priority 1', + group = 'header', +} +rspamd_config:register_symbol{ + name = 'HAS_X_PRIO_TWO', + score = 0.0, + parent = prio_cb_id, + type = 'virtual', + description = 'Priority 2', + group = 'header', +} +rspamd_config:register_symbol{ + name = 'HAS_X_PRIO_THREE', + score = 0.0, + parent = prio_cb_id, + type = 'virtual', + description = 'Priority 3-4', + group = 'header', +} +rspamd_config:register_symbol{ + name = 'HAS_X_PRIO_FIVE', + score = 0.0, + parent = prio_cb_id, + type = 'virtual', + description = 'Priority 5+', + group = 'header', +} local check_replyto_id = rspamd_config:register_callback_symbol('CHECK_REPLYTO', 1.0, function (task) diff --git a/rules/misc.lua b/rules/misc.lua index 66b1b90abe..a9382f8f46 100644 --- a/rules/misc.lua +++ b/rules/misc.lua @@ -19,6 +19,7 @@ limitations under the License. local E = {} local fun = require "fun" local util = require "rspamd_util" +local rspamd_regexp = require "rspamd_regexp" -- Different text parts rspamd_config.R_PARTS_DIFFER = {