diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-06-01 16:13:24 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-06-01 16:13:24 +0100 |
commit | 0c5d1f986a0bf2ee4c45427b067a45c85240f7f8 (patch) | |
tree | 744df493dead60344e4556026a40cdde19f6be6b | |
parent | 20beb1b7f83c423b060db88ff2619e5d85d25285 (diff) | |
download | rspamd-0c5d1f986a0bf2ee4c45427b067a45c85240f7f8.tar.gz rspamd-0c5d1f986a0bf2ee4c45427b067a45c85240f7f8.zip |
[Feature] Add `text_multiplier` param
This parameter affect minimum bytes setting in text parts and binary
parts. Min bytes for text part is min bytes for binary parts multiplied
by `text_multiplier`. The default value is `0.5`.
-rw-r--r-- | src/plugins/fuzzy_check.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 131500380..75f4091b8 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -97,6 +97,7 @@ struct fuzzy_ctx { guint32 min_hash_len; radix_compressed_t *whitelist; struct rspamd_keypair_cache *keypairs_cache; + gdouble text_multiplier; guint32 min_bytes; guint32 min_height; guint32 min_width; @@ -703,6 +704,15 @@ fuzzy_check_module_init (struct rspamd_config *cfg, struct module_ctx **ctx) 0); rspamd_rcl_add_doc_by_path (cfg, "fuzzy_check", + "Multiplier for bytes limit when checking for text parts", + "text_multiplier", + UCL_FLOAT, + NULL, + 0, + NULL, + 0); + rspamd_rcl_add_doc_by_path (cfg, + "fuzzy_check", "Minimum height in pixels for embedded images to check using fuzzy storage", "min_height", UCL_INT, @@ -918,6 +928,7 @@ fuzzy_check_module_config (struct rspamd_config *cfg) else { fuzzy_module_ctx->min_hash_len = 0; } + if ((value = rspamd_config_get_module_opt (cfg, "fuzzy_check", "min_bytes")) != NULL) { @@ -926,6 +937,16 @@ fuzzy_check_module_config (struct rspamd_config *cfg) else { fuzzy_module_ctx->min_bytes = 0; } + + if ((value = + rspamd_config_get_module_opt (cfg, "fuzzy_check", + "text_multiplier")) != NULL) { + fuzzy_module_ctx->text_multiplier = ucl_object_todouble (value); + } + else { + fuzzy_module_ctx->text_multiplier = 0.5; + } + if ((value = rspamd_config_get_module_opt (cfg, "fuzzy_check", "min_height")) != NULL) { @@ -2287,6 +2308,8 @@ fuzzy_generate_commands (struct rspamd_task *task, struct fuzzy_rule *rule, if (G_LIKELY (!(flags & FUZZY_CHECK_FLAG_NOTEXT))) { for (i = 0; i < task->text_parts->len; i ++) { + gdouble fac; + part = g_ptr_array_index (task->text_parts, i); if (IS_PART_EMPTY (part)) { @@ -2294,10 +2317,12 @@ fuzzy_generate_commands (struct rspamd_task *task, struct fuzzy_rule *rule, } /* Check length of part */ - if (fuzzy_module_ctx->min_bytes > part->content->len) { - msg_info_task ("<%s>, part is shorter than %d bytes (%d bytes), " + fac = fuzzy_module_ctx->text_multiplier * part->content->len; + if ((double)fuzzy_module_ctx->min_bytes > fac) { + msg_info_task ("<%s>, part is shorter than %d bytes (%.0f * %.2f bytes), " "skip fuzzy check", - task->message_id, fuzzy_module_ctx->min_bytes, + task->message_id, fuzzy_module_ctx->min_bytes, fac, + fuzzy_module_ctx->text_multiplier, part->content->len); continue; } |