commit 671c600: [Rework] Convert emails rules to rbl rules

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Sep 2 15:56:06 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-09-02 16:20:40 +0100
URL: https://github.com/rspamd/rspamd/commit/671c60076f1e0b1b9af9ae76f144e7145d16d7e5

[Rework] Convert emails rules to rbl rules

---
 lualib/lua_cfg_transform.lua | 55 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/lualib/lua_cfg_transform.lua b/lualib/lua_cfg_transform.lua
index 32e1a2ee3..e17ce12ca 100644
--- a/lualib/lua_cfg_transform.lua
+++ b/lualib/lua_cfg_transform.lua
@@ -278,6 +278,47 @@ local function surbl_section_convert(cfg, section)
   end
 end
 
+-- Converts surbl module config to rbl module
+local function emails_section_convert(cfg, section)
+  local rbl_section = cfg.rbl.rbls
+  local wl = section.whitelist
+  for name,value in pairs(section.rules or {}) do
+    if not rbl_section[name] then
+      local converted = {
+        emails = true,
+        ignore_defaults = true,
+      }
+
+      if wl then
+        converted.whitelist = wl
+      end
+
+      for k,v in pairs(value) do
+        -- Rename
+        if k == 'dnsbl' then k = 'rbl' end
+        if k == 'check_replyto' then k = 'replyto' end
+        if k == 'hashlen' then k = 'hash_len' end
+        if k == 'encoding' then k = 'hash_format' end
+        if k == 'domain_only' then k = 'emails_domainonly' end
+        if k == 'delimiter' then k = 'emails_delimiter' end
+        if k == 'skip_body' then
+          if v then
+            -- Hack
+            converted.emails = false
+            converted.replyto = true
+          end
+        end
+
+        converted[k] = lua_util.deepcopy(v)
+      end
+      rbl_section[name] = converted
+    else
+      logger.warnx(rspamd_config, 'conflicting names in emails and rbl rules: %s, ignore emails rule',
+          name)
+    end
+  end
+end
+
 return function(cfg)
   local ret = false
 
@@ -461,5 +502,19 @@ return function(cfg)
     cfg.surbl = {}
   end
 
+  if cfg.emails then
+    if not cfg.rbl then
+      cfg.rbl = {
+        rbls = {}
+      }
+    end
+    if not cfg.rbl.rbls then
+      cfg.rbl.rbls = {}
+    end
+    emails_section_convert(cfg, cfg.emails)
+    logger.infox(rspamd_config, 'converted emails rules to rbl rules')
+    cfg.emails = {}
+  end
+
   return ret, cfg
 end


More information about the Commits mailing list