commit 5ccaf0c: [Minor] Fix plugins to work with empty tasks

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Jul 12 16:42:39 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-07-12 17:27:13 +0100
URL: https://github.com/rspamd/rspamd/commit/5ccaf0c78a1b8ebcb75956941dcd648cf5614fe9 (refs/pull/2976/head, mime-rework)

[Minor] Fix plugins to work with empty tasks

---
 src/lua/lua_task.c           | 27 ++++++++++++++++-----------
 src/plugins/lua/greylist.lua | 23 +++++++++++------------
 src/plugins/lua/rbl.lua      |  2 +-
 3 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index d77d5b01d..068459922 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -5416,18 +5416,23 @@ lua_task_get_newlines_type (lua_State *L)
 	LUA_TRACE_POINT;
 	struct rspamd_task *task = lua_check_task (L, 1);
 
-	if (task && task->message) {
-		switch (MESSAGE_FIELD (task, nlines_type)) {
-		case RSPAMD_TASK_NEWLINES_CR:
-			lua_pushstring (L, "cr");
-			break;
-		case RSPAMD_TASK_NEWLINES_LF:
-			lua_pushstring (L, "lf");
-			break;
-		case RSPAMD_TASK_NEWLINES_CRLF:
-		default:
+	if (task) {
+		if (task->message) {
+			switch (MESSAGE_FIELD (task, nlines_type)) {
+			case RSPAMD_TASK_NEWLINES_CR:
+				lua_pushstring (L, "cr");
+				break;
+			case RSPAMD_TASK_NEWLINES_LF:
+				lua_pushstring (L, "lf");
+				break;
+			case RSPAMD_TASK_NEWLINES_CRLF:
+			default:
+				lua_pushstring (L, "crlf");
+				break;
+			}
+		}
+		else {
 			lua_pushstring (L, "crlf");
-			break;
 		}
 	}
 	else {
diff --git a/src/plugins/lua/greylist.lua b/src/plugins/lua/greylist.lua
index f39f197f5..796623b7f 100644
--- a/src/plugins/lua/greylist.lua
+++ b/src/plugins/lua/greylist.lua
@@ -63,6 +63,7 @@ local settings = {
 
 local rspamd_logger = require "rspamd_logger"
 local rspamd_util = require "rspamd_util"
+local lua_redis = require "lua_redis"
 local fun = require "fun"
 local hash = require "rspamd_cryptobox_hash"
 local rspamd_lua_utils = require "lua_util"
@@ -258,13 +259,13 @@ local function greylist_check(task)
     end
   end
 
-  local ret = rspamd_redis_make_request(task,
-    redis_params, -- connect params
-    hash_key, -- hash key
-    false, -- is write
-    redis_get_cb, --callback
-    'MGET', -- command
-    {body_key, meta_key} -- arguments
+  local ret = lua_redis.redis_make_request(task,
+      redis_params, -- connect params
+      hash_key, -- hash key
+      false, -- is write
+      redis_get_cb, --callback
+      'MGET', -- command
+      {body_key, meta_key} -- arguments
   )
   if not ret then
     rspamd_logger.errx(task, 'cannot make redis request to check results')
@@ -373,7 +374,7 @@ local function greylist_set(task)
 
     if not settings.check_local and is_rspamc then return end
 
-    ret,conn,upstream = rspamd_redis_make_request(task,
+    ret,conn,upstream = lua_redis.make_request(task,
       redis_params, -- connect params
       hash_key, -- hash key
       true, -- is write
@@ -396,7 +397,7 @@ local function greylist_set(task)
     rspamd_logger.infox(task, 'greylisted until "%s", new record', end_time)
     greylist_message(task, end_time, 'new record')
     -- Create new record
-    ret,conn,upstream = rspamd_redis_make_request(task,
+    ret,conn,upstream = lua_redis.redis_make_request(task,
       redis_params, -- connect params
       hash_key, -- hash key
       true, -- is write
@@ -458,7 +459,7 @@ if opts then
   whitelist_domains_map = lua_map.rspamd_map_add(N, 'whitelist_domains_url',
     'map', 'Greylist whitelist domains map')
 
-  redis_params = rspamd_parse_redis_server(N)
+  redis_params = lua_redis.parse_redis_server(N)
   if not redis_params then
     rspamd_logger.infox(rspamd_config, 'no servers are specified, disabling module')
     rspamd_lua_utils.disable_module(N, "redis")
@@ -468,14 +469,12 @@ if opts then
       type = 'postfilter',
       callback = greylist_set,
       priority = 6,
-      flags = 'empty',
     })
     rspamd_config:register_symbol({
       name = 'GREYLIST_CHECK',
       type = 'prefilter',
       callback = greylist_check,
       priority = 6,
-      flags = 'empty',
     })
   end
 end
diff --git a/src/plugins/lua/rbl.lua b/src/plugins/lua/rbl.lua
index eb2e3ed82..70339fd85 100644
--- a/src/plugins/lua/rbl.lua
+++ b/src/plugins/lua/rbl.lua
@@ -547,7 +547,7 @@ local function add_rbl(key, rbl)
     flags_tbl[#flags_tbl + 1] = 'nice'
   end
 
-  if not (rbl.dkim or rbl.emails) then
+  if not (rbl.dkim or rbl.emails or rbl.received) then
     flags_tbl[#flags_tbl + 1] = 'empty'
   end
 


More information about the Commits mailing list