commit aa41958: [Minor] Restore `task:has_urls(true)` behaviour

Vsevolod Stakhov vsevolod at rspamd.com
Thu Sep 15 22:07:04 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-09-15 23:04:54 +0100
URL: https://github.com/rspamd/rspamd/commit/aa419582649958cce55bdb25686ce7ef5abf8f08 (HEAD -> master)

[Minor] Restore `task:has_urls(true)` behaviour
Issue: #4124

---
 src/lua/lua_task.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index b7a087103..e2634ce34 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -2599,18 +2599,32 @@ lua_task_has_urls (lua_State * L)
 {
 	LUA_TRACE_POINT;
 	struct rspamd_task *task = lua_check_task (L, 1);
+	bool need_urls = false;
 	gboolean ret = FALSE;
 	gsize sz = 0;
 
 	if (task) {
 		if (task->message) {
 			if (lua_gettop (L) >= 2) {
-				lua_toboolean (L, 2);
+				need_urls = lua_toboolean (L, 2);
 			}
 
-			if (kh_size (MESSAGE_FIELD (task, urls)) > 0) {
-				sz += kh_size (MESSAGE_FIELD (task, urls));
-				ret = TRUE;
+			if (!need_urls) {
+				/* Simplified check */
+				if (kh_size (MESSAGE_FIELD (task, urls)) > 0) {
+					sz += kh_size (MESSAGE_FIELD (task, urls));
+					ret = TRUE;
+				}
+			}
+			else {
+				/* Linear scan */
+				struct rspamd_url *u;
+				kh_foreach_key(MESSAGE_FIELD (task, urls), u, {
+					if (u->protocol != PROTOCOL_MAILTO) {
+						sz ++;
+						ret = TRUE;
+					}
+				});
 			}
 		}
 	}


More information about the Commits mailing list