2016-12-10 03:39:02 +08:00
|
|
|
sign_condition =<<EOD
|
|
|
|
return function(task)
|
2016-12-22 03:55:38 +08:00
|
|
|
local smtp_from = task:get_from('smtp')
|
|
|
|
local mime_from = task:get_from('mime')
|
2016-12-15 17:04:56 +08:00
|
|
|
local rspamd_logger = require "rspamd_logger"
|
2016-12-22 03:55:38 +08:00
|
|
|
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
|
|
|
|
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")
|
2016-12-15 17:04:56 +08:00
|
|
|
return false
|
|
|
|
end
|
2016-12-22 03:55:38 +08:00
|
|
|
local keyfile = io.open("/data/dkim/keys/" .. domain .. ".dkim")
|
|
|
|
if keyfile then
|
|
|
|
rspamd_logger.infox(task, "found dkim key file for domain %s", domain)
|
|
|
|
keyfile:close()
|
|
|
|
return {
|
|
|
|
key = "/data/dkim/keys/" .. domain .. ".dkim",
|
|
|
|
domain = domain,
|
|
|
|
selector = "dkim"
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rspamd_logger.infox(task, "no key file for domain %s - skipped", domain)
|
2016-12-15 17:04:56 +08:00
|
|
|
end
|
|
|
|
return false
|
2016-12-10 03:39:02 +08:00
|
|
|
end
|
|
|
|
EOD;
|