]> source.dussan.org Git - rspamd.git/commitdiff
Add support for check_for_shifted_date and check_for_missing_to_header eval rules...
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 13 Nov 2015 17:14:45 +0000 (17:14 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 13 Nov 2015 17:14:45 +0000 (17:14 +0000)
src/plugins/lua/spamassassin.lua

index 53a1fc6cf20e2add2bac915c3d01d9690ccfc962..f766c8fb943e97b2807147161af600e3a47cb5db 100644 (file)
@@ -59,6 +59,9 @@ local replace = {
   post = {},
   rules = {},
 }
+local internal_regexp = {
+  date_shift = rspamd_regexp.create_cached("^\\(\\s*'((?:-?\\d+)|(?:undef))'\\s*,\\s*'((?:-?\\d+)|(?:undef))'\\s*\\)$")
+}
 local section = rspamd_config:get_all_opt("spamassassin")
 
 -- Minimum score to treat symbols as meta
@@ -213,25 +216,70 @@ local function gen_eval_rule(arg)
                 return 0
               end
             end
-           
+
             return hdr_freemail
           end
         end
-        
-        return 0   
+
+        return 0
+      end
+    },
+    {
+      'check_for_missing_to_header',
+      function (task, remain)
+        if not task:get_from(1) then
+          return 1
+        end
+
+        return 0
+      end
+    },
+    {
+      'check_for_shifted_date',
+      function (task, remain)
+        -- Remain here contains two args: start and end hours shift
+        local matches = internal_regexp['date_shift']:search(remain, true, true)
+        if matches and matches[1] then
+          local min_diff = matches[1][2]
+          local max_diff = matches[1][3]
+
+          if min_diff == 'undef' then
+            min_diff = 0
+          else
+            min_diff = tonumber(min_diff) * 3600
+          end
+          if max_diff == 'undef' then
+            max_diff = 0
+          else
+            max_diff = tonumber(max_diff) * 3600
+          end
+
+          -- Now get the difference between Date and message received date
+          local dm = task:get_date { format = 'message', gmt = true}
+          local dt = task:get_date { format = 'connect', gmt = true}
+          local diff = dm - dt
+
+          if (max_diff == 0 and diff >= min_diff) or
+              (min_diff == 0 and diff <= max_diff) or
+              (diff >= min_diff and diff <= max_diff) then
+            return 1
+          end
+        end
+
+        return 0
       end
     },
   }
-  
+
   for k,f in ipairs(eval_funcs) do
     local pat = string.format('^%s', f[1])
     local first,last = string.find(arg, pat)
-    
+
     if first then
       local func_arg = string.sub(arg, last + 1)
       return function(task)
         return f[2](task, func_arg)
-      end 
+      end
     end
   end
 end