]> source.dussan.org Git - rspamd.git/commitdiff
Add GTUBE support.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 2 Jul 2015 13:23:13 +0000 (14:23 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 3 Jul 2015 12:00:02 +0000 (13:00 +0100)
src/libmime/message.c
src/libserver/task.h

index 2df39f37222cd40476744e496dbd2949d56cd2aa..1f8167f7c6ae82f7a43e676f065ee3598751befb 100644 (file)
 #include "utlist.h"
 #include "tokenizers/tokenizers.h"
 #include "libstemmer.h"
+#include "acism.h"
 
 #include <iconv.h>
 
 #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,
index 606e4dcea7e5aae3c4c7ba84a2716bd2c63d6385..3c0a6992e759a665e54bff3e51b6709d592856b8 100644 (file)
@@ -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))