From 608ccc53afc4947256003eaf1713036230243f17 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 2 Jul 2015 14:23:13 +0100 Subject: [PATCH] Add GTUBE support. --- src/libmime/message.c | 67 +++++++++++++++++++++++++++++++++++++++++++ src/libserver/task.h | 2 ++ 2 files changed, 69 insertions(+) diff --git a/src/libmime/message.c b/src/libmime/message.c index 2df39f372..1f8167f7c 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -32,15 +32,27 @@ #include "utlist.h" #include "tokenizers/tokenizers.h" #include "libstemmer.h" +#include "acism.h" #include #define RECURSION_LIMIT 30 #define UTF8_CHARSET "UTF-8" +#define GTUBE_SYMBOL "GTUBE" #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 GQuark +rspamd_message_quark (void) +{ + return g_quark_from_static_string ("mime-error"); +} + GByteArray * strip_html_tags (struct rspamd_task *task, rspamd_mempool_t * pool, @@ -1238,6 +1250,44 @@ rspamd_normalize_text_part (struct rspamd_task *task, } } +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; + + 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)) { + task->flags |= RSPAMD_TASK_FLAG_SKIP; + task->flags |= RSPAMD_TASK_FLAG_GTUBE; + msg_info ("<%s>: gtube pattern has been found in part of length %ud", + task->message_id, part->content->len); + + return TRUE; + } + } + + return FALSE; +} + static void process_text_part (struct rspamd_task *task, GByteArray *part_content, @@ -1341,6 +1391,23 @@ process_text_part (struct rspamd_task *task, return; } + if (rspamd_check_gtube (task, text_part)) { + struct metric_result *mres; + + mres = rspamd_create_metric_result (task, DEFAULT_METRIC); + + if (mres != NULL) { + mres->score = mres->metric->actions[METRIC_ACTION_REJECT].score; + mres->action = METRIC_ACTION_REJECT; + } + + task->pre_result.action = METRIC_ACTION_REJECT; + task->pre_result.str = "Gtube pattern"; + rspamd_task_insert_result (task, GTUBE_SYMBOL, 0, NULL); + + return; + } + /* Post process part */ detect_text_language (text_part); text_part->words = rspamd_tokenize_text (text_part->content->data, diff --git a/src/libserver/task.h b/src/libserver/task.h index 606e4dcea..3c0a6992e 100644 --- a/src/libserver/task.h +++ b/src/libserver/task.h @@ -61,6 +61,8 @@ enum rspamd_metric_action { #define RSPAMD_TASK_FLAG_NO_LOG (1 << 7) #define RSPAMD_TASK_FLAG_NO_IP (1 << 8) #define RSPAMD_TASK_FLAG_HAS_CONTROL (1 << 9) +#define RSPAMD_TASK_FLAG_PROCESSING (1 << 10) +#define RSPAMD_TASK_FLAG_GTUBE (1 << 11) #define RSPAMD_TASK_IS_SKIPPED(task) (((task)->flags & RSPAMD_TASK_FLAG_SKIP)) #define RSPAMD_TASK_IS_JSON(task) (((task)->flags & RSPAMD_TASK_FLAG_JSON)) -- 2.39.5