]> source.dussan.org Git - rspamd.git/commitdiff
Allow user@ and @domain matches in multimap.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 22 Jun 2015 15:45:01 +0000 (16:45 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 22 Jun 2015 15:45:01 +0000 (16:45 +0100)
src/plugins/lua/multimap.lua

index d9c9dd09948e562c1aa2ace0688b2346ec726ba2..c9b535e67eaa16f16686d4cc99300a7ad2f7a19d 100644 (file)
@@ -67,17 +67,43 @@ local function check_multimap(task)
     if ret then
       task:insert_result(r['symbol'], 1)
     end
+    
+    return ret
   end
 
   -- Match list of values according to the field
-  local function match_list(r, ls, field)
+  local function match_list(r, ls, fields)
+    local ret = false
     if ls then
-      if field then
-        _.each(function(e) match_rule(r, e[field]) end, ls)
+      if fields then
+        _.each(function(e) 
+          local match = e[fields[1]]
+          if fields[2] then
+            match = fields[2](match)
+          end
+          ret = match_rule(r, match) 
+        end, ls)
       else
-        _.each(function(e) match_rule(r, e) end, ls)
+        _.each(function(e) ret = match_rule(r, e) end, ls)
       end
     end
+
+    return ret
+  end
+  
+  local function match_addr(r, addr)
+    local ret = match_list(r, addr, {'addr'})
+    
+    if not ret then
+      -- Try domain
+      ret = match_list(r, addr, {'domain', function(d) return '@' .. d end})
+    end
+    if not ret then
+      -- Try user
+      ret =  match_list(r, addr, {'user', function(d) return d .. '@' end})
+    end
+    
+    return ret
   end
   -- IP rules
   local ip = task:get_from_ip()
@@ -97,7 +123,7 @@ local function check_multimap(task)
   local rcpts = task:get_recipients()
   if rcpts then
     _.each(function(r)
-      match_list(r, rcpts, 'addr')
+      match_addr(r, rcpts)
     end,
     _.filter(function(r) return r['type'] == 'rcpt' end, rules))
   end
@@ -106,7 +132,7 @@ local function check_multimap(task)
   local from = task:get_from()
   if from then
     _.each(function(r)
-      match_list(r, from, 'addr')
+      match_addr(r, from)
     end,
     _.filter(function(r) return r['type'] == 'from' end, rules))
   end