aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/lua_util.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-06-29 19:13:49 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-06-29 19:13:49 +0100
commit0e2d605055462751b63b26b5f3809fcc3a020b10 (patch)
tree6b946fc126676a09ca6b4cc98f4382637c41256f /lualib/lua_util.lua
parent3019adc5713d89bc4f953cd9af0afc48a484f322 (diff)
downloadrspamd-0e2d605055462751b63b26b5f3809fcc3a020b10.tar.gz
rspamd-0e2d605055462751b63b26b5f3809fcc3a020b10.zip
[Feature] Add per-domain emails normalisation rules
Diffstat (limited to 'lualib/lua_util.lua')
-rw-r--r--lualib/lua_util.lua67
1 files changed, 60 insertions, 7 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua
index bdb0045d5..457c2f7b2 100644
--- a/lualib/lua_util.lua
+++ b/lualib/lua_util.lua
@@ -41,19 +41,37 @@ exports.template = function(tmpl, keys)
end
exports.remove_email_aliases = function(addr)
+ local function check_gmail_user(addr)
+ -- Remove all points
+ local no_dots_user = string.gsub(addr.user, '.', '')
+ local cap, pluses = string.match(no_dots_user, '^([^%+][^%+]*)(%+.*)$')
+ if cap then
+ return cap, rspamd_str_split(pluses, '+'), nil
+ elseif no_dots_user ~= addr.user then
+ return no_dots_user
+ end
+
+ return nil
+ end
+
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, '+')
+ return cap, rspamd_str_split(pluses, '+'), nil
end
end
return nil
end
- local function set_addr(addr, new_user)
- addr.user = new_user
+ local function set_addr(addr, new_user, new_domain)
+ if new_user then
+ addr.user = new_user
+ end
+ if new_domain then
+ addr.domain = new_domain
+ end
if addr.domain then
addr.addr = string.format('%s@%s', addr.user, addr.domain)
@@ -68,12 +86,47 @@ exports.remove_email_aliases = function(addr)
end
end
- if addr then
- local nu, tags = check_address(addr)
+ local function check_gmail(addr)
+ local nu, tags, nd = check_gmail_user(addr)
+
+ if nu then
+ return nu, tags, nd
+ end
+
+ return nil
+ end
+
+ local function check_gmail(addr)
+ local nd = 'gmail.com'
+ local nu, tags = check_gmail_user(addr)
+
if nu then
- set_addr(addr, nu)
+ return nu, tags, nd
+ end
+
+ return nil, nil, nd
+ end
+
+ local specific_domains = {
+ ['gmail.com'] = check_gmail,
+ ['googlemail.com'] = check_googlemail,
+ }
- return nu, tags
+ if addr then
+ if addr.domain and specific_domains[addr.domain] then
+ local nu, tags, nd = specific_domains[addr.domain](addr)
+ if nu or nd then
+ set_addr(addr, nu, nd)
+
+ return nu, tags
+ end
+ else
+ local nu, tags, nd = check_address(addr)
+ if nu or nd then
+ set_addr(addr, nu, nd)
+
+ return nu, tags
+ end
end
return nil