aboutsummaryrefslogtreecommitdiffstats
path: root/rules/headers_checks.lua
diff options
context:
space:
mode:
authorJan Smutny <js@excello.cz>2020-04-18 21:17:06 +0200
committerJan Smutny <js@excello.cz>2020-04-19 00:22:14 +0200
commit23675060063301aaa3c93044e0029fda553d4e8f (patch)
tree2fa71609399fa2f5d8251e42d6a6ab99ed88acbf /rules/headers_checks.lua
parentacc9a3ceaa4c7f4eccf7d81de87935d814dc3fd5 (diff)
downloadrspamd-23675060063301aaa3c93044e0029fda553d4e8f.tar.gz
rspamd-23675060063301aaa3c93044e0029fda553d4e8f.zip
rules/headers_checks.lua: make CHECK_FROM callback a bit more efficient
Diffstat (limited to 'rules/headers_checks.lua')
-rw-r--r--rules/headers_checks.lua50
1 files changed, 26 insertions, 24 deletions
diff --git a/rules/headers_checks.lua b/rules/headers_checks.lua
index ae5c61836..9ceb60188 100644
--- a/rules/headers_checks.lua
+++ b/rules/headers_checks.lua
@@ -626,33 +626,35 @@ 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 (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
+ if (from and from[1]) then
+ if (from[1].name == nil or from[1].name == '' ) then
+ task:insert_result('FROM_NO_DN', 1.0)
+ elseif (from[1].name and
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 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()
- local match, match_end
- match, match_end = n:find('^mrs?[%.%s]')
- if match then
- task:insert_result('FROM_NAME_HAS_TITLE', 1.0, n:sub(match, match_end-1))
- end
- match, match_end = n:find('^dr[%.%s]')
- if match then
- task:insert_result('FROM_NAME_HAS_TITLE', 1.0, n:sub(match, match_end-1))
- end
- -- Check for excess spaces
- if n:find('%s%s') then
- task:insert_result('FROM_NAME_EXCESS_SPACE', 1.0)
+ task:insert_result('FROM_DN_EQ_ADDR', 1.0)
+ elseif (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()
+ local match, match_end
+ match, match_end = n:find('^mrs?[%.%s]')
+ if match then
+ task:insert_result('FROM_NAME_HAS_TITLE', 1.0, n:sub(match, match_end-1))
+ end
+ match, match_end = n:find('^dr[%.%s]')
+ if match then
+ task:insert_result('FROM_NAME_HAS_TITLE', 1.0, n:sub(match, match_end-1))
+ end
+ -- Check for excess spaces
+ if n:find('%s%s') then
+ task:insert_result('FROM_NAME_EXCESS_SPACE', 1.0)
+ end
end
- end
- if (envfrom and from and envfrom[1] and from[1] and
+ if (envfrom and envfrom[1] and
util.strequal_caseless(envfrom[1].addr, from[1].addr))
- then
- task:insert_result('FROM_EQ_ENVFROM', 1.0)
+ then
+ task:insert_result('FROM_EQ_ENVFROM', 1.0)
+ end
elseif (envfrom and envfrom[1] and envfrom[1].addr) then
task:insert_result('FROM_NEQ_ENVFROM', 1.0, ((from or E)[1] or E).addr or '', envfrom[1].addr)
end