From 18e6b7c84617bea86adf2653a21ab690cca76f65 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 10 Apr 2015 14:16:06 +0100 Subject: [PATCH] Allow patterns (glob) in `mime_types` for fuzzy_check. --- src/plugins/fuzzy_check.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index b88d490a2..69739b9f8 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -64,8 +64,8 @@ struct fuzzy_mapping { }; struct fuzzy_mime_type { - gchar *type; - gchar *subtype; + GPatternSpec *type; + GPatternSpec *subtype; }; struct fuzzy_rule { @@ -204,20 +204,23 @@ parse_mime_types (const gchar *str) g_strstrip (strvec[i]); if ((p = strchr (strvec[i], '/')) != NULL) { *p = 0; - type = - rspamd_mempool_alloc (fuzzy_module_ctx->fuzzy_pool, + type = rspamd_mempool_alloc (fuzzy_module_ctx->fuzzy_pool, sizeof (struct fuzzy_mime_type)); - type->type = rspamd_mempool_strdup (fuzzy_module_ctx->fuzzy_pool, - strvec[i]); - type->subtype = rspamd_mempool_strdup (fuzzy_module_ctx->fuzzy_pool, - p + 1); + type->type = g_pattern_spec_new (strvec[i]); + type->subtype = g_pattern_spec_new (p + 1); + *p = '/'; res = g_list_prepend (res, type); } else { - msg_info ("bad content type: %s", strvec[i]); + type = rspamd_mempool_alloc (fuzzy_module_ctx->fuzzy_pool, + sizeof (struct fuzzy_mime_type)); + type->type = g_pattern_spec_new (strvec[i]); + type->subtype = NULL; } } + g_strfreev (strvec); + return res; } @@ -230,9 +233,20 @@ fuzzy_check_content_type (struct fuzzy_rule *rule, GMimeContentType *type) cur = rule->mime_types; while (cur) { ft = cur->data; - if (g_mime_content_type_is_type (type, ft->type, ft->subtype)) { - return TRUE; + if (ft->type) { + + if (g_pattern_match_string (ft->type, type->type)) { + if (ft->subtype) { + if (g_pattern_match_string (ft->subtype, type->subtype)) { + return TRUE; + } + } + else { + return TRUE; + } + } } + cur = g_list_next (cur); } -- 2.39.5