summaryrefslogtreecommitdiffstats
path: root/src/libstat
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-03-22 13:49:10 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-03-22 13:49:10 +0000
commitef6ed76aa67ada4dc45b0b0bccb437b22d56a2ab (patch)
treec70c8b8a53e38a2be8c770c488c95f8008dfb8a9 /src/libstat
parentc6836066bd90451f97c4db256385e23f2e922572 (diff)
downloadrspamd-ef6ed76aa67ada4dc45b0b0bccb437b22d56a2ab.tar.gz
rspamd-ef6ed76aa67ada4dc45b0b0bccb437b22d56a2ab.zip
[Feature] Do not classify message if some class is missing
Diffstat (limited to 'src/libstat')
-rw-r--r--src/libstat/backends/mmaped_file.c7
-rw-r--r--src/libstat/backends/redis_backend.c15
-rw-r--r--src/libstat/backends/sqlite3_backend.c7
-rw-r--r--src/libstat/stat_process.c18
4 files changed, 47 insertions, 0 deletions
diff --git a/src/libstat/backends/mmaped_file.c b/src/libstat/backends/mmaped_file.c
index eba730cab..2065edd5c 100644
--- a/src/libstat/backends/mmaped_file.c
+++ b/src/libstat/backends/mmaped_file.c
@@ -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;
}
diff --git a/src/libstat/backends/redis_backend.c b/src/libstat/backends/redis_backend.c
index 3b1667e1c..d66b6d68e 100644
--- a/src/libstat/backends/redis_backend.c
+++ b/src/libstat/backends/redis_backend.c
@@ -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",
diff --git a/src/libstat/backends/sqlite3_backend.c b/src/libstat/backends/sqlite3_backend.c
index 36bbaa20e..f90e6b93a 100644
--- a/src/libstat/backends/sqlite3_backend.c
+++ b/src/libstat/backends/sqlite3_backend.c
@@ -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;
+ }
}
diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c
index 6b1b16aed..1761dc7a3 100644
--- a/src/libstat/stat_process.c
+++ b/src/libstat/stat_process.c
@@ -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);