Browse Source

Allow applying settings to authenticated users

tags/0.9.0
Andrew Lewis 9 years ago
parent
commit
8663bd63f4
2 changed files with 33 additions and 2 deletions
  1. 2
    0
      doc/markdown/configuration/settings.md
  2. 31
    2
      src/plugins/lua/settings.lua

+ 2
- 0
doc/markdown/configuration/settings.md View File

@@ -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

+ 31
- 2
src/plugins/lua/settings.lua View File

@@ -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

Loading…
Cancel
Save