summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-05-14 13:43:18 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-05-14 13:43:18 +0100
commit5a870be97d168aa56710741e4db33a8db6d4eb26 (patch)
tree9a6d354744712175d5dd8cf2efb6dd8c5f95d8f5 /src
parentacb55a11b92782c0e95cbfa946acbdafc8beeea8 (diff)
downloadrspamd-5a870be97d168aa56710741e4db33a8db6d4eb26.tar.gz
rspamd-5a870be97d168aa56710741e4db33a8db6d4eb26.zip
[Feature] Support multiple return codes in emails module
Diffstat (limited to 'src')
-rw-r--r--src/plugins/lua/emails.lua54
1 files changed, 46 insertions, 8 deletions
diff --git a/src/plugins/lua/emails.lua b/src/plugins/lua/emails.lua
index f4d95d0ba..fb9e4eb31 100644
--- a/src/plugins/lua/emails.lua
+++ b/src/plugins/lua/emails.lua
@@ -55,24 +55,52 @@ local function check_email_rule(task, rule, addr)
logger.errx(task, 'Error querying DNS: %1', err)
elseif results then
local expected_found = false
+ local symbol = rule['symbol']
- if rule['expect_ip'] then
- for _,result in pairs(results) do
+ local function check_ip(ip)
+ for _,result in ipairs(results) do
local ipstr = result:to_string()
-
- if ipstr == rule['expect_ip'] then
- expected_found = true
+ if ipstr == ip then
+ return true
end
end
+
+ return false
+ end
+
+ if rule['expect_ip'] then
+ if check_ip(rule['expect_ip']) then
+ expected_found = true
+ end
else
expected_found = true -- Accept any result
end
+ if rule['returncodes'] then
+ for k,codes in pairs(rule['returncodes']) do
+ if type(codes) == 'table' then
+ for _,code in ipairs(codes) do
+ if check_ip(code) then
+ expected_found = true
+ symbol = k
+ break
+ end
+ end
+ else
+ if check_ip(codes) then
+ expected_found = true
+ symbol = k
+ break
+ end
+ end
+ end
+ end
+
if expected_found then
if rule['hash'] then
- task:insert_result(rule['symbol'], 1.0, {email, to_resolve})
+ task:insert_result(symbol, 1.0, {email, to_resolve})
else
- task:insert_result(rule['symbol'], 1.0, email)
+ task:insert_result(symbol, 1.0, email)
end
end
@@ -211,10 +239,20 @@ end
if #rules > 0 then
for _,rule in ipairs(rules) do
local cb = gen_check_emails(rule)
- rspamd_config:register_symbol({
+ local id = rspamd_config:register_symbol({
name = rule['symbol'],
callback = cb,
})
+
+ if rule.returncodes then
+ for k,_ in pairs(rule.returncodes) do
+ rspamd_config:register_symbol({
+ name = k,
+ parent = id,
+ type = 'virtual'
+ })
+ end
+ end
end
else
rspamd_lua_utils.disable_module(N, "conf")