diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-03-20 16:52:31 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-03-20 16:52:31 +0000 |
commit | c11152d9ec349554710f8104ef3b2321cfe8a068 (patch) | |
tree | 2e5dafc63b4ec3c3790c51667e4e82c6894b2c66 /src/libmime/filter.c | |
parent | 3f72bccd49234103b6ed4adee6f26f9c1d12d8d0 (diff) | |
download | rspamd-c11152d9ec349554710f8104ef3b2321cfe8a068.tar.gz rspamd-c11152d9ec349554710f8104ef3b2321cfe8a068.zip |
[Feature] Allow to specify maximum number of shots for symbols
Diffstat (limited to 'src/libmime/filter.c')
-rw-r--r-- | src/libmime/filter.c | 27 |
1 files changed, 20 insertions, 7 deletions
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); |