diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-03-11 14:06:05 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-03-11 14:06:05 +0000 |
commit | 9013ade3162aca060ab2064c419a858282812794 (patch) | |
tree | cfb722f3c754b3101297af8304d7dbb3761438e9 /rules | |
parent | a1c871c9f6a29754f88867b077b67531dcb2a001 (diff) | |
download | rspamd-9013ade3162aca060ab2064c419a858282812794.tar.gz rspamd-9013ade3162aca060ab2064c419a858282812794.zip |
[Fix] Rework HAS_X_PRIO rule to match symbols conventions
Diffstat (limited to 'rules')
-rw-r--r-- | rules/headers_checks.lua | 59 | ||||
-rw-r--r-- | rules/misc.lua | 1 |
2 files changed, 58 insertions, 2 deletions
diff --git a/rules/headers_checks.lua b/rules/headers_checks.lua index 18785234e..b8d4bd872 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 66b1b90ab..a9382f8f4 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 = { |