aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-12-05 14:39:34 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-12-05 14:39:34 +0000
commit337d5d63c0c04e6524f0900026b7a0b4bca74386 (patch)
tree353013482b4baa4040e79e30debe42a2035d8bc8
parent09ca17bcd48f001895095c36235262ab9d97dae7 (diff)
downloadrspamd-337d5d63c0c04e6524f0900026b7a0b4bca74386.tar.gz
rspamd-337d5d63c0c04e6524f0900026b7a0b4bca74386.zip
[Feature] Do not increase score for duplicate options
-rw-r--r--src/libmime/filter.c40
-rw-r--r--src/libmime/filter.h2
2 files changed, 26 insertions, 16 deletions
diff --git a/src/libmime/filter.c b/src/libmime/filter.c
index 200741260..97c8d9df7 100644
--- a/src/libmime/filter.c
+++ b/src/libmime/filter.c
@@ -142,23 +142,25 @@ insert_metric_result (struct rspamd_task *task,
*/
single = TRUE;
}
- if (!single) {
- /* Handle grow factor */
- if (metric_res->grow_factor && w > 0) {
- w *= metric_res->grow_factor;
- metric_res->grow_factor *= metric->grow_factor;
+
+ if (rspamd_task_add_result_option (task, s, opt)) {
+ if (!single) {
+ /* Handle grow factor */
+ if (metric_res->grow_factor && w > 0) {
+ w *= metric_res->grow_factor;
+ metric_res->grow_factor *= metric->grow_factor;
+ }
+ s->score += w;
+ metric_res->score += w;
}
- s->score += w;
- metric_res->score += w;
- }
- else {
- if (fabs (s->score) < fabs (w)) {
- /* Replace less weight with a bigger one */
- metric_res->score = metric_res->score - s->score + w;
- s->score = w;
+ else {
+ if (fabs (s->score) < fabs (w)) {
+ /* Replace less weight with a bigger one */
+ metric_res->score = metric_res->score - s->score + w;
+ s->score = w;
+ }
}
}
- rspamd_task_add_result_option (task, s, opt);
}
else {
s = rspamd_mempool_alloc0 (task->task_pool, sizeof (struct rspamd_symbol_result));
@@ -250,11 +252,12 @@ rspamd_task_insert_result_single (struct rspamd_task *task,
return insert_result_common (task, symbol, flag, opt, TRUE);
}
-void
+gboolean
rspamd_task_add_result_option (struct rspamd_task *task,
struct rspamd_symbol_result *s, const gchar *opt)
{
char *opt_cpy;
+ gboolean ret = FALSE;
if (s && opt) {
if (s->options && !(s->sym &&
@@ -263,6 +266,7 @@ rspamd_task_add_result_option (struct rspamd_task *task,
if (!g_hash_table_lookup (s->options, opt)) {
opt_cpy = rspamd_mempool_strdup (task->task_pool, opt);
g_hash_table_insert (s->options, opt_cpy, opt_cpy);
+ ret = TRUE;
}
}
else {
@@ -273,8 +277,14 @@ rspamd_task_add_result_option (struct rspamd_task *task,
s->options);
opt_cpy = rspamd_mempool_strdup (task->task_pool, opt);
g_hash_table_insert (s->options, opt_cpy, opt_cpy);
+ ret = TRUE;
}
}
+ else if (!opt) {
+ ret = TRUE;
+ }
+
+ return ret;
}
gboolean
diff --git a/src/libmime/filter.h b/src/libmime/filter.h
index 5b9134b8a..e947dbd44 100644
--- a/src/libmime/filter.h
+++ b/src/libmime/filter.h
@@ -79,7 +79,7 @@ struct rspamd_symbol_result* rspamd_task_insert_result_single (struct rspamd_tas
* @param s
* @param opt
*/
-void rspamd_task_add_result_option (struct rspamd_task *task,
+gboolean rspamd_task_add_result_option (struct rspamd_task *task,
struct rspamd_symbol_result *s, const gchar *opt);
/**