From: Anton Yuzhaninov Date: Tue, 22 Dec 2020 13:05:58 +0000 (+0000) Subject: [Minor] Use task:has_header instead of task:get_header X-Git-Tag: 2.7~49^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F3581%2Fhead;p=rspamd.git [Minor] Use task:has_header instead of task:get_header Use task:has_header() to check if header is exists. --- diff --git a/rules/forwarding.lua b/rules/forwarding.lua index cbbb62c53..0d8c3619e 100644 --- a/rules/forwarding.lua +++ b/rules/forwarding.lua @@ -54,9 +54,7 @@ rspamd_config.FWD_YANDEX = { end local hostname = task:get_hostname() if hostname and hostname:lower():find('%.yandex%.[a-z]+$') then - if task:get_header_raw('X-Yandex-Forward') then - return true - end + return task:has_header('X-Yandex-Forward') end return false end, @@ -72,9 +70,7 @@ rspamd_config.FWD_MAILRU = { end local hostname = task:get_hostname() if hostname and hostname:lower():find('%.mail%.ru$') then - if task:get_header_raw('X-MailRu-Forward') then - return true - end + return task:has_header('X-MailRu-Forward') end return false end, @@ -124,7 +120,7 @@ rspamd_config.FORWARDED = { -- Forwarding will only be for single recipient messages if #envrcpts > 1 then return false end -- Get any other headers we might need - local lu = task:get_header('List-Unsubscribe') + local has_list_unsub = task:has_header('List-Unsubscribe') local to = task:get_recipients(2) local matches = 0 -- Retrieve and loop through all Received headers @@ -139,7 +135,7 @@ rspamd_config.FORWARDED = { -- Check that it doesn't match the envrcpt if not rspamd_util.strequal_caseless(addr, envrcpts[1].addr) then -- Check for mailing-lists as they will have the same signature - if matches < 2 and lu and to and rspamd_util.strequal_caseless(to[1].addr, addr) then + if matches < 2 and has_list_unsub and to and rspamd_util.strequal_caseless(to[1].addr, addr) then return false else return true, 1.0, addr diff --git a/rules/headers_checks.lua b/rules/headers_checks.lua index b62676293..c4e4a4a67 100644 --- a/rules/headers_checks.lua +++ b/rules/headers_checks.lua @@ -340,17 +340,17 @@ local check_mime_id = rspamd_config:register_symbol{ callback = function(task) -- Check if there is a MIME-Version header local missing_mime = false - if not task:get_header('MIME-Version') then + if not task:has_header('MIME-Version') then missing_mime = true end -- Check presense of MIME specific headers - local ct_header = task:get_header('Content-Type') - local cte_header = task:get_header('Content-Transfer-Encoding') + local has_ct_header = task:has_header('Content-Type') + local has_cte_header = task:has_header('Content-Transfer-Encoding') -- Add the symbol if we have MIME headers, but no MIME-Version -- (do not add the symbol for RFC822 messages) - if (ct_header or cte_header) and missing_mime then + if (has_ct_header or has_cte_header) and missing_mime then task:insert_result('MISSING_MIME_VERSION', 1.0) end @@ -595,8 +595,7 @@ rspamd_config.MULTIPLE_FROM = { rspamd_config.MV_CASE = { callback = function (task) - local mv = task:get_header('Mime-Version', true) - if (mv) then return true end + return task:has_header('Mime-Version', true) end, description = 'Mime-Version .vs. MIME-Version', score = 0.5, @@ -1117,8 +1116,7 @@ rspamd_config.INVALID_RCPT_8BIT = { rspamd_config.XM_CASE = { callback = function (task) - local xm = task:get_header('X-mailer', true) - if (xm) then return true end + return task:has_header('X-mailer', true) end, description = 'X-mailer .vs. X-Mailer', score = 0.5, diff --git a/rules/misc.lua b/rules/misc.lua index a0b46f0fb..8b73f522f 100644 --- a/rules/misc.lua +++ b/rules/misc.lua @@ -638,8 +638,9 @@ rspamd_config.SPOOF_REPLYTO = { rspamd_config.INFO_TO_INFO_LU = { callback = function(task) - local lu = task:get_header('List-Unsubscribe') - if not lu then return false end + if not task:has_header('List-Unsubscribe') then + return false + end local from = task:get_from('mime') if not (from and from[1] and util.strequal_caseless(from[1].user, 'info')) then return false diff --git a/src/plugins/lua/maillist.lua b/src/plugins/lua/maillist.lua index 1fdfef010..a5d879d05 100644 --- a/src/plugins/lua/maillist.lua +++ b/src/plugins/lua/maillist.lua @@ -169,17 +169,7 @@ end -- RFC 2919 headers exist -- local function check_ml_googlegroup(task) - local header = task:get_header('X-Google-Loop') - - if not header then - header = task:get_header('X-Google-Group-Id') - - if not header then - return false - end - end - - return true + return task:has_header('X-Google-Loop') or task:has_header('X-Google-Group-Id') end -- CGP detector diff --git a/src/plugins/lua/spamassassin.lua b/src/plugins/lua/spamassassin.lua index 5a8615d6c..911661ed9 100644 --- a/src/plugins/lua/spamassassin.lua +++ b/src/plugins/lua/spamassassin.lua @@ -586,7 +586,7 @@ local function maybe_parse_sa_function(line) end for _,h in ipairs(hdrs_check) do - if task:get_header(h) then + if task:has_header(h) then return 1 end end