aboutsummaryrefslogtreecommitdiffstats
path: root/rules
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-06-29 08:05:54 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-06-29 08:59:21 +0100
commit5f52812464d4209b93c1665c242f2cd2c3576f60 (patch)
treea2243bfa227b7eae077c1d3802da7e4fe7f2f58a /rules
parent9b56954e316bd36bae782701e1de4f023aca8c4c (diff)
downloadrspamd-5f52812464d4209b93c1665c242f2cd2c3576f60.tar.gz
rspamd-5f52812464d4209b93c1665c242f2cd2c3576f60.zip
[Minor] Move emails normalization to the lua library
Diffstat (limited to 'rules')
-rw-r--r--rules/misc.lua34
1 files changed, 3 insertions, 31 deletions
diff --git a/rules/misc.lua b/rules/misc.lua
index 1814be8ab..bc9b044eb 100644
--- a/rules/misc.lua
+++ b/rules/misc.lua
@@ -20,6 +20,7 @@ local E = {}
local fun = require "fun"
local util = require "rspamd_util"
local rspamd_regexp = require "rspamd_regexp"
+local rspamd_lua_utils = require "lua_util"
-- Different text parts
rspamd_config.R_PARTS_DIFFER = {
@@ -409,39 +410,11 @@ local aliases_id = rspamd_config:register_symbol{
type = 'prefilter',
name = 'EMAIL_PLUS_ALIASES',
callback = function(task)
- local function check_address(addr)
- if addr.user then
- local cap, pluses = string.match(addr.user, '^([^%+][^%+]*)(%+.*)$')
- if cap then
- return cap, rspamd_str_split(pluses, '+')
- end
- end
-
- return nil
- end
-
- local function set_addr(addr, new_user)
- addr.user = new_user
-
- if addr.domain then
- addr.addr = string.format('%s@%s', addr.user, addr.domain)
- else
- addr.addr = string.format('%s@', addr.user)
- end
-
- if addr.name and #addr.name > 0 then
- addr.raw = string.format('"%s" <%s>', addr.name, addr.addr)
- else
- addr.raw = string.format('<%s>', addr.addr)
- end
- end
-
local function check_from(type)
if task:has_from(type) then
local addr = task:get_from(type)[1]
- local na,tags = check_address(addr)
+ local na,tags = rspamd_lua_utils.remove_email_aliases(addr)
if na then
- set_addr(addr, na)
task:set_from(type, addr)
task:insert_result('TAGGED_FROM', 1.0, fun.totable(
fun.filter(function(t) return t and #t > 0 end, tags)))
@@ -459,9 +432,8 @@ local aliases_id = rspamd_config:register_symbol{
local addrs = task:get_recipients(type)
for _, addr in ipairs(addrs) do
- local na,tags = check_address(addr)
+ local na,tags = rspamd_lua_utils.remove_email_aliases(addr)
if na then
- set_addr(addr, na)
modified = true
fun.each(function(t) table.insert(all_tags, t) end,
fun.filter(function(t) return t and #t > 0 end, tags))