]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Another iteration on #331.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 22 Jul 2015 16:02:10 +0000 (17:02 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 22 Jul 2015 16:02:10 +0000 (17:02 +0100)
src/libstat/classifiers/bayes.c
src/libstat/stat_internal.h
src/libstat/stat_process.c

index 03512f771b5a93f3bc392ec129ca8a7559ce1e30..e248fd6e606e1a52f4515fb45a3fe9b27b72eaa6 100644 (file)
@@ -256,12 +256,14 @@ bayes_learn_spam_callback (gpointer key, gpointer value, gpointer data)
        for (i = rt->start_pos; i < rt->end_pos; i++) {
                res = &g_array_index (node->results, struct rspamd_token_result, i);
 
-               if (res->st_runtime->st->is_spam) {
-                       res->value ++;
-               }
-               else if (res->value > 0) {
-                       /* Unlearning */
-                       res->value --;
+               if (res->st_runtime) {
+                       if (res->st_runtime->st->is_spam) {
+                               res->value ++;
+                       }
+                       else if (res->value > 0) {
+                               /* Unlearning */
+                               res->value --;
+                       }
                }
        }
 
@@ -280,11 +282,13 @@ bayes_learn_ham_callback (gpointer key, gpointer value, gpointer data)
        for (i = rt->start_pos; i < rt->end_pos; i++) {
                res = &g_array_index (node->results, struct rspamd_token_result, i);
 
-               if (!res->st_runtime->st->is_spam) {
-                       res->value ++;
-               }
-               else if (res->value > 0) {
-                       res->value --;
+               if (res->st_runtime) {
+                       if (!res->st_runtime->st->is_spam) {
+                               res->value ++;
+                       }
+                       else if (res->value > 0) {
+                               res->value --;
+                       }
                }
        }
 
index cb2a365c486879299b15a0fc9454ce9b8ceaa8cb..07671441188907eccbef02c6f859bf74dd63d6df 100644 (file)
@@ -63,6 +63,7 @@ struct rspamd_classifier_runtime {
        GList *st_runtime;
        guint start_pos;
        guint end_pos;
+       gboolean skipped;
 };
 
 struct rspamd_token_result {
index 5318ab1449ab994766e4618afe0bbdb8b58a0b5f..b5293f8ac6e76f2a263620bbaa5fe5c5d0004cd0 100644 (file)
@@ -112,6 +112,8 @@ preprocess_init_stat_token (gpointer k, gpointer v, gpointer d)
                                        g_tree_nnodes (cbdata->tok->tokens),
                                        cl_runtime->clcf->min_tokens);
                        cur = g_list_next (cur);
+                       cl_runtime->skipped = TRUE;
+
                        continue;
                }
 
@@ -429,6 +431,11 @@ rspamd_stat_classify (struct rspamd_task *task, lua_State *L, GError **err)
                cl_run = (struct rspamd_classifier_runtime *)cur->data;
                cl_run->stage = RSPAMD_STAT_STAGE_POST;
 
+               if (cl_run->skipped) {
+                       cur = g_list_next (cur);
+                       continue;
+               }
+
                if (cl_run->cl) {
                        if (cl_ctx != NULL) {
                                if (cl_run->cl->classify_func (cl_ctx, cl_run->tok->tokens,
@@ -442,7 +449,7 @@ rspamd_stat_classify (struct rspamd_task *task, lua_State *L, GError **err)
 
                while (curst) {
                        st_run = curst->data;
-                       st_run->backend->finalize_learn (task,
+                       st_run->backend->finalize_process (task,
                                        st_run->backend_runtime,
                                        st_run->backend->ctx);
                        curst = g_list_next (curst);
@@ -598,7 +605,7 @@ rspamd_stat_learn (struct rspamd_task *task, gboolean spam, lua_State *L,
        while (cur) {
                cl_run = (struct rspamd_classifier_runtime *)cur->data;
 
-               if (cl_run->cl) {
+               if (cl_run->cl && !cl_run->skipped) {
                        cl_ctx = cl_run->cl->init_func (task->task_pool, cl_run->clcf);
 
                        if (cl_ctx != NULL) {