Deleted two http maps, replaced by redis multimaps, much better tag system

This commit is contained in:
andryyy
2017-05-08 15:39:33 +02:00
parent a18bcce93d
commit cdf7c87e20
6 changed files with 34 additions and 104 deletions

View File

@@ -13,12 +13,9 @@ modify_subject_map = rspamd_config:add_map({
description = 'Map of users to use subject tags for'
})
auth_domain_map = rspamd_config:add_map({
url = 'http://172.22.1.251:8081/authoritative.php',
type = 'map',
description = 'Map of domains we are authoritative for'
})
local redis_params
redis_params = rspamd_parse_redis_server('tag_settings')
if redis_params then
rspamd_config:register_symbol({
name = 'TAG_MOO',
type = 'postfilter',
@@ -27,12 +24,14 @@ rspamd_config:register_symbol({
local rspamd_logger = require "rspamd_logger"
local tagged_rcpt = task:get_symbol("TAGGED_RCPT")
local mailcow_domain = task:get_symbol("RCPT_MAILCOW_DOMAIN")
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
if tagged_rcpt and mailcow_domain then
local tag = tagged_rcpt[1].options[1]
rspamd_logger.infox("found tag: %s", tag)
local action = task:get_metric_action('default')
@@ -44,32 +43,27 @@ rspamd_config:register_symbol({
return true
end
if authdomain then
rspamd_logger.infox("found mailcow domain %s", domain)
rspamd_logger.infox("querying tag settings for user %s", rcpt)
local wants_subject_tag = task:get_symbol("RCPT_WANTS_SUBJECT_TAG")
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
if wants_subject_tag 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("skip delimiter handling for unknown domain")
rspamd_logger.infox("Add X-Moo-Tag header")
task:set_rmilter_reply({
add_headers = {['X-Moo-Tag'] = 'YES'}
})
end
return false
end
end,
priority = 10
})
end
rspamd_config.MRAPTOR = {
callback = function(task)