commit bb3d825: [Fix] Emails: Check email sanity before testing on BL

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Jun 24 16:00:04 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-06-24 16:56:42 +0100
URL: https://github.com/rspamd/rspamd/commit/bb3d82561cdc72211da9df94a13d8083d519bc41 (HEAD -> master)

[Fix] Emails: Check email sanity before testing on BL

---
 src/plugins/lua/emails.lua | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/src/plugins/lua/emails.lua b/src/plugins/lua/emails.lua
index 6c23daf79..1be193390 100644
--- a/src/plugins/lua/emails.lua
+++ b/src/plugins/lua/emails.lua
@@ -32,6 +32,8 @@ local lua_maps = require "lua_maps"
 local lua_maps_expressions = require "lua_maps_expressions"
 local N = "emails"
 
+-- TODO: move this into common part
+
 -- Check rule for a single email
 local function check_email_rule(task, rule, addr)
   if rule['whitelist'] then
@@ -172,19 +174,24 @@ local function gen_check_emails(rule)
     local checked = {}
     if emails and not rule.skip_body then
       for _,addr in ipairs(emails) do
-        local to_check = string.format('%s%s%s', addr:get_user(),
-          rule.delimiter, addr:get_host())
-        local naddr = {
-          user = (addr:get_user() or ''):lower(),
-          domain = (addr:get_host() or ''):lower(),
-          addr = to_check:lower()
-        }
-
-        rspamd_lua_utils.remove_email_aliases(naddr)
-
-        if not checked[naddr.addr] then
-          check_email_rule(task, rule, naddr)
-          checked[naddr.addr] = true
+        local user_part = addr:get_user()
+        local domain = addr:get_host()
+
+        if (user_part and #user_part > 0) and (domain and #domain > 0) then
+          local to_check = string.format('%s%s%s', addr:get_user(),
+              rule.delimiter, addr:get_host())
+          local naddr = {
+            user = (addr:get_user() or ''):lower(),
+            domain = (addr:get_host() or ''):lower(),
+            addr = to_check:lower()
+          }
+
+          rspamd_lua_utils.remove_email_aliases(naddr)
+
+          if not checked[naddr.addr] then
+            check_email_rule(task, rule, naddr)
+            checked[naddr.addr] = true
+          end
         end
       end
     end
@@ -198,7 +205,7 @@ local function gen_check_emails(rule)
       if replyto then
         local rt = util.parse_mail_address(replyto, task:get_mempool())
 
-        if rt and rt[1] then
+        if rt and rt[1] and (rt[1].addr and #rt[1].addr > 0) then
           rspamd_lua_utils.remove_email_aliases(rt[1])
           rt[1].addr = rt[1].addr:lower()
           if not checked[rt[1].addr] then


More information about the Commits mailing list