From 5aa8400c1fddc761a333b333c72ad00e108702c2 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 25 Mar 2015 21:48:07 +0000 Subject: [PATCH] Add support for 'full' and 'uri' rules. --- src/plugins/lua/spamassassin.lua | 35 ++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/plugins/lua/spamassassin.lua b/src/plugins/lua/spamassassin.lua index f9b39af29..8aad56618 100644 --- a/src/plugins/lua/spamassassin.lua +++ b/src/plugins/lua/spamassassin.lua @@ -182,7 +182,7 @@ local function process_sa_conf(f) cur_rule['re_expr'] = words_to_re(words, 2) cur_rule['re'] = rspamd_regexp.create_cached(cur_rule['re_expr']) if cur_rule['re'] then valid_rule = true end - elseif words[1] == "rawbody" and slash then + elseif words[1] == "rawbody" or words[1] == "full" and slash then -- body SYMBOL /regexp/ if valid_rule then insert_cur_rule() @@ -192,6 +192,16 @@ local function process_sa_conf(f) cur_rule['re_expr'] = words_to_re(words, 2) cur_rule['re'] = rspamd_regexp.create_cached(cur_rule['re_expr']) if cur_rule['re'] then valid_rule = true end + elseif words[1] == "uri" then + -- uri SYMBOL /regexp/ + if valid_rule then + insert_cur_rule() + end + cur_rule['type'] = 'uri' + cur_rule['symbol'] = words[2] + cur_rule['re_expr'] = words_to_re(words, 2) + cur_rule['re'] = rspamd_regexp.create_cached(cur_rule['re_expr']) + if cur_rule['re'] then valid_rule = true end elseif words[1] == "meta" then -- meta SYMBOL expression if valid_rule then @@ -334,6 +344,27 @@ _.each(function(k, r) return r['type'] == 'message' end, rules)) +-- URL rules +_.each(function(k, r) + local f = function(task) + local urls = task:get_urls() + for _,u in ipairs(urls) do + if (r['re']:match(u:get_text())) then + return 1 + end + end + return 0 + end + if r['score'] then + rspamd_config:set_metric_symbol(k, r['score'], r['description']) + end + --rspamd_config:register_symbol(k, calculate_score(k), f) + atoms[k] = f + end, + _.filter(function(k, r) + return r['type'] == 'uri' + end, + rules)) local sa_mempool = rspamd_mempool.create() @@ -354,7 +385,7 @@ local function process_atom(atom, task) if atom_cb then return atom_cb(task) else - --rspamd_logger.err('Cannot find atom ' .. atom) + rspamd_logger.err('Cannot find atom ' .. atom) end return 0 end -- 2.39.5