local util = require "rspamd_util"
local regexp = require "rspamd_regexp"
local rspamd_expression = require "rspamd_expression"
+local rspamd_ip = require "rspamd_ip"
local redis_params
local fun = require "fun"
local N = 'multimap'
country = {
get_value = function(val) return val end,
},
+ received = {
+ get_value = function(val) return val end,
+ },
mempool = {
get_value = function(val) return val end,
},
match_rule(r, fn)
end
+ local function match_received_header(r, pos, total, h)
+ local filter = r['filter'] or 'real_ip'
+ local v = h[filter]
+ if v then
+ local min_pos = tonumber(r['min_pos'])
+ local max_pos = tonumber(r['max_pos'])
+ if min_pos then
+ if min_pos < 0 then
+ if (pos - (min_pos*-1)) < pos then
+ return
+ end
+ else
+ if pos < min_pos then
+ return
+ end
+ end
+ end
+ if max_pos then
+ if max_pos < 0 then
+ if (pos - (max_pos*-1)) > pos then
+ return
+ end
+ else
+ if pos > max_pos then
+ return
+ end
+ end
+ end
+ if filter == 'real_ip' or filter == 'from_ip' then
+ v = rspamd_ip.from_string(v)
+ if v and v:is_valid() then
+ match_rule(r, v)
+ end
+ else
+ match_rule(r, v)
+ end
+ end
+ end
+
local function match_content(r)
local data
match_rule(rule, var)
end
end,
+ received = function()
+ local hdrs = task:get_received_headers()
+ if hdrs and hdrs[1] then
+ local num_hdrs = #hdrs
+ for pos, h in ipairs(hdrs) do
+ match_received_header(rule, pos, num_hdrs, h)
+ end
+ end
+ end,
}
process_rule_funcs.ip = process_rule_funcs.dnsbl
local f = process_rule_funcs[rt]
rspamd_logger.warnx(rspamd_config, 'Cannot add rule: map doesn\'t exists: %1',
newrule['map'])
end
+ elseif newrule['type'] == 'received' then
+ local filter = newrule['filter'] or 'real_ip'
+ if filter == 'real_ip' or filter == 'from_ip' then
+ newrule['radix'] = rspamd_config:add_map ({
+ url = newrule['map'],
+ description = newrule['description'],
+ type = 'radix'
+ })
+ if newrule['radix'] then
+ ret = true
+ end
+ else
+ if newrule['regexp'] then
+ newrule['hash'] = rspamd_config:add_map ({
+ url = newrule['map'],
+ description = newrule['description'],
+ type = 'regexp'
+ })
+ else
+ newrule['hash'] = rspamd_config:add_map ({
+ url = newrule['map'],
+ description = newrule['description'],
+ type = 'hash'
+ })
+ end
+ if newrule['hash'] then
+ ret = true
+ if type(newrule['map']) == 'string' then
+ urls[newrule['map']] = {
+ type = newrule['type'],
+ map = newrule['hash'],
+ regexp = newrule['regexp']
+ }
+ end
+ else
+ rspamd_logger.warnx(rspamd_config, 'Cannot add rule: map doesn\'t exists: %1',
+ newrule['map'])
+ end
+ end
elseif newrule['type'] == 'header'
or newrule['type'] == 'rcpt'
or newrule['type'] == 'from'