]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Do not classify message if some class is missing
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 22 Mar 2016 13:49:10 +0000 (13:49 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 22 Mar 2016 13:49:10 +0000 (13:49 +0000)
src/libserver/task.h
src/libstat/backends/mmaped_file.c
src/libstat/backends/redis_backend.c
src/libstat/backends/sqlite3_backend.c
src/libstat/stat_process.c

index a653b0a4774fce4b7b42e9de2f9ad32b98c2c860..f293ef10f7b0f96b17e4dd49c9ad60f86a63b7a0 100644 (file)
@@ -100,6 +100,8 @@ enum rspamd_task_stage {
 #define RSPAMD_TASK_FLAG_LEARN_HAM (1 << 17)
 #define RSPAMD_TASK_FLAG_LEARN_AUTO (1 << 18)
 #define RSPAMD_TASK_FLAG_BROKEN_HEADERS (1 << 19)
+#define RSPAMD_TASK_FLAG_HAS_SPAM_TOKENS (1 << 20)
+#define RSPAMD_TASK_FLAG_HAS_HAM_TOKENS (1 << 21)
 
 #define RSPAMD_TASK_IS_SKIPPED(task) (((task)->flags & RSPAMD_TASK_FLAG_SKIP))
 #define RSPAMD_TASK_IS_JSON(task) (((task)->flags & RSPAMD_TASK_FLAG_JSON))
index eba730cab3a26939a18dcd3b816b7656225d79cf..2065edd5ce7f8acc1149312a374456e92c2cbbd5 100644 (file)
@@ -871,6 +871,13 @@ rspamd_mmaped_file_process_tokens (struct rspamd_task *task, GPtrArray *tokens,
                tok->values[id] = rspamd_mmaped_file_get_block (mf, h1, h2);
        }
 
+       if (mf->cf->is_spam) {
+               task->flags |= RSPAMD_TASK_FLAG_HAS_SPAM_TOKENS;
+       }
+       else {
+               task->flags |= RSPAMD_TASK_FLAG_HAS_HAM_TOKENS;
+       }
+
        return TRUE;
 }
 
index 3b1667e1cfa0aa4ae583edc51d4d250b2c5a503b..d66b6d68e44d3cc9b3222437e130da1de788cb09 100644 (file)
@@ -828,9 +828,24 @@ rspamd_redis_processed (redisAsyncContext *c, gpointer r, gpointer priv)
 
                                                processed ++;
                                        }
+
+                                       if (rt->stcf->is_spam) {
+                                               task->flags |= RSPAMD_TASK_FLAG_HAS_SPAM_TOKENS;
+                                       }
+                                       else {
+                                               task->flags |= RSPAMD_TASK_FLAG_HAS_HAM_TOKENS;
+                                       }
+                               }
+                               else {
+                                       msg_err_task ("got invalid length of reply vector from redis: "
+                                                       "%d, expected: %d",
+                                                       (gint)reply->elements,
+                                                       (gint)task->tokens->len);
                                }
                        }
                        else {
+                               msg_err_task ("got invalid reply from redis: %d",
+                                               reply->type);
                        }
 
                        msg_debug_task ("received tokens for %s: %d processed, %d found",
index 36bbaa20e79bdc8e263dad6bef66b66ab5a40b35..f90e6b93a3628e834abb92285c61cefed96b8309 100644 (file)
@@ -723,6 +723,13 @@ rspamd_sqlite3_process_tokens (struct rspamd_task *task,
                else {
                        tok->values[id] = 0.0;
                }
+
+               if (rt->cf->is_spam) {
+                       task->flags |= RSPAMD_TASK_FLAG_HAS_SPAM_TOKENS;
+               }
+               else {
+                       task->flags |= RSPAMD_TASK_FLAG_HAS_HAM_TOKENS;
+               }
        }
 
 
index 6b1b16aed026803aaa0098a700f838510e2c2652..1761dc7a33d9b9ff524b47102e8dd99fe97c94ae 100644 (file)
@@ -321,6 +321,24 @@ rspamd_stat_classifiers_process (struct rspamd_stat_ctx *st_ctx,
        guint i;
        struct rspamd_classifier *cl;
 
+       if (st_ctx->classifiers->len == 0) {
+               return;
+       }
+
+       /*
+        * Do not classify a message if some class is missing
+        */
+       if (!(task->flags & RSPAMD_TASK_FLAG_HAS_SPAM_TOKENS)) {
+               msg_warn_task ("skip statistics as SPAM class is missing");
+
+               return;
+       }
+       if (!(task->flags & RSPAMD_TASK_FLAG_HAS_HAM_TOKENS)) {
+               msg_warn_task ("skip statistics as HAM class is missing");
+
+               return;
+       }
+
        for (i = 0; i < st_ctx->classifiers->len; i++) {
                cl = g_ptr_array_index (st_ctx->classifiers, i);
                g_assert (cl != NULL);