]> source.dussan.org Git - 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:17:08 +0000 (17:17 +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 f13ccc96e39b77d43c22fb21927dfd29b03a67f4..6fbc824138b1bcf9f193873a8cd967ea55b2b6e3 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;
                }
 
@@ -413,6 +415,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,
@@ -572,7 +579,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) {