aboutsummaryrefslogtreecommitdiffstats
path: root/rules/misc.lua
diff options
context:
space:
mode:
authorAnton Yuzhaninov <citrin+git@citrin.ru>2020-10-07 10:33:07 +0100
committerAnton Yuzhaninov <citrin+git@citrin.ru>2020-10-07 11:54:27 +0100
commitee429ed73788f3e6f7f39cc1fe6b1deee50c341b (patch)
treee0d1eb84df04dbeb883206cc23bfe27c0cbc952e /rules/misc.lua
parent967a9a4de30d1ee6bdb8cf1f0121c03422479f65 (diff)
downloadrspamd-ee429ed73788f3e6f7f39cc1fe6b1deee50c341b.tar.gz
rspamd-ee429ed73788f3e6f7f39cc1fe6b1deee50c341b.zip
[Feature] Add INVALID_DATE rule
The symbol indicates that a date in Date: header has invalid format and cannot be parsed by Rspamd.
Diffstat (limited to 'rules/misc.lua')
-rw-r--r--rules/misc.lua28
1 files changed, 21 insertions, 7 deletions
diff --git a/rules/misc.lua b/rules/misc.lua
index 5a65442ef..d12e09e2c 100644
--- a/rules/misc.lua
+++ b/rules/misc.lua
@@ -65,16 +65,21 @@ local date_id = rspamd_config:register_symbol({
return
end
- local dm = task:get_date({format = 'message', gmt = true})
+ local dm, err = util.parse_smtp_date(date_time)
+ if err then
+ task:insert_result('INVALID_DATE', 1.0)
+ return
+ end
+
local dt = task:get_date({format = 'connect', gmt = true})
+ local date_diff = dt - dm
- if dm > 0 and dm - dt > 7200 then
- -- 2 hours
- task:insert_result('DATE_IN_FUTURE', 1.0)
- return
- elseif dm > 0 and dt - dm > 86400 then
- -- A day
+ if date_diff > 86400 then
+ -- Older than a day
task:insert_result('DATE_IN_PAST', 1.0)
+ elseif -date_diff > 7200 then
+ -- More than 2 hours in the future
+ task:insert_result('DATE_IN_FUTURE', 1.0)
end
end
})
@@ -89,6 +94,15 @@ rspamd_config:register_symbol({
})
rspamd_config:register_symbol({
+ name = 'INVALID_DATE',
+ score = 1.5,
+ description = 'Malformed date header',
+ group = 'headers',
+ type = 'virtual',
+ parent = date_id,
+})
+
+rspamd_config:register_symbol({
name = 'DATE_IN_FUTURE',
score = 4.0,
description = 'Message date is in future',