aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/lua/emails.lua
diff options
context:
space:
mode:
authorAndrew Lewis <nerf@judo.za.org>2017-06-29 17:19:40 +0200
committerAndrew Lewis <nerf@judo.za.org>2017-06-29 17:19:40 +0200
commit2ae9274ed3e519f1a9c762314b52fd1ee0df57d4 (patch)
tree5cb9f735cf3605b4128334d4943c340fbc257f57 /src/plugins/lua/emails.lua
parentad3cb615e8ff7e46e24a43fdb27b7fb743adf9c6 (diff)
downloadrspamd-2ae9274ed3e519f1a9c762314b52fd1ee0df57d4.tar.gz
rspamd-2ae9274ed3e519f1a9c762314b52fd1ee0df57d4.zip
[Minor] Fix emails plugin
Diffstat (limited to 'src/plugins/lua/emails.lua')
-rw-r--r--src/plugins/lua/emails.lua52
1 files changed, 23 insertions, 29 deletions
diff --git a/src/plugins/lua/emails.lua b/src/plugins/lua/emails.lua
index 3c3d103fd..9199bc6f3 100644
--- a/src/plugins/lua/emails.lua
+++ b/src/plugins/lua/emails.lua
@@ -27,6 +27,7 @@ local rules = {}
local logger = require "rspamd_logger"
local hash = require "rspamd_cryptobox_hash"
local rspamd_lua_utils = require "lua_util"
+local util = require "rspamd_util"
local N = "emails"
-- Check rule for a single email
@@ -101,36 +102,34 @@ local function check_email_rule(task, rule, addr)
end
-- Check email
-local function check_emails(task)
- local emails = task:get_emails()
- local checked = {}
- if emails and not rule.skip_body then
- for _,addr in ipairs(emails) do
- local to_check = string.format('%s@%s', addr:get_user(), addr:get_host())
- local naddr = {
- user = addr:get_user(),
- domain = addr:get_host(),
- addr = to_check
- }
-
- rspamd_lua_utils.remove_email_aliases(naddr)
-
- if not checked[naddr.addr] then
- for _,rule in ipairs(rules) do
+local function gen_check_emails(rule)
+ return function(task)
+ local emails = task:get_emails()
+ local checked = {}
+ if emails and not rule.skip_body then
+ for _,addr in ipairs(emails) do
+ local to_check = string.format('%s@%s', addr:get_user(), addr:get_host())
+ local naddr = {
+ user = addr:get_user(),
+ domain = addr:get_host(),
+ addr = to_check
+ }
+
+ rspamd_lua_utils.remove_email_aliases(naddr)
+
+ if not checked[naddr.addr] then
check_email_rule(task, rule, naddr)
+ checked[naddr.addr] = true
end
- checked[naddr.addr] = true
end
end
- end
- for _,rule in ipairs(rules) do
if rule.check_replyto then
- local function get_raw_header(task, name)
- return ((task:get_header_full(name) or {})[1] or {})['raw']
+ local function get_raw_header(name)
+ return ((task:get_header_full(name) or {})[1] or {})['value']
end
- local replyto = get_raw_header(task, 'Reply-To')
+ local replyto = get_raw_header('Reply-To')
if not replyto then return false end
local rt = util.parse_mail_address(replyto)
@@ -176,16 +175,11 @@ if opts and type(opts) == 'table' then
end
if #rules > 0 then
- -- add fake symbol to check all maps inside a single callback
- local id = rspamd_config:register_symbol({
- type = 'callback',
- callback = check_emails
- })
for _,rule in ipairs(rules) do
+ local cb = gen_check_emails(rule)
rspamd_config:register_symbol({
name = rule['symbol'],
- type = 'virtual',
- parent = id
+ callback = cb,
})
end
end