Hi Andrew
first of all: thanks a lot :-)
Based on your snippet I wrote a rule that mimics spamassassin
trusted_networks setting.
I changed your code so FRIENDLY_HN and FRIENDLY_IP are "exploded" into a
tables. This allows multiple values to be provided as trusted hosts
local FRIENDLY_HN = 'mx01.domain.tld mx02.domain.tld mx.other-domain.tld'
local FRIENDLY_IP = '203.0.113.1 203.0.113.2 203.0.113.3'
local FRIENDLY_HOST = {}
local FRIENDLY_ADDRS = {}
local delimiter = ' '
for match in (FRIENDLY_IP..delimiter):gmatch("(.-)"..delimiter) do
table.insert(FRIENDLY_ADDRS, match)
end
for match in (FRIENDLY_HN..delimiter):gmatch("(.-)"..delimiter) do
table.insert(FRIENDLY_HOST, match)
end
local function has_value (tab, val)
for index, value in ipairs(tab) do
if value == val then
return true
end
end
return false
end
rspamd_config.LOCAL_IP_OVERRIDE = {
callback = function(task)
local ip = task:get_from_ip()
if ip then
if ip:is_valid() and has_value(FRIENDLY_ADDRS, ip:to_string()) == false then
return false
end
end
for _, r in ipairs(task:get_received_headers()) do
if has_value(FRIENDLY_HOST, r['by_hostname']) and has_value(FRIENDLY_HOST, r['from_hostname']) == false then
if r['real_ip'] and r['real_ip']:is_valid() then
task:set_from_ip(r['from_ip'])
return true, r['from_ip']
end
end
end
end,
type = 'prefilter',
priority = 11,
score = 0.1,
}
First tests show it works as it's intended. IPs of my MX are replaced by
the ip of the server handing of to my MX. So the correct ip is queried
agains rbl
Again thanks a lot for your help
Cheers
tobi