diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-01-06 15:08:48 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-01-06 15:08:48 +0000 |
commit | 96d887fb8e167278e5406f91882ac262355c9ebe (patch) | |
tree | 8ddd59634e116ced4229d5a217679034436195dc /src/controller.c | |
parent | df9ada40a53a804d2d90d9dfddc149a68c141a15 (diff) | |
download | rspamd-96d887fb8e167278e5406f91882ac262355c9ebe.tar.gz rspamd-96d887fb8e167278e5406f91882ac262355c9ebe.zip |
Fix learning.
Diffstat (limited to 'src/controller.c')
-rw-r--r-- | src/controller.c | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/src/controller.c b/src/controller.c index aa90fc8b6..0a359a9a6 100644 --- a/src/controller.c +++ b/src/controller.c @@ -1163,25 +1163,55 @@ rspamd_controller_learn_fin_task (void *ud) struct rspamd_task *task = ud; struct rspamd_controller_session *session; struct rspamd_http_connection_entry *conn_ent; - GError *err = NULL; conn_ent = task->fin_arg; session = conn_ent->ud; - if (rspamd_learn_task_spam (task, session->is_spam, session->classifier, &err) == - RSPAMD_STAT_PROCESS_ERROR) { - msg_info_session ("cannot learn <%s>: %e", task->message_id, err); - rspamd_controller_send_error (conn_ent, err->code, err->message); + if (task->err != NULL) { + msg_info_session ("cannot learn <%s>: %e", task->message_id, task->err); + rspamd_controller_send_error (conn_ent, task->err->code, + task->err->message); return TRUE; } - /* Successful learn */ - 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 (RSPAMD_TASK_IS_PROCESSED (task)) { + /* Successful learn */ + 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; + } + + if (!rspamd_task_process (task, RSPAMD_TASK_PROCESS_LEARN)) { + msg_info_session ("cannot learn <%s>: %e", task->message_id, task->err); + + if (task->err) { + rspamd_controller_send_error (conn_ent, task->err->code, + task->err->message); + } + else { + rspamd_controller_send_error (conn_ent, 500, + "Internal error"); + } + } + + 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}"); + return TRUE; + } + + /* One more iteration */ + return FALSE; + + + return TRUE; } @@ -1284,6 +1314,8 @@ rspamd_controller_handle_learn_common ( return 0; } + rspamd_learn_task_spam (task, is_spam, session->classifier, NULL); + if (!rspamd_task_process (task, RSPAMD_TASK_PROCESS_LEARN)) { msg_warn_session ("<%s> message cannot be processed", task->message_id); rspamd_controller_send_error (conn_ent, task->err->code, task->err->message); |