commit 71246a1: [Feature] Multimap: Allow multiple email addresses matches

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Sep 27 10:07:05 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-09-27 11:05:39 +0100
URL: https://github.com/rspamd/rspamd/commit/71246a1a926cc088de211b5a87a6ed5eacd87270 (HEAD -> master)

[Feature] Multimap: Allow multiple email addresses matches

---
 src/plugins/lua/multimap.lua | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/plugins/lua/multimap.lua b/src/plugins/lua/multimap.lua
index 284a05198..bafa27476 100644
--- a/src/plugins/lua/multimap.lua
+++ b/src/plugins/lua/multimap.lua
@@ -235,27 +235,27 @@ local function apply_addr_filter(task, filter, input, rule)
   if filter == 'email:addr' or filter == 'email' then
     local addr = util.parse_mail_address(input, task:get_mempool())
     if addr and addr[1] then
-      return addr[1]['addr']
+      return fun.totable(fun.map(function(a) return a.addr end, addr))
     end
   elseif filter == 'email:user' then
     local addr = util.parse_mail_address(input, task:get_mempool())
     if addr and addr[1] then
-      return addr[1]['user']
+      return fun.totable(fun.map(function(a) return a.user end, addr))
     end
   elseif filter == 'email:domain' then
     local addr = util.parse_mail_address(input, task:get_mempool())
     if addr and addr[1] then
-      return addr[1]['domain']
+      return fun.totable(fun.map(function(a) return a.domain end, addr))
     end
   elseif filter == 'email:domain:tld' then
     local addr = util.parse_mail_address(input, task:get_mempool())
     if addr and addr[1] then
-      return util.get_tld(addr[1]['domain'])
+      return fun.totable(fun.map(function(a) return util.get_tld(a.domain) end, addr))
     end
   elseif filter == 'email:name' then
     local addr = util.parse_mail_address(input, task:get_mempool())
     if addr and addr[1] then
-      return addr[1]['name']
+      return fun.totable(fun.map(function(a) return a.name end, addr))
     end
   elseif filter == 'ip_addr' then
     local ip_addr = rspamd_ip.from_string(input)
@@ -637,7 +637,11 @@ local function multimap_callback(task, rule)
       end
     end
 
-    match_element(r, value, rule_callback)
+    if type(value) == 'table' then
+      fun.each(function(elt) match_element(r, elt, rule_callback) end, value)
+    else
+      match_element(r, value, rule_callback)
+    end
   end
 
   -- Match list of values according to the field


More information about the Commits mailing list