]> source.dussan.org Git - rspamd.git/commitdiff
Allow applying settings to authenticated users
authorAndrew Lewis <nerf@judo.za.org>
Fri, 6 Feb 2015 13:39:45 +0000 (15:39 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Fri, 6 Feb 2015 13:39:45 +0000 (15:39 +0200)
doc/markdown/configuration/settings.md
src/plugins/lua/settings.lua

index 4162e6843b670a6dda83dfb2302379628250a751..a7b85a11cedcbb2ce5f55623ccc63507ee8fcc50 100644 (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
index debd62632284195de84e41d94ad41299de92c15a..5b9311adfcac85627d18469c223045e6ba7e6c68 100644 (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