From: Vsevolod Stakhov Date: Mon, 17 May 2021 15:34:17 +0000 (+0100) Subject: [Minor] Dmarc: Slightly refactor function X-Git-Tag: 3.0~398 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d2ed10141ba44a5de8ae8d54d73ee95cbe1e07cf;p=rspamd.git [Minor] Dmarc: Slightly refactor function --- diff --git a/src/plugins/lua/dmarc.lua b/src/plugins/lua/dmarc.lua index d6dc4947c..aae556c96 100644 --- a/src/plugins/lua/dmarc.lua +++ b/src/plugins/lua/dmarc.lua @@ -758,7 +758,44 @@ if opts['symbols'] then end end --- XXX: rework this shitty code some day please +-- Reporting related code -- + +--- +--- Converts a reporting entry to an XML format +--- @param data data table +--- @return string with an XML representation +local function entry_to_xml(data) + local buf = { + table.concat({ + '', data.ip, '', + data.count, '', + data.disposition, '', data.dkim_disposition, + '', data.spf_disposition, '' + }), + } + if data.override ~= '' then + table.insert(buf, string.format('%s', data.override)) + end + table.insert(buf, table.concat({ + '', data.header_from, + '', + })) + table.insert(buf, '') + if data.dkim_results[1] then + for _, d in ipairs(data.dkim_results) do + table.insert(buf, table.concat({ + '', d.domain, '', + d.result, '', + })) + end + end + table.insert(buf, table.concat({ + '', data.spf_domain, '', + data.spf_result, '', + })) + return table.concat(buf) +end + if opts['reporting'] == true then redis_params = rspamd_parse_redis_server('dmarc') if not redis_params then @@ -808,37 +845,6 @@ if opts['reporting'] == true then local domain_policy = {} local to_verify = {} local cursor = 0 - local function entry_to_xml(data) - local buf = { - table.concat({ - '', data.ip, '', - data.count, '', - data.disposition, '', data.dkim_disposition, - '', data.spf_disposition, '' - }), - } - if data.override ~= '' then - table.insert(buf, string.format('%s', data.override)) - end - table.insert(buf, table.concat({ - '', data.header_from, - '', - })) - table.insert(buf, '') - if data.dkim_results[1] then - for _, d in ipairs(data.dkim_results) do - table.insert(buf, table.concat({ - '', d.domain, '', - d.result, '', - })) - end - end - table.insert(buf, table.concat({ - '', data.spf_domain, '', - data.spf_result, '', - })) - return table.concat(buf) - end local function dmarc_report_xml() local entries = {} report_id = string.format('%s.%d.%d',