commit 1e6a1fe: [Minor] Some fixes in least passthrough results processing

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Apr 29 11:21:04 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-04-29 11:41:28 +0100
URL: https://github.com/rspamd/rspamd/commit/1e6a1fecc70b723109f9e7ec1b8da1acd744861c (HEAD -> master)

[Minor] Some fixes in least passthrough results processing

---
 src/libmime/filter.c | 40 ++++++++++++++++++++++++----------------
 src/lua/lua_task.c   | 13 ++++++++-----
 2 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/src/libmime/filter.c b/src/libmime/filter.c
index c3f3089f8..a454cb8df 100644
--- a/src/libmime/filter.c
+++ b/src/libmime/filter.c
@@ -503,25 +503,33 @@ rspamd_check_action_metric (struct rspamd_task *task)
 	gboolean seen_least = FALSE;
 
 	if (mres->passthrough_result != NULL)  {
-		/* Peek the highest priority result */
-		pr = mres->passthrough_result;
-		sc = pr->target_score;
-		selected_action = pr->action;
-
-		if (!(pr->flags & RSPAMD_PASSTHROUGH_LEAST)) {
-			if (!isnan (sc)) {
-				if (pr->action->action_type == METRIC_ACTION_NOACTION) {
-					mres->score = MIN (sc, mres->score);
+		DL_FOREACH (mres->passthrough_result, pr) {
+			if (!seen_least || !(pr->flags & RSPAMD_PASSTHROUGH_LEAST)) {
+				sc = pr->target_score;
+				selected_action = pr->action;
+
+				if (!(pr->flags & RSPAMD_PASSTHROUGH_LEAST)) {
+					if (!isnan (sc)) {
+						if (pr->action->action_type == METRIC_ACTION_NOACTION) {
+							mres->score = MIN (sc, mres->score);
+						}
+						else {
+							mres->score = sc;
+						}
+					}
+
+					return selected_action;
 				}
 				else {
-					mres->score = sc;
+					seen_least = true;
+
+					if (isnan (sc)) {
+						sc = selected_action->threshold;
+					}
+
+					max_score = sc;
 				}
 			}
-
-			return selected_action;
-		}
-		else {
-			seen_least = true;
 		}
 	}
 	/* We are not certain about the results during processing */
@@ -555,7 +563,7 @@ rspamd_check_action_metric (struct rspamd_task *task)
 	if (selected_action) {
 
 		if (seen_least) {
-			mres->score = MIN (sc, mres->score);
+			mres->score = MAX (max_score, mres->score);
 		}
 
 		return selected_action;
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 6a4ae145d..6a6413e7f 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -1809,11 +1809,14 @@ lua_task_set_pre_result (lua_State * L)
 		if (lua_type (L, 3) == LUA_TSTRING) {
 			message = lua_tostring (L, 3);
 
-			/* Keep compatibility here :( */
-			ucl_object_replace_key (task->messages,
-					ucl_object_fromstring_common (message, 0, UCL_STRING_RAW),
-					"smtp_message", 0,
-					false);
+			if (lua_type (L, 7) != LUA_TSTRING) {
+				/* Keep compatibility here :( */
+
+				ucl_object_replace_key (task->messages,
+						ucl_object_fromstring_common (message, 0, UCL_STRING_RAW),
+						"smtp_message", 0,
+						false);
+			}
 		}
 		else {
 			message = "unknown reason";


More information about the Commits mailing list