From 509a804acdb0d7eaa5eb2e2cca199a068fb58efc Mon Sep 17 00:00:00 2001 From: andryyy Date: Thu, 16 Mar 2017 13:42:56 +0100 Subject: [PATCH] Deprecated lua function replaced, better tag handling when spam --- data/conf/rspamd/lua/rspamd.local.lua | 85 ++++++++++++++------------- 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/data/conf/rspamd/lua/rspamd.local.lua b/data/conf/rspamd/lua/rspamd.local.lua index 236734f2..60516991 100644 --- a/data/conf/rspamd/lua/rspamd.local.lua +++ b/data/conf/rspamd/lua/rspamd.local.lua @@ -23,51 +23,56 @@ auth_domain_map = rspamd_config:add_map({ description = 'Map of domains we are authoritative for' }) -rspamd_config:register_post_filter(function(task) - local util = require("rspamd_util") - local rspamd_logger = require "rspamd_logger" +rspamd_config:register_symbol({ + name = 'TAG_MOO', + type = 'postfilter', + callback = function(task) + local util = require("rspamd_util") + local rspamd_logger = require "rspamd_logger" - local tagged_rcpt = task:get_symbol("TAGGED_RCPT") - local user = task:get_recipients(0)[1]['user'] - local domain = task:get_recipients(0)[1]['domain'] - local rcpt = user .. '@' .. domain - local authdomain = auth_domain_map:get_key(domain) + local tagged_rcpt = task:get_symbol("TAGGED_RCPT") + local user = task:get_recipients(0)[1]['user'] + local domain = task:get_recipients(0)[1]['domain'] + local rcpt = user .. '@' .. domain + local authdomain = auth_domain_map:get_key(domain) - if tagged_rcpt then - local tag = tagged_rcpt[1].options[1] - rspamd_logger.infox("found tag: %s", tag) - local action = task:get_metric_action('default') - rspamd_logger.infox("metric action now: %s", action) + if tagged_rcpt then + local tag = tagged_rcpt[1].options[1] + rspamd_logger.infox("found tag: %s", tag) + local action = task:get_metric_action('default') + rspamd_logger.infox("metric action now: %s", action) - if action ~= 'no action' and action ~= 'greylist' then - rspamd_logger.infox("skipping tag handler for action: %s", action) + if action ~= 'no action' and action ~= 'greylist' then + rspamd_logger.infox("skipping tag handler for action: %s", action) + task:set_metric_action('default', action) + end + + if authdomain then + rspamd_logger.infox("found mailcow domain %s", domain) + rspamd_logger.infox("querying tag settings for user %s", rcpt) + + if modify_subject_map:get_key(rcpt) then + rspamd_logger.infox("user wants subject modified for tagged mail") + local sbj = task:get_header('Subject') + new_sbj = '=?UTF-8?B?' .. tostring(util.encode_base64('[' .. tag .. '] ' .. sbj)) .. '?=' + task:set_rmilter_reply({ + remove_headers = {['Subject'] = 1}, + add_headers = {['Subject'] = new_sbj} + }) + else + rspamd_logger.infox("Add X-Moo-Tag header") + task:set_rmilter_reply({ + add_headers = {['X-Moo-Tag'] = 'YES'} + }) + end + else + rspamd_logger.infox("skip delimiter handling for unknown domain") + end return false end - - if authdomain then - rspamd_logger.infox("found mailcow domain %s", domain) - rspamd_logger.infox("querying tag settings for user %s", rcpt) - - if modify_subject_map:get_key(rcpt) then - rspamd_logger.infox("user wants subject modified for tagged mail") - local sbj = task:get_header('Subject') - new_sbj = '=?UTF-8?B?' .. tostring(util.encode_base64('[' .. tag .. '] ' .. sbj)) .. '?=' - task:set_rmilter_reply({ - remove_headers = {['Subject'] = 1}, - add_headers = {['Subject'] = new_sbj} - }) - else - rspamd_logger.infox("Add X-Moo-Tag header") - task:set_rmilter_reply({ - add_headers = {['X-Moo-Tag'] = 'YES'} - }) - end - else - rspamd_logger.infox("skip delimiter handling for unknown domain") - end - return false - end -end) + end, + priority = 10 +}) rspamd_config.MRAPTOR = { callback = function(task)