From 355526a8d1ad68e5badcd76da3ec4f63c501d15d Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 11 Mar 2017 14:35:22 +0000 Subject: [PATCH] [Fix] RCPT_COUNT fixes --- rules/headers_checks.lua | 88 ++++++++++++++++++++++++++++++++++++++-- rules/misc.lua | 2 +- 2 files changed, 85 insertions(+), 5 deletions(-) diff --git a/rules/headers_checks.lua b/rules/headers_checks.lua index a50edeb73..da48a8a1f 100644 --- a/rules/headers_checks.lua +++ b/rules/headers_checks.lua @@ -16,7 +16,10 @@ limitations under the License. local util = require "rspamd_util" local ipairs = ipairs +local pairs = pairs local table = table +local tostring = tostring +local tonumber = tonumber local fun = require "fun" local E = {} @@ -682,13 +685,25 @@ local check_to_cc_id = rspamd_config:register_symbol{ local rcpts = task:get_recipients(1) local to = task:get_recipients(2) local to_match_envrcpt = 0 + local cnts = { + [1] = 'ONE', + [2] = 'TWO', + [3] = 'THREE', + [5] = 'FIVE', + [7] = 'SEVEN', + [12] = 'TWELVE', + [50] = 'GT_50' + } + local def = 'ZERO' if (not to) then return false end -- Add symbol for recipient count - if (#to > 50) then - task:insert_result('RCPT_COUNT_GT_50', 1.0) - else - task:insert_result('RCPT_COUNT_' .. #to, 1.0) + local nrcpt = #to + for k,v in pairs(cnts) do + if nrcpt >= tonumber(k) then + def = v + end end + task:insert_result('RCPT_COUNT_' .. def, 1.0, tostring(nrcpt)) -- Check for display names local to_dn_count = 0 local to_dn_eq_addr_count = 0 @@ -736,6 +751,71 @@ local check_to_cc_id = rspamd_config:register_symbol{ end } +rspamd_config:register_symbol{ + name = 'RCPT_COUNT_ZERO', + score = 0.0, + parent = check_to_cc_id, + type = 'virtual', + description = 'No recipients', + group = 'header', +} +rspamd_config:register_symbol{ + name = 'RCPT_COUNT_ONE', + score = 0.0, + parent = check_to_cc_id, + type = 'virtual', + description = 'One recipient', + group = 'header', +} +rspamd_config:register_symbol{ + name = 'RCPT_COUNT_TWO', + score = 0.0, + parent = check_to_cc_id, + type = 'virtual', + description = 'Two recipients', + group = 'header', +} +rspamd_config:register_symbol{ + name = 'RCPT_COUNT_THREE', + score = 0.0, + parent = check_to_cc_id, + type = 'virtual', + description = '3-5 recipients', + group = 'header', +} +rspamd_config:register_symbol{ + name = 'RCPT_COUNT_FIVE', + score = 0.0, + parent = check_to_cc_id, + type = 'virtual', + description = '5-7 recipients', + group = 'header', +} +rspamd_config:register_symbol{ + name = 'RCPT_COUNT_SEVEN', + score = 0.0, + parent = check_to_cc_id, + type = 'virtual', + description = '7-11 recipients', + group = 'header', +} +rspamd_config:register_symbol{ + name = 'RCPT_COUNT_TWELVE', + score = 0.0, + parent = check_to_cc_id, + type = 'virtual', + description = '12-50 recipients', + group = 'header', +} +rspamd_config:register_symbol{ + name = 'RCPT_COUNT_GT_50', + score = 0.0, + parent = check_to_cc_id, + type = 'virtual', + description = '50+ recipients', + group = 'header', +} + rspamd_config:register_symbol{ name = 'TO_DN_RECIPIENTS', score = 2.0, diff --git a/rules/misc.lua b/rules/misc.lua index a9382f8f4..2c6d8899b 100644 --- a/rules/misc.lua +++ b/rules/misc.lua @@ -235,7 +235,7 @@ rspamd_config.URI_COUNT_ODD = { if (ct and ct:lower():find('^multipart/alternative')) then local urls = task:get_urls() if (urls and (#urls % 2 == 1)) then - return true + return true, 1.0, tostring(#urls % 2) end end end, -- 2.39.5