aboutsummaryrefslogtreecommitdiffstats
path: root/rules/misc.lua
diff options
context:
space:
mode:
authorAnton Yuzhaninov <citrin+git@citrin.ru>2020-10-06 18:17:33 +0100
committerAnton Yuzhaninov <citrin+git@citrin.ru>2020-10-06 18:17:33 +0100
commit967a9a4de30d1ee6bdb8cf1f0121c03422479f65 (patch)
treee2954382e719539b0c200d1153c4141fe0c67d2c /rules/misc.lua
parent0c312c81f3009ae9b679c7739531181f7f8b4222 (diff)
downloadrspamd-967a9a4de30d1ee6bdb8cf1f0121c03422479f65.tar.gz
rspamd-967a9a4de30d1ee6bdb8cf1f0121c03422479f65.zip
[Minor] Combine Date checks
Combine Date header checks into a single callback. No functional changes.
Diffstat (limited to 'rules/misc.lua')
-rw-r--r--rules/misc.lua69
1 files changed, 37 insertions, 32 deletions
diff --git a/rules/misc.lua b/rules/misc.lua
index 88895c2b9..5a65442ef 100644
--- a/rules/misc.lua
+++ b/rules/misc.lua
@@ -55,51 +55,56 @@ rspamd_config.R_PARTS_DIFFER = {
}
-- Date issues
-rspamd_config.MISSING_DATE = {
+local date_id = rspamd_config:register_symbol({
+ name = 'DATE_CB',
+ type = 'callback,mime',
callback = function(task)
- local date = task:get_header_raw('Date')
- if date == nil or date == '' then
- return true
+ local date_time = task:get_header('Date')
+ if date_time == nil or date_time == '' then
+ task:insert_result('MISSING_DATE', 1.0)
+ return
end
- return false
- end,
+
+ local dm = task:get_date({format = 'message', gmt = true})
+ local dt = task:get_date({format = 'connect', gmt = true})
+
+ 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
+ task:insert_result('DATE_IN_PAST', 1.0)
+ end
+ end
+})
+
+rspamd_config:register_symbol({
+ name = 'MISSING_DATE',
score = 1.0,
description = 'Message date is missing',
group = 'headers',
- type = 'mime',
-}
+ type = 'virtual',
+ parent = date_id,
+})
-rspamd_config.DATE_IN_FUTURE = {
- callback = function(task)
- local dm = task:get_date{format = 'message', gmt = true}
- local dt = task:get_date{format = 'connect', gmt = true}
- -- 2 hours
- if dm > 0 and dm - dt > 7200 then
- return true
- end
- return false
- end,
+rspamd_config:register_symbol({
+ name = 'DATE_IN_FUTURE',
score = 4.0,
description = 'Message date is in future',
group = 'headers',
- type = 'mime',
-}
+ type = 'virtual',
+ parent = date_id,
+})
-rspamd_config.DATE_IN_PAST = {
- callback = function(task)
- local dm = task:get_date{format = 'message', gmt = true}
- local dt = task:get_date{format = 'connect', gmt = true}
- -- A day
- if dm > 0 and dt - dm > 86400 then
- return true
- end
- return false
- end,
+rspamd_config:register_symbol({
+ name = 'DATE_IN_PAST',
score = 1.0,
description = 'Message date is in past',
group = 'headers',
- type = 'mime',
-}
+ type = 'virtual',
+ parent = date_id,
+})
local obscured_id = rspamd_config:register_symbol{
callback = function(task)