mirror of
https://github.com/mailcow/mailcow-dockerized.git
synced 2024-12-12 10:45:14 +02:00
Add ability to set tag handling, add domain map
This commit is contained in:
parent
603902014a
commit
49a98a30b5
22
data/conf/rspamd/dynmaps/authoritative.php
Normal file
22
data/conf/rspamd/dynmaps/authoritative.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
ini_set('error_reporting', 0);
|
||||||
|
header('Content-Type: text/plain');
|
||||||
|
require_once "vars.inc.php";
|
||||||
|
$dsn = $database_type . ':host=' . $database_host . ';dbname=' . $database_name;
|
||||||
|
$opt = [
|
||||||
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||||
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||||
|
PDO::ATTR_EMULATE_PREPARES => false,
|
||||||
|
];
|
||||||
|
$pdo = new PDO($dsn, $database_user, $database_pass, $opt);
|
||||||
|
$stmt = $pdo->query("SELECT `domain` FROM `domain`");
|
||||||
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
while ($row = array_shift($rows)) {
|
||||||
|
echo strtolower(trim($row['domain'])) . PHP_EOL;
|
||||||
|
}
|
||||||
|
$stmt = $pdo->query("SELECT `alias_domain` FROM `alias_domain`");
|
||||||
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
while ($row = array_shift($rows)) {
|
||||||
|
echo strtolower(trim($row['alias_domain'])) . PHP_EOL;
|
||||||
|
}
|
||||||
|
?>
|
17
data/conf/rspamd/dynmaps/tags.php
Normal file
17
data/conf/rspamd/dynmaps/tags.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
ini_set('error_reporting', 0);
|
||||||
|
header('Content-Type: text/plain');
|
||||||
|
require_once "vars.inc.php";
|
||||||
|
$dsn = $database_type . ':host=' . $database_host . ';dbname=' . $database_name;
|
||||||
|
$opt = [
|
||||||
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||||
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||||
|
PDO::ATTR_EMULATE_PREPARES => false,
|
||||||
|
];
|
||||||
|
$pdo = new PDO($dsn, $database_user, $database_pass, $opt);
|
||||||
|
$stmt = $pdo->query("SELECT `username` FROM `mailbox` WHERE `wants_tagged_subject` = '1'");
|
||||||
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
while ($row = array_shift($rows)) {
|
||||||
|
echo strtolower(trim($row['username'])) . PHP_EOL;
|
||||||
|
}
|
||||||
|
?>
|
@ -10,3 +10,52 @@ rspamd_config.MAILCOW_AUTH = {
|
|||||||
rspamd_config.MAILCOW_MOO = function (task)
|
rspamd_config.MAILCOW_MOO = function (task)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local modify_subject_map = rspamd_config:add_map({
|
||||||
|
url = 'http://nginx:8081/tags.php',
|
||||||
|
type = 'map',
|
||||||
|
description = 'Map of users to use subject tags for'
|
||||||
|
})
|
||||||
|
|
||||||
|
local auth_domain_map = rspamd_config:add_map({
|
||||||
|
url = 'http://nginx:8081/authoritative.php',
|
||||||
|
type = 'map',
|
||||||
|
description = 'Map of domains we are authoritative for'
|
||||||
|
})
|
||||||
|
|
||||||
|
rspamd_config.ADD_DELIMITER_TAG = {
|
||||||
|
callback = function(task)
|
||||||
|
local util = require("rspamd_util")
|
||||||
|
local rspamd_logger = require "rspamd_logger"
|
||||||
|
local user_tagged = task:get_recipients(1)[1]['user']
|
||||||
|
local domain = task:get_recipients(1)[1]['domain']
|
||||||
|
local user, tag = user_tagged:match("([^+]+)+(.*)")
|
||||||
|
local authdomain = auth_domain_map:get_key(domain)
|
||||||
|
|
||||||
|
if tag and authdomain then
|
||||||
|
rspamd_logger.infox("Domain %s is part of mailcow, start reading tag settings", domain)
|
||||||
|
local user_untagged = user .. '@' .. domain
|
||||||
|
rspamd_logger.infox("Querying tag settings for user %1", user_untagged)
|
||||||
|
if modify_subject_map:get_key(user_untagged) then
|
||||||
|
rspamd_logger.infox("User wants subject modified for tagged mail")
|
||||||
|
local sbj = task:get_header('Subject')
|
||||||
|
if tag then
|
||||||
|
rspamd_logger.infox("Found tag %1, will modify subject header", tag)
|
||||||
|
new_sbj = '=?UTF-8?B?' .. tostring(util.encode_base64('[' .. tag .. '] ' .. sbj)) .. '?='
|
||||||
|
task:set_rmilter_reply({
|
||||||
|
remove_headers = {['Subject'] = 1},
|
||||||
|
add_headers = {['Subject'] = new_sbj}
|
||||||
|
})
|
||||||
|
end
|
||||||
|
else
|
||||||
|
rspamd_logger.infox("Add X-Move-Tag header")
|
||||||
|
task:set_rmilter_reply({
|
||||||
|
add_headers = {['X-Moo-Tag'] = 'YES'}
|
||||||
|
})
|
||||||
|
end
|
||||||
|
else
|
||||||
|
rspamd_logger.infox("Skip delimiter handling for untagged message or authenticated user")
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user