Skip to content

Instantly share code, notes, and snippets.

@smfreegard
Created October 7, 2016 22:27
Show Gist options
  • Save smfreegard/36a1e71ed31de86559fdd1f2be12bd8d to your computer and use it in GitHub Desktop.
Save smfreegard/36a1e71ed31de86559fdd1f2be12bd8d to your computer and use it in GitHub Desktop.
rspamd_config.NO_MX_FOR_RETURN_ADDR = {
callback = function(task)
local return_addr
local hdr_from = task:get_header('From')
local hdr_replyto = task:get_header('Reply-To')
-- Work out the return address
if (hdr_replyto) then
return_addr = hdr_replyto
elseif (hdr_from) then
return_addr = hdr_from
else
return false
end
local logger = require "rspamd_logger"
-- Parse return address
local util = require "rspamd_util"
local parsed_return_addr = util.parse_mail_address(return_addr)
if not (parsed_return_addr and parsed_return_addr[1]) then
logger.infox("Unable to parse return address: %1", return_addr)
return false
end
local return_domain = parsed_return_addr[1]['domain']
local function dns_a_cb(resolver, to_resolve, results, err)
if not results then
if (err == 'requested record is not found') then
-- TODO: check for AAAA record (rspamd has no resolve_aaa function)
task:insert_result('NO_MX_FOR_RETURN_ADDR', 1.0, return_domain)
end
-- TODO: check IP address returned is valid
end
end
local function dns_mx_cb(resolver, to_resolve, results, err)
if not results then
if (err == 'requested record is not found') then
-- Check A record
task:get_resolver():resolve_a(task:get_session(), task:get_mempool(),
return_domain, dns_a_cb)
return
end
-- TODO: resolve MX records to IP addresses
-- and check that at least one is valid.
end
end
task:get_resolver():resolve_mx(task:get_session(), task:get_mempool(),
return_domain, dns_mx_cb)
end,
score = 3.0,
description = 'Return address domain has no valid MX'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment