From: Anton Yuzhaninov Date: Tue, 6 Oct 2020 17:17:33 +0000 (+0100) Subject: [Minor] Combine Date checks X-Git-Tag: 2.7~256^2~2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=967a9a4de30d1ee6bdb8cf1f0121c03422479f65;p=rspamd.git [Minor] Combine Date checks Combine Date header checks into a single callback. No functional changes. --- 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)