]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Deal with lists of maps in whitelist module 1516/head
authorAndrew Lewis <nerf@judo.za.org>
Mon, 13 Mar 2017 10:14:25 +0000 (12:14 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Mon, 13 Mar 2017 10:14:25 +0000 (12:14 +0200)
src/plugins/lua/whitelist.lua

index 710b22effa5df67057a3bfd5110c7873181fbcb2..f8c5b1b9b72d9159c91665d4499b9b56ebd71eb4 100644 (file)
@@ -45,6 +45,17 @@ local function whitelist_cb(symbol, rule, task)
         table.insert(domains, dom)
         return true,mult
       end
+    elseif rule['maps'] then
+      for map, mult in pairs(rule['maps']) do
+        local val = map:get_key(dom)
+        if val then
+          if #val > 0 then
+            mult = tonumber(val)
+          end
+          table.insert(domains, dom)
+          return true,mult
+        end
+      end
     else
       mult = rule['domains'][dom]
       if mult then
@@ -190,16 +201,26 @@ local configure_whitelist_module = function()
         elseif type(rule['domains']) == 'table' then
           -- Transform ['domain1', 'domain2' ...] to indexes:
           -- {'domain1' = 1, 'domain2' = 1 ...]
-          rule['domains'] = fun.tomap(fun.map(function(d)
-            local name = d
+          rule['maps'] = fun.tomap(fun.map(function(d)
+            local name
             local value = 1
 
             if type(d) == 'table' then
-              name = d[1]
+              name = rspamd_config:add_map({
+                url = d[1],
+                type = 'map',
+              })
               value = tonumber(d[2])
+            else
+              name = rspamd_config:add_map({
+                url = d,
+                type = 'map',
+              })
             end
 
-            return name,value
+            if name and value then
+              return name,value
+            end
           end, rule['domains']))
         else
           rspamd_logger.errx(rspamd_config, 'whitelist %s has bad "domains" value',