From: Vsevolod Stakhov Date: Mon, 16 Feb 2015 23:50:34 +0000 (+0000) Subject: Allow to use SA header rules. X-Git-Tag: 0.9.0~685 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=be7c52baebbc5134d57ec775ff789cb5fb8ab5b5;p=thirdparty%2Frspamd.git Allow to use SA header rules. --- diff --git a/src/plugins/lua/spamassassin.lua b/src/plugins/lua/spamassassin.lua index d62675af4a..2cc59ff6ef 100644 --- a/src/plugins/lua/spamassassin.lua +++ b/src/plugins/lua/spamassassin.lua @@ -111,6 +111,8 @@ local function process_sa_conf(f) if cur_rule['meta'] then valid_rule = true end elseif words[1] == "describe" and valid_rule then cur_rule['description'] = words_to_re(words, 1) + elseif words[1] == "score" and valid_rule then + cur_rule['score'] = tonumber(words_to_re(words, 1)[1]) end end)() end @@ -126,4 +128,41 @@ if type(section) == "table" then process_sa_conf(f) end end -end \ No newline at end of file +end + +-- Now check all valid rules and add the according rspamd rules + +-- Meta rules +_.each(function(k, r) + rspamd_config:add_composite(k, r['meta']) + if r['score'] then + rspamd_config:set_metric_symbol(k, r['score'], r['description']) + end + end, + _.filter(function(k, r) + return r['type'] == 'meta' + end, + rules)) + +-- Header rules +_.each(function(k, r) + local f = function(task) + local hdr = task:get_header_full(r['header']) + if hdr then + for n, rh in ipairs(hdr) do + -- Subject for optimization + if (r['re']:match(rh['decoded'])) then + task:insert_result(k, 1.0) + end + end + end + end + rspamd_config:register_symbol(k, 1.0, f) + if r['score'] then + rspamd_config:set_metric_symbol(k, r['score'], r['description']) + end + end, + _.filter(function(k, r) + return r['type'] == 'header' and r['header'] + end, + rules)) \ No newline at end of file