From 8663bd63f49c04d122a06fbcbf5addbd5bdf155e Mon Sep 17 00:00:00 2001 From: Andrew Lewis Date: Fri, 6 Feb 2015 15:39:45 +0200 Subject: [PATCH] Allow applying settings to authenticated users --- doc/markdown/configuration/settings.md | 2 ++ src/plugins/lua/settings.lua | 33 ++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/doc/markdown/configuration/settings.md b/doc/markdown/configuration/settings.md index 4162e6843..a7b85a11c 100644 --- a/doc/markdown/configuration/settings.md +++ b/doc/markdown/configuration/settings.md @@ -49,6 +49,7 @@ settings { rcpt = "admin"; rcpt = "/user.*/"; ip = "172.16.0.0/16"; + user = "@example.net"; apply "default" { symbol1 = 10.0; symbol2 = 0.0; @@ -74,6 +75,7 @@ So each setting has the following attributes: + `from` - match SMTP from + `rcpt` - match RCPT + `ip` - match source IP address + + `user` - matches authenticated user ID of message sender if any - `apply` - list of applied rules, identified by metric name (e.g. `default`) + `symbol` - modify weight of a symbol + `actions` - section of modified actions diff --git a/src/plugins/lua/settings.lua b/src/plugins/lua/settings.lua index debd62632..5b9311adf 100644 --- a/src/plugins/lua/settings.lua +++ b/src/plugins/lua/settings.lua @@ -70,7 +70,7 @@ local function check_settings(task) return false end - local function check_specific_setting(name, rule, ip, from, rcpt) + local function check_specific_setting(name, rule, ip, from, rcpt, user) local res = false if rule['ip'] and ip then @@ -100,6 +100,15 @@ local function check_settings(task) end end + if not res and rule['user'] and user then + for _, i in ipairs(rule['user']) do + res = check_addr_setting(i, user) + if res then + break + end + end + end + if res then if rule['whitelist'] then return {whitelist = true} @@ -120,11 +129,25 @@ local function check_settings(task) local ip = task:get_from_ip() local from = task:get_from() local rcpt = task:get_recipients() + local uname = task:get_user() + local user = {} + user[1] = {} + if uname then + for localpart, domainpart in string.gmatch(uname, "(.+)@(.+)") do + user[1]["user"] = localpart + user[1]["domain"] = domainpart + user[1]["addr"] = uname + break + end + if not user[1]["addr"] then + user[1]["user"] = uname + end + end -- Match rules according their order for pri = max_pri,1,-1 do if settings[pri] then for name, rule in pairs(settings[pri]) do - local rule = check_specific_setting(name, rule, ip, from, rcpt) + local rule = check_specific_setting(name, rule, ip, from, rcpt, user) if rule then rspamd_logger.info(string.format("<%s> apply settings according to rule %s", task:get_message_id(), name)) @@ -276,6 +299,12 @@ local function process_settings_table(tbl) out['rcpt'] = check_table(elt['rcpt'], rcpt) end end + if elt['user'] then + local user = process_addr(elt['user']) + if user then + out['user'] = check_table(elt['user'], user) + end + end -- Now we must process actions if elt['apply'] then -- 2.39.5