DKIM sign auto-responder messages by using mime from field

master
andryyy 2016-12-21 20:55:38 +01:00
parent 5a3bfa1e59
commit 2783510bef
1 changed files with 25 additions and 18 deletions

View File

@ -1,17 +1,25 @@
sign_condition =<<EOD sign_condition =<<EOD
return function(task) return function(task)
local from = task:get_from('smtp') local smtp_from = task:get_from('smtp')
local mime_from = task:get_from('mime')
local rspamd_logger = require "rspamd_logger" local rspamd_logger = require "rspamd_logger"
if smtp_from[1]['domain'] ~= nil and smtp_from[1]['domain'] ~= '' then
domain = smtp_from[1]['domain']
rspamd_logger.infox(task, "set domain found in smtp from field to %s", domain)
if not task:get_user() then if not task:get_user() then
rspamd_logger.infox(task, "Skip DKIM signing for unauthorized user") rspamd_logger.infox(task, "found domain in smtp header field, but user is not authenticated - skipped")
return false
end
elseif mime_from[1]['domain'] ~= nil and mime_from[1]['domain'] ~= '' then
domain = mime_from[1]['domain']
rspamd_logger.infox(task, "set domain found in mime from field to %s", domain)
else
rspamd_logger.infox(task, "cannot determine domain for dkim signing")
return false return false
end end
if from and from[1]['addr'] then
lastAtSymbol = from[1]['addr']:find("[^%@]+$")
local domain = from[1]['addr']:sub(lastAtSymbol, #from[1]['addr'])
local keyfile = io.open("/data/dkim/keys/" .. domain .. ".dkim") local keyfile = io.open("/data/dkim/keys/" .. domain .. ".dkim")
if keyfile then if keyfile then
rspamd_logger.infox(task, "DKIM signing mail for authorized user of domain %s", domain) rspamd_logger.infox(task, "found dkim key file for domain %s", domain)
keyfile:close() keyfile:close()
return { return {
key = "/data/dkim/keys/" .. domain .. ".dkim", key = "/data/dkim/keys/" .. domain .. ".dkim",
@ -19,8 +27,7 @@ return function(task)
selector = "dkim" selector = "dkim"
} }
else else
rspamd_logger.infox(task, "Authorized user, but no key file for domain %s - skipped DKIM signing", domain) rspamd_logger.infox(task, "no key file for domain %s - skipped", domain)
end
end end
return false return false
end end