aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-09-16 17:55:49 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-09-16 17:55:49 +0100
commit21d8c9a4f21c81476970c3bef2b64fef2ba68e48 (patch)
tree144ef8ab6449e9a269b14024bbf3d5a7615b51c9 /src
parentaeb3226c5324cc289f8dd3151576f38e9bb301bf (diff)
downloadrspamd-21d8c9a4f21c81476970c3bef2b64fef2ba68e48.tar.gz
rspamd-21d8c9a4f21c81476970c3bef2b64fef2ba68e48.zip
Allow optional multiplier for whitelists.
Diffstat (limited to 'src')
-rw-r--r--src/plugins/lua/whitelist.lua27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/plugins/lua/whitelist.lua b/src/plugins/lua/whitelist.lua
index f28e80018..74be5dbfe 100644
--- a/src/plugins/lua/whitelist.lua
+++ b/src/plugins/lua/whitelist.lua
@@ -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)