diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-11-15 15:43:08 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-11-15 15:43:08 +0000 |
commit | b5d08799fcadfb314682f4fd29bcb44cce56c802 (patch) | |
tree | 3bda02e2bec0d644fa603d062c33625daa15e804 /src | |
parent | fa934c88f35c402aa01d5c039bb11040cb2afa63 (diff) | |
download | rspamd-b5d08799fcadfb314682f4fd29bcb44cce56c802.tar.gz rspamd-b5d08799fcadfb314682f4fd29bcb44cce56c802.zip |
[Minor] Check for empty bayes results
Diffstat (limited to 'src')
-rw-r--r-- | src/libstat/classifiers/bayes.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/libstat/classifiers/bayes.c b/src/libstat/classifiers/bayes.c index 1898df4fe..1a28a42cb 100644 --- a/src/libstat/classifiers/bayes.c +++ b/src/libstat/classifiers/bayes.c @@ -329,6 +329,21 @@ bayes_classify (struct rspamd_classifier * ctx, bayes_classify_token (ctx, tok, &cl); } + if (cl.processed_tokens == 0) { + msg_info_bayes ("no tokens found in bayes database, ignore stats"); + + return TRUE; + } + + if (ctx->cfg->min_tokens > 0 && + cl.text_tokens < (gint)(ctx->cfg->min_tokens * 0.1)) { + msg_info_bayes ("ignore bayes probability since we have " + "too few text tokens: %uL, at least %d is required", + cl.text_tokens, (gint)(ctx->cfg->min_tokens * 0.1)); + + return TRUE; + } + h = 1 - inv_chi_square (task, cl.spam_prob, cl.processed_tokens); s = 1 - inv_chi_square (task, cl.ham_prob, cl.processed_tokens); @@ -368,17 +383,6 @@ bayes_classify (struct rspamd_classifier * ctx, } } - if (ctx->cfg->min_tokens > 0 && - cl.text_tokens < (gint)(ctx->cfg->min_tokens * 0.1)) { - msg_info_bayes ("ignore bayes probability %.2f since we have " - "too few text tokens: %uL, at least %d is required", - final_prob, - cl.text_tokens, - (gint)(ctx->cfg->min_tokens * 0.1)); - - return TRUE; - } - pprob = rspamd_mempool_alloc (task->task_pool, sizeof (*pprob)); *pprob = final_prob; rspamd_mempool_set_variable (task->task_pool, "bayes_prob", pprob, NULL); |