From 7b9dd286eae49337eaebdd41cfbc5d3569a1e585 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 15 Jan 2024 15:25:23 +0000 Subject: [Minor] Fix scripts invocation --- src/libstat/learn_cache/redis_cache.cxx | 34 +++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'src/libstat/learn_cache') diff --git a/src/libstat/learn_cache/redis_cache.cxx b/src/libstat/learn_cache/redis_cache.cxx index e53bd4df0..86a6a35d4 100644 --- a/src/libstat/learn_cache/redis_cache.cxx +++ b/src/libstat/learn_cache/redis_cache.cxx @@ -217,22 +217,28 @@ static gint rspamd_stat_cache_checked(lua_State *L) { auto *task = lua_check_task(L, 1); - auto val = lua_tointeger(L, 2); - - if ((val > 0 && (task->flags & RSPAMD_TASK_FLAG_LEARN_SPAM)) || - (val < 0 && (task->flags & RSPAMD_TASK_FLAG_LEARN_HAM))) { - /* Already learned */ - msg_info_task("<%s> has been already " - "learned as %s, ignore it", - MESSAGE_FIELD(task, message_id), - (task->flags & RSPAMD_TASK_FLAG_LEARN_SPAM) ? "spam" : "ham"); - task->flags |= RSPAMD_TASK_FLAG_ALREADY_LEARNED; - } - else if (val != 0) { - /* Unlearn flag */ - task->flags |= RSPAMD_TASK_FLAG_UNLEARN; + auto res = lua_toboolean(L, 2); + + if (res) { + auto val = lua_tointeger(L, 3); + + if ((val > 0 && (task->flags & RSPAMD_TASK_FLAG_LEARN_SPAM)) || + (val < 0 && (task->flags & RSPAMD_TASK_FLAG_LEARN_HAM))) { + /* Already learned */ + msg_info_task("<%s> has been already " + "learned as %s, ignore it", + MESSAGE_FIELD(task, message_id), + (task->flags & RSPAMD_TASK_FLAG_LEARN_SPAM) ? "spam" : "ham"); + task->flags |= RSPAMD_TASK_FLAG_ALREADY_LEARNED; + } + else if (val != 0) { + /* Unlearn flag */ + task->flags |= RSPAMD_TASK_FLAG_UNLEARN; + } } + /* Ignore errors for now, as we can do nothing about them at the moment */ + return 0; } -- cgit v1.2.3