From c52921bf522b3dc7dfd72e9183b9ff8bba7a6c42 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 5 Dec 2013 12:03:47 +0000 Subject: [PATCH] Allow to skip unknown flags in fuzzy_check module. --- conf/metrics.conf | 4 ++-- conf/modules.conf | 4 ++-- src/plugins/fuzzy_check.c | 18 ++++++++++++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/conf/metrics.conf b/conf/metrics.conf index 9dfdb1c00..62c633bee 100644 --- a/conf/metrics.conf +++ b/conf/metrics.conf @@ -408,9 +408,9 @@ metric { name = "BAYES_HAM"; } symbol { - weight = 10.0; + weight = 5.0; description = "Generic fuzzy hash match"; - name = "R_FUZZY"; + name = "FUZZY_UNKNOWN"; } symbol { weight = 10.0; diff --git a/conf/modules.conf b/conf/modules.conf index a6a2adbed..b007ae8b5 100644 --- a/conf/modules.conf +++ b/conf/modules.conf @@ -3,9 +3,9 @@ fuzzy_check { min_bytes = 300; rule { servers = "highsecure.ru:11335"; - symbol = "R_FUZZY"; + symbol = "FUZZY_UNKNOWN"; mime_types = "application/pdf"; - max_score = 10; + max_score = 10.0; read_only = yes; fuzzy_map = { FUZZY_DENIED { diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 1a1657878..db1325d15 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -85,6 +85,7 @@ struct fuzzy_rule { GList *mime_types; double max_score; gboolean read_only; + gboolean skip_unknown; }; struct fuzzy_ctx { @@ -345,9 +346,15 @@ fuzzy_parse_rule (struct config_file *cfg, ucl_object_t *obj) if ((value = ucl_object_find_key (obj, "max_score")) != NULL) { rule->max_score = ucl_obj_todouble (value); } + if ((value = ucl_object_find_key (obj, "symbol")) != NULL) { + rule->symbol = ucl_obj_tostring (value); + } if ((value = ucl_object_find_key (obj, "read_only")) != NULL) { rule->read_only = ucl_obj_toboolean (value); } + if ((value = ucl_object_find_key (obj, "skip_unknown")) != NULL) { + rule->skip_unknown = ucl_obj_toboolean (value); + } if ((value = ucl_object_find_key (obj, "servers")) != NULL) { if (value->type == UCL_ARRAY) { @@ -541,11 +548,14 @@ fuzzy_io_callback (gint fd, short what, void *arg) symbol = map->symbol; nval = fuzzy_normalize (value, map->weight); } - msg_info ("<%s>, found fuzzy hash '%s' with weight: %.2f, in list: %s:%d", - session->task->message_id, fuzzy_to_string (session->h), nval, symbol, flag); - rspamd_snprintf (buf, sizeof (buf), "%d: %d / %.2f", flag, value, nval); - insert_result (session->task, symbol, nval, g_list_prepend (NULL, + msg_info ("<%s>, found fuzzy hash '%s' with weight: %.2f, in list: %s:%d%s", + session->task->message_id, fuzzy_to_string (session->h), nval, symbol, + flag, map == NULL ? "(unknown)" : ""); + if (map != NULL || !session->rule->skip_unknown) { + rspamd_snprintf (buf, sizeof (buf), "%d: %d / %.2f", flag, value, nval); + insert_result (session->task, symbol, nval, g_list_prepend (NULL, memory_pool_strdup (session->task->task_pool, buf))); + } } goto ok; } -- 2.39.5