aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/lua/multimap.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-03-17 12:45:39 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-03-17 12:45:39 +0000
commit2619184fb0b188be5e088c0e95fa84c4069c097d (patch)
treea1a0c1dfa7cca9a47405d9fef0963e29b5aa356d /src/plugins/lua/multimap.lua
parentc2f53048d6236c85fd76b08eb2ff484a0a7e2ec3 (diff)
downloadrspamd-2619184fb0b188be5e088c0e95fa84c4069c097d.tar.gz
rspamd-2619184fb0b188be5e088c0e95fa84c4069c097d.zip
[Feature] Add filename multimap type
Diffstat (limited to 'src/plugins/lua/multimap.lua')
-rw-r--r--src/plugins/lua/multimap.lua62
1 files changed, 61 insertions, 1 deletions
diff --git a/src/plugins/lua/multimap.lua b/src/plugins/lua/multimap.lua
index a8d807656..d89b90aab 100644
--- a/src/plugins/lua/multimap.lua
+++ b/src/plugins/lua/multimap.lua
@@ -243,6 +243,53 @@ local function multimap_callback(task, pre_filter)
end
end
+ local function apply_filename_filter(filter, fn, r)
+ if filter == 'extension' or filter == 'ext' then
+ return string.match(fn, '%.([^.]+)$')
+ elseif string.find(filter, 'regexp:') then
+ if not r['re_filter'] then
+ local type,pat = string.match(filter, '(regexp:)(.+)')
+ if type and pat then
+ r['re_filter'] = regexp.create(pat)
+ end
+ end
+
+ if not r['re_filter'] then
+ rspamd_logger.errx(task, 'bad search filter: %s', filter)
+ else
+ local results = r['re_filter']:search(fn)
+ if results then
+ return results[1]
+ else
+ return nil
+ end
+ end
+ end
+
+ return fn
+ end
+
+ local function match_filename(r, fn)
+ local value
+ local ret = false
+
+ if r['filter'] then
+ value = apply_filename_filter(r['filter'], fn, r)
+ else
+ value = fn
+ end
+
+ ret = match_element(r, value)
+
+ if ret then
+ task:insert_result(r['symbol'], 1)
+
+ if pre_filter then
+ task:set_pre_result(r['action'], 'Matched map: ' .. r['symbol'])
+ end
+ end
+ end
+
-- IP rules
local ip = task:get_from_ip()
if ip:is_valid() then
@@ -296,7 +343,19 @@ local function multimap_callback(task, pre_filter)
end, rules))
end
end
-
+ -- Filename rules
+ local parts = task:get_parts()
+ for i,p in ipairs(parts) do
+ local fn = p:get_filename()
+ if fn then
+ _.each(function(r)
+ match_filename(r, fn)
+ end,
+ _.filter(function(r)
+ return pre_filter == r['prefilter'] and r['type'] == 'filename'
+ end, rules))
+ end
+ end
-- RBL rules
if ip:is_valid() then
_.each(function(r)
@@ -367,6 +426,7 @@ local function add_multimap_rule(key, newrule)
elseif newrule['type'] == 'header'
or newrule['type'] == 'rcpt'
or newrule['type'] == 'from'
+ or newrule['type'] == 'filename'
or newrule['type'] == 'url' then
if newrule['regexp'] then
newrule['hash'] = rspamd_config:add_map ({