From 42e13bdaa1afee59cbbd62b2001e05e4f53f4888 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 9 Jan 2016 21:57:36 +0000 Subject: [PATCH] Fix learn errors reporting --- src/controller.c | 17 ++++++++++++----- src/libserver/task.c | 4 +++- src/libstat/stat_process.c | 4 ---- src/worker.c | 2 ++ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/controller.c b/src/controller.c index e5b06c2db..bef6fa61b 100644 --- a/src/controller.c +++ b/src/controller.c @@ -1199,11 +1199,18 @@ rspamd_controller_learn_fin_task (void *ud) } if (RSPAMD_TASK_IS_PROCESSED (task)) { - msg_info_session ("<%s> learned message as %s: %s", - rspamd_inet_address_to_string (session->from_addr), - session->is_spam ? "spam" : "ham", - task->message_id); - rspamd_controller_send_string (conn_ent, "{\"success\":true}"); + if (task->err) { + rspamd_controller_send_error (conn_ent, task->err->code, + task->err->message); + } + else { + msg_info_session ("<%s> learned message as %s: %s", + rspamd_inet_address_to_string (session->from_addr), + session->is_spam ? "spam" : "ham", + task->message_id); + rspamd_controller_send_string (conn_ent, "{\"success\":true}"); + } + return TRUE; } diff --git a/src/libserver/task.c b/src/libserver/task.c index fe7d490c2..2f79b540b 100644 --- a/src/libserver/task.c +++ b/src/libserver/task.c @@ -455,7 +455,9 @@ rspamd_task_process (struct rspamd_task *task, guint stages) case RSPAMD_TASK_STAGE_POST_FILTERS: rspamd_lua_call_post_filters (task); - rspamd_stat_check_autolearn (task); + if (task->flags & RSPAMD_TASK_FLAG_LEARN_AUTO) { + rspamd_stat_check_autolearn (task); + } break; case RSPAMD_TASK_STAGE_LEARN: diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c index 81986f552..4bf99b98b 100644 --- a/src/libstat/stat_process.c +++ b/src/libstat/stat_process.c @@ -843,10 +843,6 @@ rspamd_stat_check_autolearn (struct rspamd_task *task) } } - if (ret) { - task->flags |= RSPAMD_TASK_FLAG_LEARN_AUTO; - } - return ret; } diff --git a/src/worker.c b/src/worker.c index 6e46c15a7..9c5f0bd40 100644 --- a/src/worker.c +++ b/src/worker.c @@ -255,6 +255,8 @@ accept_socket (gint fd, short what, void *arg) worker->srv->stat->connections_count++; task->resolver = ctx->resolver; + /* TODO: allow to disable autolearn in protocol */ + task->flags |= RSPAMD_TASK_FLAG_LEARN_AUTO; task->http_conn = rspamd_http_connection_new ( rspamd_worker_body_handler, -- 2.39.5