aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/lua/once_received.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-04-20 16:38:37 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-04-20 16:38:37 +0100
commit7f0966b5fbb77ed821a302b1f467c5d6d864a76e (patch)
treedfb2bff3c02f6f5b815c5b38af7f4dc914800db3 /src/plugins/lua/once_received.lua
parentd4a35f5b65dea20d990b8a82835396bbca5cfb52 (diff)
downloadrspamd-7f0966b5fbb77ed821a302b1f467c5d6d864a76e.tar.gz
rspamd-7f0966b5fbb77ed821a302b1f467c5d6d864a76e.zip
[Fix] Various fixes to once_received module
- Exclude artificial headers - Avoid extra '#' operations - Do not insert ONCE_RECEIVED if MTA has not resolved the first received (#2190)
Diffstat (limited to 'src/plugins/lua/once_received.lua')
-rw-r--r--src/plugins/lua/once_received.lua25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/plugins/lua/once_received.lua b/src/plugins/lua/once_received.lua
index 503a98345..527cf9a62 100644
--- a/src/plugins/lua/once_received.lua
+++ b/src/plugins/lua/once_received.lua
@@ -29,13 +29,22 @@ local symbol_strict = nil
local bad_hosts = {}
local good_hosts = {}
local whitelist = nil
+
local rspamd_logger = require "rspamd_logger"
+local fun = require "fun"
+
local check_local = false
local check_authed = false
local function check_quantity_received (task)
local recvh = task:get_received_headers()
+ local nreceived = fun.reduce(function(acc, rcvd)
+ return acc + 1
+ end, 0, fun.filter(function(h)
+ return not h['artificial']
+ end, recvh))
+
local function recv_dns_cb(_, to_resolve, results, err)
if err and (err ~= 'requested record is not found' and err ~= 'no records with this name') then
rspamd_logger.errx(task, 'error looking up %s: %s', to_resolve, err)
@@ -44,7 +53,7 @@ local function check_quantity_received (task)
task:inc_dns_req()
if not results then
- if recvh and #recvh <= 1 then
+ if nreceived <= 1 then
task:insert_result(symbol, 1)
task:insert_result(symbol_strict, 1)
-- Check for MUAs
@@ -66,12 +75,14 @@ local function check_quantity_received (task)
end
end
- task:insert_result(symbol, 1)
- for _,h in ipairs(bad_hosts) do
- if string.find(results[1], h) then
+ if nreceived <= 1 then
+ task:insert_result(symbol, 1)
+ for _,h in ipairs(bad_hosts) do
+ if string.find(results[1], h) then
- task:insert_result(symbol_strict, 1, h)
- return
+ task:insert_result(symbol_strict, 1, h)
+ return
+ end
end
end
end
@@ -101,7 +112,7 @@ local function check_quantity_received (task)
return
end
- if recvh and #recvh <= 1 then
+ if nreceived <= 1 then
local ret = true
local r = recvh[1]