return fn
end
+local function apply_regexp_filter(task, filter, fn, r)
+ if 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 apply_content_filter(task, filter, r)
if filter == 'body' then
return {task:get_rawbody()}
header = apply_addr_filter,
url = apply_url_filter,
filename = apply_filename_filter,
+ mempool = apply_regex_filter,
--content = apply_content_filter, -- Content filters are special :(
}
if country then
match_rule(rule, country)
end
+ elseif rt == 'mempool' then
+ local var = task:get_mempool():get_variable(rule['variable'])
+ if var then
+ match_rule(rule, var)
+ end
end
end
newrule['description'] = string.format('multimap, type %s: %s', newrule['type'],
newrule['symbol'])
end
+ if newrule['type'] == 'mempool' and not newrule['variable'] then
+ rspamd_logger.errx(rspamd_config, 'mempool map requires variable')
+ return nil
+ end
-- Check cdb flag
if string.find(newrule['map'], '^cdb://.*$') then
local test = cdb.create(newrule['map'])
or newrule['type'] == 'content'
or newrule['type'] == 'hostname'
or newrule['type'] == 'asn'
- or newrule['type'] == 'country' then
+ or newrule['type'] == 'country'
+ or newrule['type'] == 'mempool' then
if newrule['regexp'] then
newrule['hash'] = rspamd_config:add_map ({
url = newrule['map'],
${result} = Scan Message With Rspamc ${MESSAGE} -i 8.8.8.8
Check Rspamc ${result} REDIS_COUNTRY
-MAP - REDIS - ASN - MISS
+MAP - REDIS - CC - MISS
${result} = Scan Message With Rspamc ${MESSAGE} -i 46.228.47.114
Check Rspamc ${result} REDIS_COUNTRY inverse=1
+MAP - REDIS - ASN FILTERED - HIT
+ Redis HSET asn 1 ${EMPTY}
+ ${result} = Scan Message With Rspamc ${MESSAGE} -i 8.8.8.8
+ Check Rspamc ${result} REDIS_ASN_FILTERED
+
+MAP - REDIS - ASN FILTERED - MISS
+ ${result} = Scan Message With Rspamc ${MESSAGE} -i 46.228.47.114
+ Check Rspamc ${result} REDIS_ASN_FILTERED inverse=1
+
*** Keywords ***
Multimap Setup
${PLUGIN_CONFIG} = Get File ${TESTDIR}/configs/multimap.conf