commit 2df03ee: [Fix] Fix greylisting log message and logic

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Dec 27 18:28:04 UTC 2018


Author: Vsevolod Stakhov
Date: 2018-12-07 08:38:34 +0000
URL: https://github.com/rspamd/rspamd/commit/2df03ee50f6ca1415f2f0ba8d5cf87a93a3ed094

[Fix] Fix greylisting log message and logic

---
 src/plugins/lua/greylist.lua | 47 ++++++++++++++++++++++++++++----------------
 1 file changed, 30 insertions(+), 17 deletions(-)

diff --git a/src/plugins/lua/greylist.lua b/src/plugins/lua/greylist.lua
index 87ed1080d..20b5550fa 100644
--- a/src/plugins/lua/greylist.lua
+++ b/src/plugins/lua/greylist.lua
@@ -132,7 +132,7 @@ local function envelope_key(task)
 end
 
 -- Returns pair of booleans: found,greylisted
-local function check_time(task, tm, type)
+local function check_time(task, tm, type, now)
   local t = tonumber(tm)
 
   if not t then
@@ -140,7 +140,6 @@ local function check_time(task, tm, type)
     return false,false
   end
 
-  local now = rspamd_util.get_time()
   if now - t < settings['timeout'] then
     return true,true
   else
@@ -196,37 +195,51 @@ local function greylist_check(task)
 
     if data then
       local end_time_body,end_time_meta
+      local now = rspamd_util.get_time()
 
       if data[1] and type(data[1]) ~= 'userdata' then
-        local tm = tonumber(data[1]) or rspamd_util.get_time()
-        ret_body,greylisted_body = check_time(task, data[1], 'body')
+        local tm = tonumber(data[1]) or now
+        ret_body,greylisted_body = check_time(task, data[1], 'body', now)
         if greylisted_body then
-          end_time_body = rspamd_util.time_to_string(tm + settings['timeout'])
-          task:get_mempool():set_variable("grey_greylisted_body", end_time_body)
+          end_time_body = tm + settings['timeout']
+          task:get_mempool():set_variable("grey_greylisted_body",
+              rspamd_util.time_to_string(end_time_body))
         end
       end
 
       if data[2] and type(data[2]) ~= 'userdata' then
         if not ret_body or greylisted_body then
-          local tm = tonumber(data[2]) or rspamd_util.get_time()
-          ret_meta,greylisted_meta = check_time(task, data[2], 'meta')
+          local tm = tonumber(data[2]) or now
+          ret_meta,greylisted_meta = check_time(task, data[2], 'meta', now)
 
           if greylisted_meta then
-            end_time_meta = rspamd_util.time_to_string(tm + settings['timeout'])
-            task:get_mempool():set_variable("grey_greylisted_meta", end_time_meta)
+            end_time_meta = tm + settings['timeout']
+            task:get_mempool():set_variable("grey_greylisted_meta",
+                rspamd_util.time_to_string(end_time_meta))
           end
         end
       end
 
       if not ret_body and not ret_meta then
-        local end_time = rspamd_util.time_to_string(rspamd_util.get_time()
-          + settings['timeout'])
-        task:get_mempool():set_variable("grey_greylisted", end_time)
+        local end_time = rspamd_util.get_time() + settings['timeout']
+        task:get_mempool():set_variable("grey_greylisted",
+          rspamd_util.time_to_string(end_time))
       elseif greylisted_body and greylisted_meta then
-        local end_time = math.min(end_time_body, end_time_meta)
-        rspamd_logger.infox(task, 'greylisted until "%s"',
-          end_time)
-        greylist_message(task, end_time, 'too early')
+        local end_time_str = rspamd_util.time_to_string(
+            math.min(end_time_body, end_time_meta))
+        rspamd_logger.infox(task, 'greylisted until (meta and body) "%s"',
+            end_time_str)
+        greylist_message(task, end_time_str, 'too early')
+      elseif greylisted_body then
+        local end_time_str = rspamd_util.time_to_string(end_time_body)
+        rspamd_logger.infox(task, 'greylisted until (body only) "%s"',
+            end_time_str)
+        greylist_message(task, end_time_str, 'too early')
+      else
+        local end_time_str = rspamd_util.time_to_string(end_time_meta)
+        rspamd_logger.infox(task, 'greylisted until (meta only) "%s"',
+            end_time_str)
+        greylist_message(task, end_time_str, 'too early')
       end
     elseif err then
       rspamd_logger.errx(task, 'got error while getting greylisting keys: %1', err)


More information about the Commits mailing list