diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-03-24 20:19:06 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-24 20:19:06 +0000 |
commit | f3bbf3f8f4dd26cceee798a83ac3882b6e0d8337 (patch) | |
tree | 0b1a55a78c93e785eb1affa35a50351f9595007f | |
parent | a04efc35197414102796de2ca934c118656f769b (diff) | |
parent | 5ccc100322551c5b42556319d385efba3ca991ab (diff) | |
download | rspamd-f3bbf3f8f4dd26cceee798a83ac3882b6e0d8337.tar.gz rspamd-f3bbf3f8f4dd26cceee798a83ac3882b6e0d8337.zip |
Merge pull request #1556 from smfreegard/rules_170324
Rule update
-rw-r--r-- | conf/modules.d/once_received.conf | 1 | ||||
-rw-r--r-- | rules/headers_checks.lua | 25 | ||||
-rw-r--r-- | src/plugins/lua/once_received.lua | 14 |
3 files changed, 28 insertions, 12 deletions
diff --git a/conf/modules.d/once_received.conf b/conf/modules.d/once_received.conf index 93080d531..233d662ef 100644 --- a/conf/modules.d/once_received.conf +++ b/conf/modules.d/once_received.conf @@ -19,6 +19,7 @@ once_received { bad_host = "dynamic"; symbol_strict = "ONCE_RECEIVED_STRICT"; symbol = "ONCE_RECEIVED"; + symbol_mx = "DIRECT_TO_MX"; .include(try=true,priority=5) "${DBDIR}/dynamic/once_received.conf" .include(try=true,priority=1,duplicate=merge) "$LOCAL_CONFDIR/local.d/once_received.conf" diff --git a/rules/headers_checks.lua b/rules/headers_checks.lua index da48a8a1f..7e345b95a 100644 --- a/rules/headers_checks.lua +++ b/rules/headers_checks.lua @@ -210,17 +210,17 @@ local check_replyto_id = rspamd_config:register_callback_symbol('CHECK_REPLYTO', else if (from and from[1]) then -- See if From and Reply-To addresses match - if (from[1].addr:lower() == rt[1].addr:lower()) then + if (util.strequal_caseless(from[1].addr, rt[1].addr)) then task:insert_result('REPLYTO_ADDR_EQ_FROM', 1.0) elseif from[1].domain and rt[1].domain then - if (from[1].domain:lower() == rt[1].domain:lower()) then + if (util.streqal_caseless(from[1].domain, rt[1].domain)) then task:insert_result('REPLYTO_DOM_EQ_FROM_DOM', 1.0) else task:insert_result('REPLYTO_DOM_NEQ_FROM_DOM', 1.0) end end -- See if the Display Names match - if (from[1].name and rt[1].name and from[1].name:lower() == rt[1].name:lower()) then + if (from[1].name and rt[1].name and util.strequal_caseless(from[1].name, rt[1].name)) then task:insert_result('REPLYTO_DN_EQ_FROM_DN', 1.0) end end @@ -562,12 +562,12 @@ local check_from_id = rspamd_config:register_symbol{ callback = function(task) local envfrom = task:get_from(1) local from = task:get_from(2) - if (from and from[1] and not from[1].name) then + if (from and from[1] and (from[1].name == nil or from[1].name == '' )) then task:insert_result('FROM_NO_DN', 1.0) elseif (from and from[1] and from[1].name and - from[1].name:lower() == from[1].addr:lower()) then + util.strequal_caseless(from[1].name, from[1].addr)) then task:insert_result('FROM_DN_EQ_ADDR', 1.0) - elseif (from and from[1] and from[1].name) then + elseif (from and from[1] and from[1].name and from[1].name ~= '') then task:insert_result('FROM_HAS_DN', 1.0) -- Look for Mr/Mrs/Dr titles local n = from[1].name:lower() @@ -586,7 +586,7 @@ local check_from_id = rspamd_config:register_symbol{ end end if (envfrom and from and envfrom[1] and from[1] and - envfrom[1].addr:lower() == from[1].addr:lower()) + util.strequal_caseless(envfrom[1].addr, from[1].addr)) then task:insert_result('FROM_EQ_ENVFROM', 1.0) elseif (envfrom and envfrom[1] and envfrom[1].addr) then @@ -596,10 +596,11 @@ local check_from_id = rspamd_config:register_symbol{ local to = task:get_recipients(2) if not (to and to[1] and #to == 1 and from) then return false end -- Check if FROM == TO - if (to[1].addr:lower() == from[1].addr:lower()) then + if (util.strequal_caseless(to[1].addr, from[1].addr)) then task:insert_result('TO_EQ_FROM', 1.0) elseif (to[1].domain and from[1].domain and - to[1].domain:lower() == from[1].domain:lower()) then + util.strequal_caseless(to[1].domain, from[1].domain)) + then task:insert_result('TO_DOM_EQ_FROM_DOM', 1.0) end end @@ -713,16 +714,16 @@ local check_to_cc_id = rspamd_config:register_symbol{ or toa['name']:lower() == 'recipients')) then task:insert_result('TO_DN_RECIPIENTS', 1.0) end - if (toa['name'] and toa['name']:lower() == toa['addr']:lower()) then + if (toa['name'] and util.strequal_caseless(toa['name'], toa['addr'])) then to_dn_eq_addr_count = to_dn_eq_addr_count + 1 - elseif (toa['name']) then + elseif (toa['name'] and toa['name'] ~= '') then to_dn_count = to_dn_count + 1 end -- See if header recipients match envrcpts if (rcpts) then for _, rcpt in ipairs(rcpts) do if (toa and toa['addr'] and rcpt and rcpt['addr'] and - rcpt['addr']:lower() == toa['addr']:lower()) + util.strequal_caseless(rcpt['addr'], toa['addr'])) then to_match_envrcpt = to_match_envrcpt + 1 end diff --git a/src/plugins/lua/once_received.lua b/src/plugins/lua/once_received.lua index 00161159f..e1eea2ca5 100644 --- a/src/plugins/lua/once_received.lua +++ b/src/plugins/lua/once_received.lua @@ -18,6 +18,7 @@ limitations under the License. local symbol = 'ONCE_RECEIVED' local symbol_rdns = 'RDNS_NONE' +local symbol_mx = 'DIRECT_TO_MX' -- Symbol for strict checks local symbol_strict = nil local bad_hosts = {} @@ -40,6 +41,12 @@ local function check_quantity_received (task) if recvh and #recvh <= 1 then task:insert_result(symbol, 1) task:insert_result(symbol_strict, 1) + -- Check for MUAs + local ua = task:get_header('User-Agent') + local xm = task:get_header('X-Mailer') + if (ua or xm) then + task:insert_result(symbol_mx, 1, (ua or xm)) + end end task:insert_result(symbol_rdns, 1) else @@ -169,6 +176,8 @@ if opts then elseif n == 'whitelist' then whitelist = rspamd_map_add('once_received', 'whitelist', 'radix', 'once received whitelist') + elseif n == 'symbol_mx' then + symbol_mx = v end end @@ -182,5 +191,10 @@ if opts then type = 'virtual', parent = id }) + rspamd_config:register_symbol({ + name = symbol_mx, + type = 'virtual', + parent = id + }) end end |