aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-11-13 17:14:45 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-11-13 17:14:45 +0000
commite99a2a605b28fb194e993b96977890237f0d5d39 (patch)
treee5aeb30487722449e937a50e1c5737140376e1b0 /src/plugins/lua
parentf1d528aafbd690b95a23b684ba0be69f3c5f781c (diff)
downloadrspamd-e99a2a605b28fb194e993b96977890237f0d5d39.tar.gz
rspamd-e99a2a605b28fb194e993b96977890237f0d5d39.zip
Add support for check_for_shifted_date and check_for_missing_to_header eval rules to SA plugin
Diffstat (limited to 'src/plugins/lua')
-rw-r--r--src/plugins/lua/spamassassin.lua60
1 files changed, 54 insertions, 6 deletions
diff --git a/src/plugins/lua/spamassassin.lua b/src/plugins/lua/spamassassin.lua
index 53a1fc6cf..f766c8fb9 100644
--- a/src/plugins/lua/spamassassin.lua
+++ b/src/plugins/lua/spamassassin.lua
@@ -59,6 +59,9 @@ local replace = {
post = {},
rules = {},
}
+local internal_regexp = {
+ date_shift = rspamd_regexp.create_cached("^\\(\\s*'((?:-?\\d+)|(?:undef))'\\s*,\\s*'((?:-?\\d+)|(?:undef))'\\s*\\)$")
+}
local section = rspamd_config:get_all_opt("spamassassin")
-- Minimum score to treat symbols as meta
@@ -213,25 +216,70 @@ local function gen_eval_rule(arg)
return 0
end
end
-
+
return hdr_freemail
end
end
-
- return 0
+
+ return 0
+ end
+ },
+ {
+ 'check_for_missing_to_header',
+ function (task, remain)
+ if not task:get_from(1) then
+ return 1
+ end
+
+ return 0
+ end
+ },
+ {
+ 'check_for_shifted_date',
+ function (task, remain)
+ -- Remain here contains two args: start and end hours shift
+ local matches = internal_regexp['date_shift']:search(remain, true, true)
+ if matches and matches[1] then
+ local min_diff = matches[1][2]
+ local max_diff = matches[1][3]
+
+ if min_diff == 'undef' then
+ min_diff = 0
+ else
+ min_diff = tonumber(min_diff) * 3600
+ end
+ if max_diff == 'undef' then
+ max_diff = 0
+ else
+ max_diff = tonumber(max_diff) * 3600
+ end
+
+ -- Now get the difference between Date and message received date
+ local dm = task:get_date { format = 'message', gmt = true}
+ local dt = task:get_date { format = 'connect', gmt = true}
+ local diff = dm - dt
+
+ if (max_diff == 0 and diff >= min_diff) or
+ (min_diff == 0 and diff <= max_diff) or
+ (diff >= min_diff and diff <= max_diff) then
+ return 1
+ end
+ end
+
+ return 0
end
},
}
-
+
for k,f in ipairs(eval_funcs) do
local pat = string.format('^%s', f[1])
local first,last = string.find(arg, pat)
-
+
if first then
local func_arg = string.sub(arg, last + 1)
return function(task)
return f[2](task, func_arg)
- end
+ end
end
end
end