aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-09-22 13:00:24 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-09-22 13:00:24 +0100
commit876a816414bc2333c077ed8bc55cc1261b4d093a (patch)
treee4de8964eee5810b958578fbaf7924bb84cc23c7 /src/plugins
parentbb582f23a0f5aef76ae05dc116778a1afdb0fe2a (diff)
downloadrspamd-876a816414bc2333c077ed8bc55cc1261b4d093a.tar.gz
rspamd-876a816414bc2333c077ed8bc55cc1261b4d093a.zip
[Feature] Fuzzy_check: Add weight_threshold option for fuzzy rules
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/fuzzy_check.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c
index 5c9ef7fe7..810abf587 100644
--- a/src/plugins/fuzzy_check.c
+++ b/src/plugins/fuzzy_check.c
@@ -82,6 +82,7 @@ struct fuzzy_rule {
struct rspamd_cryptobox_keypair *local_key;
struct rspamd_cryptobox_pubkey *peer_key;
double max_score;
+ double weight_threshold;
gboolean read_only;
gboolean skip_unknown;
gboolean no_share;
@@ -312,6 +313,7 @@ fuzzy_rule_new (const char *default_symbol, rspamd_mempool_t *pool)
(rspamd_mempool_destruct_t)g_hash_table_unref,
rule->mappings);
rule->read_only = FALSE;
+ rule->weight_threshold = NAN;
return rule;
}
@@ -596,6 +598,10 @@ fuzzy_parse_rule (struct rspamd_config *cfg, const ucl_object_t *obj,
rule->algorithm_str);
}
+ if ((value = ucl_object_lookup (obj, "weight_threshold")) != NULL) {
+ rule->weight_threshold = ucl_object_todouble (value);
+ }
+
/*
* Process rule in Lua
*/
@@ -2362,7 +2368,8 @@ fuzzy_check_try_read (struct fuzzy_client_session *session)
}
static void
-fuzzy_insert_metric_results (struct rspamd_task *task, GPtrArray *results)
+fuzzy_insert_metric_results (struct rspamd_task *task, struct fuzzy_rule *rule,
+ GPtrArray *results)
{
struct fuzzy_client_result *res;
guint i;
@@ -2439,8 +2446,22 @@ fuzzy_insert_metric_results (struct rspamd_task *task, GPtrArray *results)
}
}
- rspamd_task_insert_result_single (task, res->symbol,
- res->score * mult, res->option);
+ gdouble weight = res->score * mult;
+
+ if (!isnan (rule->weight_threshold)) {
+ if (weight >= rule->weight_threshold) {
+ rspamd_task_insert_result_single (task, res->symbol,
+ weight, res->option);
+ }
+ else {
+ msg_info_task ("%s is not added: weight=%.4f below threshold",
+ res->symbol, weight);
+ }
+ }
+ else {
+ rspamd_task_insert_result_single (task, res->symbol,
+ weight, res->option);
+ }
}
}
@@ -2461,10 +2482,12 @@ fuzzy_check_session_is_completed (struct fuzzy_client_session *session)
}
if (nreplied == session->commands->len) {
- fuzzy_insert_metric_results (session->task, session->results);
+ fuzzy_insert_metric_results (session->task, session->rule, session->results);
+
if (session->item) {
rspamd_symcache_item_async_dec_check (session->task, session->item, M);
}
+
rspamd_session_remove_event (session->task->s, fuzzy_io_fin, session);
return TRUE;