aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_task.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2022-09-15 23:04:54 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2022-09-15 23:05:46 +0100
commitaa419582649958cce55bdb25686ce7ef5abf8f08 (patch)
treec7006a78581e5d257bb31200af0e714f086f3a63 /src/lua/lua_task.c
parent4bc2d652db7130ace5f7a44fda0f42ca8bef4bae (diff)
downloadrspamd-aa419582649958cce55bdb25686ce7ef5abf8f08.tar.gz
rspamd-aa419582649958cce55bdb25686ce7ef5abf8f08.zip
[Minor] Restore `task:has_urls(true)` behaviour
Issue: #4124
Diffstat (limited to 'src/lua/lua_task.c')
-rw-r--r--src/lua/lua_task.c22
1 files 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;
+ }
+ });
}
}
}