From 2d9c862bad1428c369101510b4af1513b04ff0c2 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 3 May 2017 11:58:57 +0100 Subject: [PATCH] [Minor] Other style fixes in spamtrap --- src/plugins/lua/spamtrap.lua | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/plugins/lua/spamtrap.lua b/src/plugins/lua/spamtrap.lua index 06de27717..d4c496f64 100644 --- a/src/plugins/lua/spamtrap.lua +++ b/src/plugins/lua/spamtrap.lua @@ -20,6 +20,7 @@ limitations under the License. local rspamd_logger = require "rspamd_logger" local redis_params local use_redis = false; +local M = 'spamtrap' local settings = { symbol = 'SPAMTRAP', @@ -34,16 +35,21 @@ local settings = { local function spamtrap_cb(task) local rcpts = task:get_recipients('smtp') local called_for_domain = false - local target = nil + local target local function do_action(rcpt) if settings['learn_fuzzy'] then - rspamd_plugins.fuzzy_check.learn(task, settings['fuzzy_flag'], settings['fuzzy_weight']) + rspamd_plugins.fuzzy_check.learn(task, + settings['fuzzy_flag'], + settings['fuzzy_weight']) end if settings['learn_spam'] then task:set_flag("learn_spam") end - task:insert_result(settings['symbol'], settings['score'], rcpt) + task:insert_result(settings['symbol'], + settings['score'], + rcpt) + if settings['action'] then task:set_pre_result(settings['action'], string.format('spamtrap found: <%s>', rcpt)) @@ -76,7 +82,7 @@ local function spamtrap_cb(task) end called_for_domain = true else - return -- nothing found + rspamd_logger.debugm(M, task, 'skip spamtrap for %s', target) end end end @@ -97,10 +103,11 @@ local function spamtrap_cb(task) if not ret then rspamd_logger.errx(task, "redis request wasn't scheduled") end - else + elseif settings['map'] then if settings['map']:get_key(target) then do_action(target) else + rspamd_logger.debugm(M, task, 'skip spamtrap for %s', target) end end end @@ -117,12 +124,11 @@ if opts then settings[k] = v end if settings['map'] then - settings['name'] = settings['map'] - settings['map'] = rspamd_config:add_map({ - url = settings['name'], + settings['map'] = rspamd_config:add_map{ + url = settings['map'], description = "Spamtrap map for %s", settings['symbol'], type = "regexp" - }) + } else redis_params = rspamd_parse_redis_server('spamtrap') if not redis_params then -- 2.39.5