]> source.dussan.org Git - rspamd.git/commitdiff
[Rules] Blank spam detection 4644/head
authorAndrew Lewis <nerf@judo.za.org>
Fri, 13 Oct 2023 15:01:50 +0000 (17:01 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Fri, 13 Oct 2023 15:01:50 +0000 (17:01 +0200)
conf/composites.conf
rules/headers_checks.lua
rules/misc.lua
rules/parts.lua [new file with mode: 0644]
rules/rspamd.lua

index e598f73ef20f59ee67d331833b46fd2eb321aad8..fe89808fb13c2fb54be453adabb9b2b940f8436e 100644 (file)
 
 composites {
 
+  SHORT_PART_BAD_HEADERS {
+    expression = "MISSING_ESSENTIAL_HEADERS & SINGLE_SHORT_PART";
+    group = "blankspam";
+    policy = "leave";
+    score = 7.0;
+  }
   FORGED_RECIPIENTS_MAILLIST {
     expression = "FORGED_RECIPIENTS & -MAILLIST";
   }
index f28b0bc7a946028ee08ac3c3b6e5bb166e974698..92ebb0ca38c3543a28bc68f4240d34e24e212019 100644 (file)
@@ -547,14 +547,17 @@ local headers_unique = {
   ['Subject'] = 0.7
 }
 
-rspamd_config.MULTIPLE_UNIQUE_HEADERS = {
+local multiple_unique_headers_id = rspamd_config:register_symbol {
+  name = 'MULTIPLE_UNIQUE_HEADERS',
   callback = function(task)
     local res = 0
     local max_mult = 0.0
     local res_tbl = {}
+    local found = 0
 
     for hdr, mult in pairs(headers_unique) do
       local hc = task:get_header_count(hdr)
+      found = found + hc
 
       if hc > 1 then
         res = res + 1
@@ -566,10 +569,10 @@ rspamd_config.MULTIPLE_UNIQUE_HEADERS = {
     end
 
     if res > 0 then
-      return true, max_mult, table.concat(res_tbl, ',')
+      task:insert_result('MULTIPLE_UNIQUE_HEADERS', max_mult, table.concat(res_tbl, ','))
+    elseif found == 0 then
+      task:insert_result('MISSING_ESSENTIAL_HEADERS', 1.0)
     end
-
-    return false
   end,
 
   score = 7.0,
@@ -578,6 +581,15 @@ rspamd_config.MULTIPLE_UNIQUE_HEADERS = {
   description = 'Repeated unique headers'
 }
 
+rspamd_config:register_symbol {
+  name = 'MISSING_ESSENTIAL_HEADERS',
+  score = 7.0,
+  group = 'blankspam',
+  parent = multiple_unique_headers_id,
+  type = 'virtual',
+  description = 'Common headers were entirely absent',
+}
+
 rspamd_config.MISSING_FROM = {
   callback = function(task)
     local from = task:get_header('From')
index 17e3b8ac7deb3f5bbfb41e50d1c348fdf1007508..faf4a8fb8ec2eecb5fdd848af2bad5a4f3c7dc27 100644 (file)
@@ -853,3 +853,12 @@ rspamd_config:register_symbol {
   score = -2.0,
   one_shot = true
 }
+
+rspamd_config.COMPLETELY_EMPTY = {
+  callback = function(task)
+    return (task:get_size() == 0)
+  end,
+  flags = 'empty',
+  group = 'blankspam',
+  score = 15
+}
diff --git a/rules/parts.lua b/rules/parts.lua
new file mode 100644 (file)
index 0000000..2be9ff8
--- /dev/null
@@ -0,0 +1,11 @@
+rspamd_config.SINGLE_SHORT_PART = {
+  callback = function(task)
+    local parts = task:get_parts()
+    if #parts ~= 1 then return end
+    local text = parts[1]:get_text()
+    if not text then return end
+    if text:get_length() >= 64 then return end
+    return true
+  end,
+  score = 0.0,
+}
index 39017f1699966354b6af5513e158c18e16ec32ab..6b2c1a51cce60407858b9c617cfdb17a2cf6970f 100644 (file)
@@ -35,6 +35,7 @@ dofile(local_rules .. '/subject_checks.lua')
 dofile(local_rules .. '/misc.lua')
 dofile(local_rules .. '/forwarding.lua')
 dofile(local_rules .. '/mid.lua')
+dofile(local_rules .. '/parts.lua')
 dofile(local_rules .. '/bitcoin.lua')
 dofile(local_rules .. '/bounce.lua')
 dofile(local_rules .. '/content.lua')