summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-07-02 14:23:13 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-07-02 14:23:31 +0100
commitc3b8ab4425a166cfc9fb85068532fc9eeb66a68d (patch)
treec866c5dd636f51d77f473b0e1f46cb2144da722d
parent50a5a3075d27729ecc4ab53e1c43b7b33b88d2a7 (diff)
downloadrspamd-c3b8ab4425a166cfc9fb85068532fc9eeb66a68d.tar.gz
rspamd-c3b8ab4425a166cfc9fb85068532fc9eeb66a68d.zip
Add GTUBE support.
-rw-r--r--src/libmime/message.c61
-rw-r--r--src/libserver/task.h1
2 files changed, 62 insertions, 0 deletions
diff --git a/src/libmime/message.c b/src/libmime/message.c
index 4ca463422..7fbb46e58 100644
--- a/src/libmime/message.c
+++ b/src/libmime/message.c
@@ -32,15 +32,21 @@
#include "utlist.h"
#include "tokenizers/tokenizers.h"
#include "libstemmer.h"
+#include "acism.h"
#include <iconv.h>
#define RECURSION_LIMIT 5
#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)
{
@@ -1247,6 +1253,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,
@@ -1350,6 +1394,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 7506b25c1..25694be9a 100644
--- a/src/libserver/task.h
+++ b/src/libserver/task.h
@@ -88,6 +88,7 @@ enum rspamd_task_stage {
#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))