From e9261b7c8ebcea93e0b8bbe6fc847d1168a25a4d Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 29 Jul 2017 16:22:46 +0100 Subject: [PATCH] [Minor] Some more minor fixes to lua --- rules/headers_checks.lua | 15 ++++++--------- src/plugins/lua/fann_redis.lua | 19 +++++++++---------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/rules/headers_checks.lua b/rules/headers_checks.lua index 2e4bae307..25cb263ff 100644 --- a/rules/headers_checks.lua +++ b/rules/headers_checks.lua @@ -920,15 +920,12 @@ rspamd_config.CTYPE_MIXED_BOGUS = { local found = false -- Check each part and look for a part that isn't multipart/* or text/plain or text/html for _,p in ipairs(parts) do - local ct = p:get_header('Content-Type') - if (ct) then - ct = ct:lower() - if (ct:match('^multipart/') or - ct:match('^text/plain') or - ct:match('^text/html')) - then - -- Nothing - else + local pct = p:get_header('Content-Type') + if (pct) then + pct = pct:lower() + if not ((pct:match('^multipart/') or + pct:match('^text/plain') or + pct:match('^text/html'))) then found = true end end diff --git a/src/plugins/lua/fann_redis.lua b/src/plugins/lua/fann_redis.lua index ee73a5bf9..378000a24 100644 --- a/src/plugins/lua/fann_redis.lua +++ b/src/plugins/lua/fann_redis.lua @@ -423,18 +423,19 @@ local function load_or_invalidate_fann(data, id, ev_base) end end -local function fann_train_callback(task, score, required_score, id, opts) +local function fann_train_callback(task, score, required_score, id) + local train_opts = opts['train'] local fname,suffix = gen_fann_prefix(id) local learn_spam, learn_ham - if opts['spam_score'] then - learn_spam = score >= opts['spam_score'] + if train_opts['spam_score'] then + learn_spam = score >= train_opts['spam_score'] else learn_spam = score >= required_score end - if opts['ham_score'] then - learn_ham = score <= opts['ham_score'] + if train_opts['ham_score'] then + learn_ham = score <= train_opts['ham_score'] else learn_ham = score < 0 end @@ -469,7 +470,7 @@ local function fann_train_callback(task, score, required_score, id, opts) if err then rspamd_logger.errx(rspamd_config, 'cannot check if we can train %s: %s', fname, err) if string.match(err, 'NOSCRIPT') then - load_scripts(rspamd_config, ev_base, nil) + load_scripts(rspamd_config, task:get_ev_base(), nil) end end end @@ -836,11 +837,9 @@ local function ann_push_vector(task) local scores = task:get_metric_score() local sid = task:get_settings_id() if use_settings then - fann_train_callback(task, scores[1], scores[2], - tostring(sid), opts['train']) + fann_train_callback(task, scores[1], scores[2], tostring(sid)) else - fann_train_callback(task, scores[1], scores[2], - tostring(sid), opts['train']) + fann_train_callback(task, scores[1], scores[2], "1") end end -- 2.39.5