commit 04616a9: [Minor] Pet luacheck and small improvements

Vsevolod Stakhov vsevolod at highsecure.ru
Sun Jul 18 11:28:04 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-07-18 12:21:40 +0100
URL: https://github.com/rspamd/rspamd/commit/04616a9ef604df1c122fde15587ec52875866515 (HEAD -> master)

[Minor] Pet luacheck and small improvements

---
 lualib/lua_scanners/pyzor.lua | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/lualib/lua_scanners/pyzor.lua b/lualib/lua_scanners/pyzor.lua
index ef9ece824..cd8c8e92b 100644
--- a/lualib/lua_scanners/pyzor.lua
+++ b/lualib/lua_scanners/pyzor.lua
@@ -121,15 +121,17 @@ local function pyzor_check(task, content, digest, rule)
         -- pyzor output is unicode (\x09 -> tab, \0a -> newline)
         --   public.pyzor.org:24441  (200, 'OK')     21285091   206759
         --   server:port             Code  Diag      Count      WL-Count
-        lua_util.debugm(N, task, '%s: returned data: %s', rule.log_prefix, tostring(data))
+        local str_data = tostring(data)
+        lua_util.debugm(N, task, '%s: returned data: %s',
+            rule.log_prefix, str_data)
         -- If pyzor would return JSON this wouldn't be necessary
         local resp = {}
-        for v in string.gmatch(tostring(data), '[^\t]+') do
+        for v in string.gmatch(str_data, '[^\t]+') do
           table.insert(resp, v)
         end
         -- rspamd_logger.infox(task, 'resp: %s', resp)
-        if resp[2] ~= '(200, \'OK\')' then
-          rspamd_logger.errx(task, "error parsing response: %s", tostring(data))
+        if resp[2] ~= [[(200, 'OK')]] then
+          rspamd_logger.errx(task, "error parsing response: %s", str_data)
           return
         end
 
@@ -151,19 +153,24 @@ local function pyzor_check(task, content, digest, rule)
           rule.default_score: 1
           Weight: 0
         ]]
-        local weight = tonumber(string.format("%.2f", rule.default_score * (reported - whitelisted) / (reported + whitelisted)))
+        local weight = tonumber(string.format("%.2f",
+            rule.default_score * (reported - whitelisted) / (reported + whitelisted)))
         local info = string.format("count=%d wl=%d", reported, whitelisted)
-        local threat_string = string.format("bl_%d_wl_%d", reported, whitelisted)
+        local threat_string = string.format("bl_%d_wl_%d",
+            reported, whitelisted)
 
         if weight > 0 then
-          lua_util.debugm(N, task, '%s: returned result is spam - info: %s', rule.log_prefix, info)
+          lua_util.debugm(N, task, '%s: returned result is spam - info: %s',
+              rule.log_prefix, info)
           common.yield_result(task, rule, threat_string, weight)
           common.save_cache(task, digest, rule, threat_string, weight)
         else
           if rule.log_clean then
-            rspamd_logger.infox(task, '%s: clean, returned result is ham - info: %s', rule.log_prefix, info)
+            rspamd_logger.infox(task, '%s: clean, returned result is ham - info: %s',
+                rule.log_prefix, info)
           else
-            lua_util.debugm(N, task, '%s: returned result is ham - info: %s', rule.log_prefix, info)
+            lua_util.debugm(N, task, '%s: returned result is ham - info: %s',
+                rule.log_prefix, info)
           end
           common.save_cache(task, digest, rule, 'OK', weight)
         end


More information about the Commits mailing list