]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Allow optional multiplier for whitelists.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 16 Sep 2015 16:55:49 +0000 (17:55 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 16 Sep 2015 16:55:49 +0000 (17:55 +0100)
doc/markdown/modules/whitelist.md
src/plugins/lua/whitelist.lua

index 2ca776748dd4428aa80c02eb9543856112aeefdf..403f103c3ce7b0d48808135d751642fad693799b 100644 (file)
@@ -31,6 +31,16 @@ You can also set the default metric settings using the ordinary attributes, such
 - `one_shot`: default one shot mode
 - `description`: default description
 
+Within lists, you can also use optional `multiplier` argument that defines additional
+multiplier for the score added by this module. For example, let's define twice bigger
+score for `github.com`:
+
+    ["github.com", 2.0]
+
+or if using map:
+
+    github.com 2.0
+
 ## Configuration example
 
 ~~~nginx
@@ -56,9 +66,9 @@ whitelist {
             valid_spf = true;
             valid_dkim = true;
             domains = [
-                "github.com",
+                ["github.com", 2.0],
             ]
-            score = -7.0
+            score = -3.0
         }
         
         WHITELIST_DMARC_DKIM = {
index f28e800187088d7209fc56d07e962ff42a8bf163..74be5dbfe9e5bbc23b4837956ddf5e189dc0f274 100644 (file)
@@ -41,13 +41,20 @@ local function whitelist_cb(symbol, rule, task)
   if from and from[1] and from[1]['domain'] then
     local domain = from[1]['domain']
     local found = false
+    local mult = 1.0
 
     if rule['map'] then
-      if rule['map']:get_key(domain) then
+      local val = rule['map']:get_key(domain)
+      if val then
         found = true
+
+        if #val > 0 then
+          mult = tonumber(val)
+        end
       end
     else
-      if rule['domains'][domain] then
+      mult = rule['domains'][domain]
+      if mult then
         found = true
       end
     end
@@ -78,7 +85,7 @@ local function whitelist_cb(symbol, rule, task)
     end
 
     if found then
-      task:insert_result(symbol, 1.0, domain)
+      task:insert_result(symbol, mult, domain)
     end
   end
 
@@ -114,11 +121,21 @@ local configure_whitelist_module = function()
     each(function(symbol, rule)
       if rule['domains'] then
         if type(rule['domains']) == 'string' then
-          rule['map'] = rspamd_config:add_hash_map(rule['domains'])
+          rule['map'] = rspamd_config:add_kv_map(rule['domains'])
         elseif type(rule['domains']) == 'table' then
           -- Transform ['domain1', 'domain2' ...] to indexes:
           -- {'domain1' = 1, 'domain2' = 1 ...]
-          rule['domains'] = tomap(zip(rule['domains'], ones()))
+          rule['domains'] = tomap(map(function(d)
+            local name = d
+            local value = 1
+
+            if type(d) == 'table' then
+              name = d[1]
+              value = tonumber(d[2])
+            end
+
+            return name,value
+          end, rule['domains']))
         else
           rspamd_logger.errx(rspamd_config, 'whitelist %s has bad "domains" value',
             symbol)