]> source.dussan.org Git - rspamd.git/commitdiff
[Enhancement] Implement Message-ID RHS checks against DNSBLs
authortwesterhever <40121680+twesterhever@users.noreply.github.com>
Sun, 24 Mar 2024 16:29:22 +0000 (16:29 +0000)
committertwesterhever <40121680+twesterhever@users.noreply.github.com>
Sun, 28 Apr 2024 08:28:38 +0000 (08:28 +0000)
lualib/plugins/rbl.lua
src/plugins/lua/rbl.lua

index af5d6bd91f4e40f97d7c96bd395513cc43dc7233..9dacbaa42025ec18b72733afbc4e0ddbc454aefb 100644 (file)
@@ -33,6 +33,7 @@ local check_types = {
   numeric_urls = {},
   emails = {},
   replyto = {},
+  mid = {},
   dkim = {},
   rdns = {
     connfilter = true,
@@ -118,6 +119,7 @@ local rule_schema_tbl = {
   received_min_pos = ts.number:is_optional(),
   received_nflags = ts.array_of(ts.string):is_optional(),
   replyto = ts.boolean:is_optional(),
+  mid = ts.boolean:is_optional(),
   requests_limit = (ts.integer + ts.string / tonumber):is_optional(),
   require_symbols = (
       ts.array_of(ts.string) + (ts.string / function(s)
index b2ccf86999cd73cb56831aa706a13cad35a33b10..065a58fda0c4f7de8f471d60b524ab3ca04e2a02 100644 (file)
@@ -829,6 +829,24 @@ local function gen_rbl_callback(rule)
     return true
   end
 
+  local function check_mid(task, requests_table, whitelist)
+    local function get_raw_header(name)
+      return ((task:get_header_full(name) or {})[1] or {})['value']
+    end
+
+    local mid = get_raw_header('Message-ID')
+    if mid then
+      local md = rspamd_util.parse_mail_address(mid, task:get_mempool())
+      lua_util.debugm(N, task, 'check message-id %s', md[1])
+
+      if md and md[1] and (md[1].addr and #md[1].addr > 0) then
+        check_email_table(task, md[1], requests_table, whitelist, 'mid')
+      end
+    end
+
+    return true
+  end
+
   -- Create function pipeline depending on rbl settings
   local pipeline = {
     is_alive, -- check monitored status
@@ -866,6 +884,10 @@ local function gen_rbl_callback(rule)
     pipeline[#pipeline + 1] = check_replyto
     description[#description + 1] = 'replyto'
   end
+  if rule.mid then
+    pipeline[#pipeline + 1] = check_mid
+    description[#description + 1] = 'mid'
+  end
 
   if rule.urls or rule.content_urls or rule.images or rule.numeric_urls then
     pipeline[#pipeline + 1] = check_urls
@@ -1028,7 +1050,7 @@ local function add_rbl(key, rbl, global_opts)
   end
 
   -- Check if rbl is available for empty tasks
-  if not (rbl.emails or rbl.urls or rbl.dkim or rbl.received or rbl.selector or rbl.replyto) or
+  if not (rbl.emails or rbl.urls or rbl.dkim or rbl.received or rbl.selector or rbl.replyto or rbl.mid) or
       rbl.is_empty then
     flags_tbl[#flags_tbl + 1] = 'empty'
   end
@@ -1118,7 +1140,7 @@ local function add_rbl(key, rbl, global_opts)
   end
 
   if not rbl.whitelist and not rbl.ignore_url_whitelist and (global_opts.url_whitelist or rbl.url_whitelist) and
-      (rbl.urls or rbl.emails or rbl.dkim or rbl.replyto) and
+      (rbl.urls or rbl.emails or rbl.dkim or rbl.replyto or rbl.mid) and
       not (rbl.from or rbl.received) then
     local def_type = 'set'
     rbl.whitelist = lua_maps.map_add_from_ucl(rbl.url_whitelist or global_opts.url_whitelist, def_type,