From c11152d9ec349554710f8104ef3b2321cfe8a068 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 20 Mar 2017 16:52:31 +0000 Subject: [Feature] Allow to specify maximum number of shots for symbols --- src/libmime/filter.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src/libmime/filter.c') diff --git a/src/libmime/filter.c b/src/libmime/filter.c index 8b4b30534..2a6bbae6d 100644 --- a/src/libmime/filter.c +++ b/src/libmime/filter.c @@ -106,6 +106,7 @@ insert_metric_result (struct rspamd_task *task, struct rspamd_symbol *sdef; struct rspamd_symbols_group *gr = NULL; const ucl_object_t *mobj, *sobj; + gint max_shots; metric_res = rspamd_create_metric_result (task, metric->name); @@ -142,14 +143,24 @@ insert_metric_result (struct rspamd_task *task, /* Add metric score */ if ((s = g_hash_table_lookup (metric_res->symbols, symbol)) != NULL) { - if (sdef && (sdef->flags & RSPAMD_SYMBOL_FLAG_ONESHOT)) { - /* - * For one shot symbols we do not need to add them again, so - * we just force single behaviour here - */ + if (single) { + max_shots = 1; + } + else { + if (sdef) { + max_shots = sdef->nshots; + } + else { + max_shots = task->cfg->default_max_shots; + } + } + + if (!single && (max_shots > 0 && (s->nshots >= max_shots))) { single = TRUE; } + s->nshots ++; + if (rspamd_task_add_result_option (task, s, opt)) { if (!single) { diff = w; @@ -208,6 +219,7 @@ insert_metric_result (struct rspamd_task *task, s->name = symbol; s->sym = sdef; + s->nshots = 1; w = rspamd_check_group_score (task, symbol, gr, gr_score, w); @@ -285,7 +297,7 @@ rspamd_task_insert_result (struct rspamd_task *task, const gchar *opt) { return insert_result_common (task, symbol, flag, opt, - task->cfg->one_shot_mode); + FALSE); } /* Insert result as a single option */ @@ -307,7 +319,8 @@ rspamd_task_add_result_option (struct rspamd_task *task, if (s && opt) { if (s->options && !(s->sym && - (s->sym->flags & RSPAMD_SYMBOL_FLAG_ONEPARAM))) { + (s->sym->flags & RSPAMD_SYMBOL_FLAG_ONEPARAM)) && + g_hash_table_size (s->options) < task->cfg->default_max_shots) { /* Append new options */ if (!g_hash_table_lookup (s->options, opt)) { opt_cpy = rspamd_mempool_strdup (task->task_pool, opt); -- cgit v1.2.3