From 535538f55126dea8962c79c3f8d0d787409c8421 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 15 Apr 2016 14:28:31 +0100 Subject: [PATCH] [Feature] Avoid acism usage to find gtube pattern --- src/libmime/message.c | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/src/libmime/message.c b/src/libmime/message.c index ed2014ef7..302717c9d 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -28,8 +28,6 @@ #include "libstemmer.h" #endif -#include "acism.h" - #include #define RECURSION_LIMIT 5 @@ -39,7 +37,6 @@ #define SET_PART_RAW(part) ((part)->flags &= ~RSPAMD_MIME_PART_FLAG_UTF) #define SET_PART_UTF(part) ((part)->flags |= RSPAMD_MIME_PART_FLAG_UTF) -static ac_trie_t *gtube_trie = NULL; static const gchar gtube_pattern[] = "XJS*C4JDBQADN1.NSBN3*2IDNEN*" "GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"; static rspamd_regexp_t *utf_compatible_re = NULL; @@ -1078,32 +1075,17 @@ rspamd_words_levenshtein_distance (struct rspamd_task *task, return column[s1len]; } -static int -rspamd_gtube_cb (int strnum, int textpos, void *context) -{ - return TRUE; -} - static gboolean rspamd_check_gtube (struct rspamd_task *task, struct mime_text_part *part) { - static ac_trie_pat_t pat[1] = { - { - .ptr = gtube_pattern, - .len = sizeof (gtube_pattern) - 1 - } - }; - gint state = 0; - + static const gsize max_check_size = 4 * 1024; g_assert (part != NULL); - if (gtube_trie == NULL) { - gtube_trie = acism_create (pat, G_N_ELEMENTS (pat)); - } - - if (part->content && part->content->len > sizeof (gtube_pattern)) { - if (acism_lookup (gtube_trie, part->content->data, part->content->len, - rspamd_gtube_cb, NULL, &state, FALSE)) { + if (part->content && part->content->len > sizeof (gtube_pattern) && + part->content->len <= max_check_size) { + if (rspamd_substring_search_twoway (part->content->data, + part->content->len, + gtube_pattern, sizeof (gtube_pattern) - 1) != -1) { task->flags |= RSPAMD_TASK_FLAG_SKIP; task->flags |= RSPAMD_TASK_FLAG_GTUBE; msg_info_task ("<%s>: gtube pattern has been found in part of length %ud", -- 2.39.5