diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2022-05-14 14:38:37 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2022-05-14 14:38:37 +0100 |
commit | 20817548d32bd7280001f9a0f80a087ea7175ab1 (patch) | |
tree | 99729e129682b9da390c681f8e8dc59cd5fb5c42 | |
parent | ae9aabdc6573336f36086513fccc055b6536ea46 (diff) | |
download | rspamd-20817548d32bd7280001f9a0f80a087ea7175ab1.tar.gz rspamd-20817548d32bd7280001f9a0f80a087ea7175ab1.zip |
[Rework] Multimap: Avoid prefilters usage where augmentations can be used
-rw-r--r-- | src/plugins/lua/multimap.lua | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/src/plugins/lua/multimap.lua b/src/plugins/lua/multimap.lua index 2706443d3..edc54443d 100644 --- a/src/plugins/lua/multimap.lua +++ b/src/plugins/lua/multimap.lua @@ -427,8 +427,6 @@ local function multimap_query_redis(key, task, value, callback) end local function multimap_callback(task, rule) - local pre_filter = rule['prefilter'] - local function match_element(r, value, callback) if not value then return false @@ -591,7 +589,7 @@ local function multimap_callback(task, rule) task:insert_result(forced, symbol, score) end - if pre_filter then + if rule.action then local message = rule.message if rule.message_func then message = rule.message_func(task, rule.symbol, opt) @@ -798,7 +796,7 @@ local function multimap_callback(task, rule) rspamd_logger.errx(task, 'error looking up %s: %s', to_resolve, results) elseif results then task:insert_result(rule['symbol'], 1, rule['map']) - if pre_filter then + if rule.action then task:set_pre_result(rule['action'], 'Matched map: ' .. rule['symbol'], N) end @@ -1188,17 +1186,11 @@ local function add_multimap_rule(key, newrule) end end - if newrule['action'] then - newrule['prefilter'] = true - else - newrule['prefilter'] = false - end - if ret then if newrule['type'] == 'symbol_options' then rspamd_config:register_dependency(newrule['symbol'], newrule['target_symbol']) end - if newrule['require_symbols'] and not newrule['prefilter'] then + if newrule['require_symbols'] then local atoms = {} local function parse_atom(str) @@ -1259,11 +1251,19 @@ if opts and type(opts) == 'table' then end -- add fake symbol to check all maps inside a single callback fun.each(function(rule) + local augmentations = {} + + if rule.action then + table.insert(augmentations, 'passthrough') + end + local id = rspamd_config:register_symbol({ type = 'normal', name = rule['symbol'], + augmentations = augmentations, callback = gen_multimap_callback(rule), }) + if rule['symbols'] then -- Find allowed symbols by this map rule['symbols_set'] = {} @@ -1303,17 +1303,7 @@ if opts and type(opts) == 'table' then rspamd_config:set_metric_symbol(rule) rule.flags = tmp_flags end - end, fun.filter(function(r) return not r['prefilter'] end, rules)) - - -- prefilter symbols - fun.each(function(rule) - rspamd_config:register_symbol({ - type = 'prefilter', - name = rule['symbol'], - score = tonumber(rule.score or "0") or 0, - callback = gen_multimap_callback(rule), - }) - end, fun.filter(function(r) return r['prefilter'] end, rules)) + end, rules) if #rules == 0 then lua_util.disable_module(N, "config") |