From c45aaab61f20780e889a8e79d03c9eca23d7f4d6 Mon Sep 17 00:00:00 2001 From: Andrew Lewis Date: Sun, 13 Nov 2016 13:13:47 +0200 Subject: [PATCH] [Minor] Some linting for rules --- rules/html.lua | 6 +----- rules/http_headers.lua | 4 ++-- rules/misc.lua | 12 ++++-------- rules/regexp/headers.lua | 7 ------- rules/rspamd.classifiers.lua | 23 ++++++++++------------- rules/rspamd.lua | 3 --- 6 files changed, 17 insertions(+), 38 deletions(-) diff --git a/rules/html.lua b/rules/html.lua index a5f861b2d..bedf0cc61 100644 --- a/rules/html.lua +++ b/rules/html.lua @@ -14,8 +14,6 @@ -- limitations under the License. local reconf = config['regexp'] -local rspamd_regexp = require "rspamd_regexp" -local rspamd_logger = require "rspamd_logger" -- Messages that have only HTML part reconf['MIME_HTML_ONLY'] = { @@ -184,7 +182,7 @@ rspamd_config.R_WHITE_ON_WHITE = { normal_len = p:get_length() local hc = p:get_html() -- we get HTML context - hc:foreach_tag({'font', 'span', 'div', 'p'}, function(tag, len) + hc:foreach_tag({'font', 'span', 'div', 'p'}, function(tag, _) local bl = tag:get_extra() if bl then if bl['bgcolor'] and bl['color'] and bl['visible'] then @@ -208,8 +206,6 @@ rspamd_config.R_WHITE_ON_WHITE = { color[1], color[2], color[3], bgcolor[1], bgcolor[2], bgcolor[3]) end - else - end end end diff --git a/rules/http_headers.lua b/rules/http_headers.lua index ceb1893df..04e9b5dd4 100644 --- a/rules/http_headers.lua +++ b/rules/http_headers.lua @@ -54,7 +54,7 @@ if opts and opts['symbols'] then end end -local opts = rspamd_config:get_all_opt('dkim') +opts = rspamd_config:get_all_opt('dkim') if opts then for k,_ in pairs(dkim_symbols) do if opts[k] then @@ -63,7 +63,7 @@ if opts then end end -local opts = rspamd_config:get_all_opt('spf') +opts = rspamd_config:get_all_opt('spf') if opts then for k,_ in pairs(spf_symbols) do if opts[k] then diff --git a/rules/misc.lua b/rules/misc.lua index 2fc93da32..53e8a66f8 100644 --- a/rules/misc.lua +++ b/rules/misc.lua @@ -18,9 +18,6 @@ limitations under the License. local util = require "rspamd_util" local rspamd_regexp = require "rspamd_regexp" -local rspamd_logger = require "rspamd_logger" - -local reconf = config['regexp'] -- Uncategorized rules local subject_re = rspamd_regexp.create('/^(?:(?:Re|Fwd|Fw|Aw|Antwort|Sv):\\s*)+(.+)$/i') @@ -54,7 +51,7 @@ end rspamd_config.SUBJ_ALL_CAPS = { callback = function(task) - local caps_test = function(sbj, len) + local caps_test = function(sbj, _) return util.is_uppercase(sbj) end return test_subject(task, caps_test, 1.0/40.0) @@ -66,7 +63,7 @@ rspamd_config.SUBJ_ALL_CAPS = { rspamd_config.LONG_SUBJ = { callback = function(task) - local length_test = function(sbj, len) + local length_test = function(_, len) return len > 200 end return test_subject(task, length_test, 1.0/400.0) @@ -161,7 +158,7 @@ rspamd_config.R_SUSPICIOUS_URL = { local urls = task:get_urls() if urls then - for i,u in ipairs(urls) do + for _,u in ipairs(urls) do if u:is_obscured() then task:insert_result('R_SUSPICIOUS_URL', 1.0, u:get_host()) end @@ -272,7 +269,7 @@ rspamd_config.MULTIPLE_UNIQUE_HEADERS = { local res = 0 local res_tbl = {} - for i,hdr in ipairs(headers_unique) do + for _,hdr in ipairs(headers_unique) do local h = task:get_header_full(hdr) if h and #h > 1 then @@ -372,7 +369,6 @@ rspamd_config.RCVD_TLS_ALL = { for _, rcvd in ipairs(rcvds) do count = count + 1 local r = rcvd['decoded']:lower() - local by = r:match('^by%s+([^%s]+)') or r:match('%sby%s+([^%s]+)') local with = r:match('%swith%s+(e?smtps?a?)') if with and with:match('esmtps') then encrypted = encrypted + 1 diff --git a/rules/regexp/headers.lua b/rules/regexp/headers.lua index 56f710650..ef0adc6b1 100644 --- a/rules/regexp/headers.lua +++ b/rules/regexp/headers.lua @@ -529,7 +529,6 @@ reconf['FM_FAKE_HELO_VERIZON'] = { -- Forged yahoo msgid local at_yahoo_msgid = 'Message-Id=/\\@yahoo\\.com\\b/iH' -local at_yahoogroups_msgid = 'Message-Id=/\\@yahoogroups\\.com\\b/iH' local from_yahoo_com = 'From=/\\@yahoo\\.com\\b/iH' reconf['FORGED_MSGID_YAHOO'] = { re = string.format('(%s) & !(%s)', at_yahoo_msgid, from_yahoo_com), @@ -537,8 +536,6 @@ reconf['FORGED_MSGID_YAHOO'] = { description = 'Forged yahoo msgid', group = 'header' } -local r_from_yahoo_groups = 'From=/rambler.ru\\@returns\\.groups\\.yahoo\\.com\\b/iH' -local r_from_yahoo_groups_ro = 'From=/ro.ru\\@returns\\.groups\\.yahoo\\.com\\b/iH' -- Forged The Bat! MUA headers local thebat_mua_v1 = 'X-Mailer=/^The Bat! \\(v1\\./H' @@ -564,8 +561,6 @@ reconf['RCVD_DOUBLE_IP_SPAM'] = { -- Quoted reply-to from yahoo (seems to be forged) local repto_quote = 'Reply-To=/\\".*\\"\\s*\\ 5 then - table.foreach(st_many, function(i,v) table.insert(spec_st,v) end) + fun.each(function(_,v) table.insert(spec_st,v) end, st_many) end end -- Undisclosed @@ -43,7 +40,7 @@ local function get_specific_statfiles(classifier, task) if st_undisc then local rcpt = task:get_recipients(2) if rcpt and #rcpt == 0 then - table.foreach(st_undisc, function(i,v) table.insert(spec_st,v) end) + fun.each(function(_,v) table.insert(spec_st,v) end, st_undisc) end end -- Maillist @@ -51,7 +48,7 @@ local function get_specific_statfiles(classifier, task) if st_maillist then local unsub_header = task:get_header_raw('List-Unsubscribe') if unsub_header then - table.foreach(st_maillist, function(i,v) table.insert(spec_st,v) end) + fun.each(function(_,v) table.insert(spec_st,v) end, st_maillist) end end -- Long subject @@ -59,7 +56,7 @@ local function get_specific_statfiles(classifier, task) if st_longsubj then local subj = task:get_header_raw('Subject') if subj and string.len(subj) > 150 then - table.foreach(st_longsubj, function(i,v) table.insert(spec_st,v) end) + fun.each(function(_,v) table.insert(spec_st,v) end, st_longsubj) end end @@ -70,9 +67,9 @@ local function get_specific_statfiles(classifier, task) end end -classifiers['bayes'] = function(classifier, task, is_learn, is_spam) +classifiers['bayes'] = function(classifier, task, is_learn, _) -- Subfunction for detection of message's language - local detect_language = function(task) + local detect_language = function() local parts = task:get_text_parts() for _,p in ipairs(parts) do local l = p:get_language() @@ -91,11 +88,11 @@ classifiers['bayes'] = function(classifier, task, is_learn, is_spam) return spec_st else -- Merge tables - table.foreach(spec_st, function(i,v) table.insert(selected,v) end) + fun.each(function(_,v) table.insert(selected,v) end, spec_st) end end -- Detect statfile by language - local language = detect_language(task) + local language = detect_language() if language then -- Find statfiles with specified language for _,st in ipairs(classifier:get_statfiles()) do diff --git a/rules/rspamd.lua b/rules/rspamd.lua index 086f81497..f5a5ed14e 100644 --- a/rules/rspamd.lua +++ b/rules/rspamd.lua @@ -16,10 +16,7 @@ limitations under the License. -- This is main lua config file for rspamd -local util = require "rspamd_util" - config['regexp'] = {} -local reconf = config['regexp'] local local_conf = rspamd_paths['CONFDIR'] local local_rules = rspamd_paths['RULESDIR'] -- 2.39.5