From: Vsevolod Stakhov Date: Thu, 15 Sep 2022 22:04:54 +0000 (+0100) Subject: [Minor] Restore `task:has_urls(true)` behaviour X-Git-Tag: 3.3~25 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=aa419582649958cce55bdb25686ce7ef5abf8f08;p=rspamd.git [Minor] Restore `task:has_urls(true)` behaviour Issue: #4124 --- 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; + } + }); } } }