Browse Source

[Feature] Fuzzy_check: Add weight_threshold option for fuzzy rules

pull/3491/head
Vsevolod Stakhov 5 years ago
parent
commit
876a816414
  1. 8
      src/libmime/scan_result.h
  2. 31
      src/plugins/fuzzy_check.c

8
src/libmime/scan_result.h

@ -144,10 +144,10 @@ struct rspamd_symbol_result *rspamd_task_insert_result_full (struct rspamd_task
enum rspamd_symbol_insert_flags flags,
struct rspamd_scan_result *result);
#define rspamd_task_insert_result_single(task, symbol, flag, opts) \
rspamd_task_insert_result_full (task, symbol, flag, opts, RSPAMD_SYMBOL_INSERT_SINGLE, NULL)
#define rspamd_task_insert_result(task, symbol, flag, opts) \
rspamd_task_insert_result_full (task, symbol, flag, opts, RSPAMD_SYMBOL_INSERT_DEFAULT, NULL)
#define rspamd_task_insert_result_single(task, symbol, weight, opts) \
rspamd_task_insert_result_full ((task), (symbol), (weight), (opts), RSPAMD_SYMBOL_INSERT_SINGLE, NULL)
#define rspamd_task_insert_result(task, symbol, weight, opts) \
rspamd_task_insert_result_full ((task), (symbol), (weight), (opts), RSPAMD_SYMBOL_INSERT_DEFAULT, NULL)
/**
* Removes a symbol from a specific symbol result

31
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;

Loading…
Cancel
Save