diff options
author | Andrew Lewis <nerf@judo.za.org> | 2015-02-06 15:39:45 +0200 |
---|---|---|
committer | Andrew Lewis <nerf@judo.za.org> | 2015-02-06 15:39:45 +0200 |
commit | 8663bd63f49c04d122a06fbcbf5addbd5bdf155e (patch) | |
tree | 686d1eecc9ba562702680bb9ae94d81a45cba993 /src/plugins | |
parent | 1e08514471896e3b3069cdc25f457036d257cc68 (diff) | |
download | rspamd-8663bd63f49c04d122a06fbcbf5addbd5bdf155e.tar.gz rspamd-8663bd63f49c04d122a06fbcbf5addbd5bdf155e.zip |
Allow applying settings to authenticated users
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/lua/settings.lua | 33 |
1 files changed, 31 insertions, 2 deletions
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 |