From 2b0bc647ac4be8ccfe455c072f3b3867aceece5b Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 7 Mar 2019 16:01:13 +0000 Subject: [PATCH] [Minor] Improve authentication results output Issue: #2772 Closes: #2772 --- lualib/lua_auth_results.lua | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/lualib/lua_auth_results.lua b/lualib/lua_auth_results.lua index b7c8bbc09..56761e957 100644 --- a/lualib/lua_auth_results.lua +++ b/lualib/lua_auth_results.lua @@ -17,6 +17,7 @@ limitations under the License. local global = require "global_functions" local rspamd_util = require "rspamd_util" +local fun = require "fun" local default_settings = { spf_symbols = { @@ -44,6 +45,9 @@ local default_settings = { none = 'ARC_NA', reject = 'ARC_REJECT', }, + dkim_symbols = { + none = 'R_DKIM_NA', + }, add_smtp_user = true, } @@ -140,10 +144,17 @@ local function gen_auth_results(task, settings) table.insert(hdr_parts, table.concat(hdr, ' ')) end + if #dkim_results == 0 then + -- We have no dkim results, so check for DKIM_NA symbol + if common.symbols[settings.dkim_symbols.none] then + table.insert(hdr_parts, 'dkim=none') + end + end + for auth_type, keys in pairs(auth_results) do for _, key in ipairs(keys) do local hdr = '' - if auth_type == 'dmarc' and key ~= 'none' then + if auth_type == 'dmarc' then local opts = common.symbols[auth_types['dmarc'][key]][1]['options'] or {} hdr = hdr .. 'dmarc=' if key == 'reject' or key == 'quarantine' or key == 'softfail' then @@ -155,13 +166,15 @@ local function gen_auth_results(task, settings) hdr = hdr .. ' (policy=' .. opts[2] .. ')' hdr = hdr .. ' header.from=' .. opts[1] elseif key ~= 'none' then - local t = global.rspamd_str_split(opts[1], ' : ') - local dom = t[1] - local rsn = t[2] - if rsn then - hdr = hdr .. ' reason="' .. rsn .. '"' + local t = {opts[1]:match('^([^%s]+) : (.*)$')} + if #t > 0 then + local dom = t[1] + local rsn = t[2] + if rsn then + hdr = hdr .. ' reason="' .. rsn .. '"' + end + hdr = hdr .. ' header.from=' .. dom end - hdr = hdr .. ' header.from=' .. dom if key == 'softfail' then hdr = hdr .. ' (policy=none)' else @@ -169,7 +182,7 @@ local function gen_auth_results(task, settings) end end table.insert(hdr_parts, hdr) - elseif auth_type == 'arc' and key ~= 'none' then + elseif auth_type == 'arc' then if common.symbols[auth_types['arc'][key]][1] then local opts = common.symbols[auth_types['arc'][key]][1]['options'] or {} for _, v in ipairs(opts) do @@ -177,7 +190,7 @@ local function gen_auth_results(task, settings) table.insert(hdr_parts, hdr) end end - elseif auth_type == 'spf' and key ~= 'none' then + elseif auth_type == 'spf' then -- Main type local sender local sender_type @@ -215,6 +228,9 @@ local function gen_auth_results(task, settings) elseif key == 'temperror' then comment = string.format('%s: error in processing during lookup of %s: DNS error', mta_hostname, sender) + elseif key == 'none' then + comment = string.format('%s: domain of %s has no SPF policy when checking %s', + mta_hostname, sender, tostring(task:get_from_ip() or 'unknown')) end hdr = string.format('%s=%s (%s) %s=%s', auth_type, key, comment, sender_type, sender) @@ -245,6 +261,9 @@ local function gen_auth_results(task, settings) end if #hdr_parts > 0 then + if #hdr_parts == 1 then + hdr_parts[2] = 'none' + end return table.concat(hdr_parts, '; ') end -- 2.39.5