static const guint8 gif_signature[] = {'G', 'I', 'F', '8'};
static const guint8 bmp_signature[] = {'B', 'M'};
-static void process_image (struct rspamd_task *task, struct mime_part *part);
+static void process_image (struct rspamd_task *task, struct rspamd_mime_part *part);
void
rspamd_images_process (struct rspamd_task *task)
{
guint i;
- struct mime_part *part;
+ struct rspamd_mime_part *part;
for (i = 0; i < task->parts->len; i ++) {
part = g_ptr_array_index (task->parts, i);
}
static void
-process_image (struct rspamd_task *task, struct mime_part *part)
+process_image (struct rspamd_task *task, struct rspamd_mime_part *part)
{
enum rspamd_image_type type;
struct rspamd_image *img = NULL;
struct raw_header *rh;
- struct mime_text_part *tp;
+ struct rspamd_mime_text_part *tp;
struct html_image *himg;
const gchar *cid, *html_cid;
guint cid_len, i, j;
#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)
+#define SET_PART_RAW(part) ((part)->flags &= ~RSPAMD_MIME_TEXT_PART_FLAG_UTF)
+#define SET_PART_UTF(part) ((part)->flags |= RSPAMD_MIME_TEXT_PART_FLAG_UTF)
static const gchar gtube_pattern[] = "XJS*C4JDBQADN1.NSBN3*2IDNEN*"
"GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X";
convert_text_to_utf (struct rspamd_task *task,
GByteArray * part_content,
GMimeContentType * type,
- struct mime_text_part *text_part)
+ struct rspamd_mime_text_part *text_part)
{
GError *err = NULL;
gsize write_bytes;
}
static void
-detect_text_language (struct mime_text_part *part)
+detect_text_language (struct rspamd_mime_text_part *part)
{
/* Keep sorted */
static const struct language_match language_codes[] = {
static void
rspamd_normalize_text_part (struct rspamd_task *task,
- struct mime_text_part *part)
+ struct rspamd_mime_text_part *part)
{
#ifdef WITH_SNOWBALL
struct sb_stemmer *stem = NULL;
}
static gboolean
-rspamd_check_gtube (struct rspamd_task *task, struct mime_text_part *part)
+rspamd_check_gtube (struct rspamd_task *task, struct rspamd_mime_text_part *part)
{
static const gsize max_check_size = 4 * 1024;
g_assert (part != NULL);
process_text_part (struct rspamd_task *task,
GByteArray *part_content,
GMimeContentType *type,
- struct mime_part *mime_part,
+ struct rspamd_mime_part *mime_part,
GMimeObject *parent,
gboolean is_empty)
{
- struct mime_text_part *text_part;
+ struct rspamd_mime_text_part *text_part;
const gchar *cd;
/* Skip attachments */
#ifndef GMIME24
- cd = g_mime_part_get_content_disposition (GMIME_PART (mime_part->mime));
+ cd = g_mime_part_get_content_disposition (GMIME_PART (rspamd_mime_part->mime));
if (cd &&
g_ascii_strcasecmp (cd,
"attachment") == 0 && (task->cfg && !task->cfg->check_text_attachements)) {
text_part =
rspamd_mempool_alloc0 (task->task_pool,
- sizeof (struct mime_text_part));
- text_part->flags |= RSPAMD_MIME_PART_FLAG_HTML;
+ sizeof (struct rspamd_mime_text_part));
+ text_part->flags |= RSPAMD_MIME_TEXT_PART_FLAG_HTML;
if (is_empty) {
- text_part->flags |= RSPAMD_MIME_PART_FLAG_EMPTY;
+ text_part->flags |= RSPAMD_MIME_TEXT_PART_FLAG_EMPTY;
text_part->orig = NULL;
text_part->content = NULL;
g_ptr_array_add (task->text_parts, text_part);
text_part->parent = parent;
text_part->mime_part = mime_part;
- text_part->flags |= RSPAMD_MIME_PART_FLAG_BALANCED;
+ text_part->flags |= RSPAMD_MIME_TEXT_PART_FLAG_BALANCED;
text_part->content = rspamd_html_process_part_full (
task->task_pool,
text_part->html,
task->emails);
if (text_part->content->len == 0) {
- text_part->flags |= RSPAMD_MIME_PART_FLAG_EMPTY;
+ text_part->flags |= RSPAMD_MIME_TEXT_PART_FLAG_EMPTY;
}
/* Handle offsets of this part */
text_part =
rspamd_mempool_alloc0 (task->task_pool,
- sizeof (struct mime_text_part));
+ sizeof (struct rspamd_mime_text_part));
text_part->parent = parent;
text_part->mime_part = mime_part;
if (is_empty) {
- text_part->flags |= RSPAMD_MIME_PART_FLAG_EMPTY;
+ text_part->flags |= RSPAMD_MIME_TEXT_PART_FLAG_EMPTY;
text_part->orig = NULL;
text_part->content = NULL;
g_ptr_array_add (task->text_parts, text_part);
{
struct mime_foreach_data *md = user_data;
struct rspamd_task *task;
- struct mime_part *mime_part;
+ struct rspamd_mime_part *mime_part;
GMimeContentType *type;
GMimeDataWrapper *wrapper;
GMimeStream *part_stream;
type = (GMimeContentType *) g_mime_object_get_content_type (GMIME_OBJECT (
part));
mime_part = rspamd_mempool_alloc0 (task->task_pool,
- sizeof (struct mime_part));
+ sizeof (struct rspamd_mime_part));
hdrs = g_mime_object_get_headers (GMIME_OBJECT (part));
mime_part->raw_headers = g_hash_table_new (rspamd_strcase_hash,
g_object_unref (part_stream);
mime_part =
rspamd_mempool_alloc0 (task->task_pool,
- sizeof (struct mime_part));
+ sizeof (struct rspamd_mime_part));
hdrs = g_mime_object_get_headers (GMIME_OBJECT (part));
mime_part->raw_headers = g_hash_table_new (rspamd_strcase_hash,
GMimeObject *parent;
const GMimeContentType *ct;
struct raw_header *rh;
- struct mime_text_part *p1, *p2;
+ struct rspamd_mime_text_part *p1, *p2;
struct mime_foreach_data md;
struct received_header *recv, *trecv;
const gchar *p;
GPtrArray *ret;
struct raw_header *rh, *cur;
guint nelems = 0, i;
- struct mime_part *mp;
+ struct rspamd_mime_part *mp;
for (i = 0; i < task->parts->len; i ++) {
mp = g_ptr_array_index (task->parts, i);
struct controller_session;
struct html_content;
-struct mime_part {
+enum rspamd_mime_part_flags {
+ RSPAMD_MIME_PART_TEXT = (1 << 0),
+ RSPAMD_MIME_PART_ATTACHEMENT = (1 << 1),
+ RSPAMD_MIME_PART_IMAGE = (1 << 2),
+ RSPAMD_MIME_PART_ARCHIVE = (1 << 3)
+};
+
+struct rspamd_mime_part {
GMimeContentType *type;
GByteArray *content;
GMimeObject *parent;
gchar *checksum;
const gchar *filename;
const gchar *boundary;
+ enum rspamd_mime_part_flags flags;
+ gpointer specific_data;
};
-#define RSPAMD_MIME_PART_FLAG_UTF (1 << 0)
-#define RSPAMD_MIME_PART_FLAG_BALANCED (1 << 1)
-#define RSPAMD_MIME_PART_FLAG_EMPTY (1 << 2)
-#define RSPAMD_MIME_PART_FLAG_HTML (1 << 3)
+#define RSPAMD_MIME_TEXT_PART_FLAG_UTF (1 << 0)
+#define RSPAMD_MIME_TEXT_PART_FLAG_BALANCED (1 << 1)
+#define RSPAMD_MIME_TEXT_PART_FLAG_EMPTY (1 << 2)
+#define RSPAMD_MIME_TEXT_PART_FLAG_HTML (1 << 3)
-#define IS_PART_EMPTY(part) ((part)->flags & RSPAMD_MIME_PART_FLAG_EMPTY)
-#define IS_PART_UTF(part) ((part)->flags & RSPAMD_MIME_PART_FLAG_UTF)
-#define IS_PART_RAW(part) (!((part)->flags & RSPAMD_MIME_PART_FLAG_UTF))
-#define IS_PART_HTML(part) ((part)->flags & RSPAMD_MIME_PART_FLAG_HTML)
+#define IS_PART_EMPTY(part) ((part)->flags & RSPAMD_MIME_TEXT_PART_FLAG_EMPTY)
+#define IS_PART_UTF(part) ((part)->flags & RSPAMD_MIME_TEXT_PART_FLAG_UTF)
+#define IS_PART_RAW(part) (!((part)->flags & RSPAMD_MIME_TEXT_PART_FLAG_UTF))
+#define IS_PART_HTML(part) ((part)->flags & RSPAMD_MIME_TEXT_PART_FLAG_HTML)
-struct mime_text_part {
+struct rspamd_mime_text_part {
guint flags;
GUnicodeScript script;
const gchar *lang_code;
struct html_content *html;
GList *urls_offset; /**< list of offsets of urls */
GMimeObject *parent;
- struct mime_part *mime_part;
+ struct rspamd_mime_part *mime_part;
GArray *normalized_words;
GArray *normalized_hashes;
guint nlines;
rspamd_has_only_html_part (struct rspamd_task * task, GArray * args,
void *unused)
{
- struct mime_text_part *p;
+ struct rspamd_mime_text_part *p;
gboolean res = FALSE;
if (task->text_parts->len == 1) {
gboolean
rspamd_is_html_balanced (struct rspamd_task * task, GArray * args, void *unused)
{
- struct mime_text_part *p;
+ struct rspamd_mime_text_part *p;
guint i;
gboolean res = TRUE;
p = g_ptr_array_index (task->text_parts, i);
if (!IS_PART_EMPTY (p) && IS_PART_HTML (p)) {
- if (p->flags & RSPAMD_MIME_PART_FLAG_BALANCED) {
+ if (p->flags & RSPAMD_MIME_TEXT_PART_FLAG_BALANCED) {
res = TRUE;
}
else {
gboolean
rspamd_has_html_tag (struct rspamd_task * task, GArray * args, void *unused)
{
- struct mime_text_part *p;
+ struct rspamd_mime_text_part *p;
struct expression_argument *arg;
guint i;
gboolean res = FALSE;
gboolean
rspamd_has_fake_html (struct rspamd_task * task, GArray * args, void *unused)
{
- struct mime_text_part *p;
+ struct rspamd_mime_text_part *p;
guint i;
gboolean res = FALSE;
gint r;
guint i;
gboolean recursive = FALSE;
- struct mime_part *cur_part;
+ struct rspamd_mime_part *cur_part;
if (args == NULL || args->len < 2) {
msg_warn_task ("no parameters to function");
GMimeContentType *ct;
gboolean recursive = FALSE, result = FALSE;
guint i;
- struct mime_part *cur_part;
+ struct rspamd_mime_part *cur_part;
if (args == NULL || args->len < 1) {
msg_warn_task ("no parameters to function");
gint r;
guint i;
gboolean recursive = FALSE;
- struct mime_part *cur_part;
+ struct rspamd_mime_part *cur_part;
if (args == NULL || args->len < 1) {
msg_warn_task ("no parameters to function");
}
static gboolean
-compare_len (struct mime_part *part, guint min, guint max)
+compare_len (struct rspamd_mime_part *part, guint min, guint max)
{
if (min == 0 && max == 0) {
return TRUE;
gint max_len)
{
rspamd_regexp_t *re;
- struct mime_part *part;
+ struct rspamd_mime_part *part;
GMimeContentType *ct;
gint r;
guint i;
const guchar **scvec;
guint *lenvec;
gboolean raw = FALSE;
- struct mime_text_part *part;
+ struct rspamd_mime_text_part *part;
struct rspamd_url *url;
struct rspamd_re_cache *cache = rt->cache;
gpointer k, v;
void
rspamd_task_free (struct rspamd_task *task)
{
- struct mime_part *p;
- struct mime_text_part *tp;
+ struct rspamd_mime_part *p;
+ struct rspamd_mime_text_part *tp;
struct rspamd_email_address *addr;
guint i;
struct rspamd_url_mimepart_cbdata {
struct rspamd_task *task;
- struct mime_text_part *part;
+ struct rspamd_mime_text_part *part;
};
static void
void
rspamd_url_text_extract (rspamd_mempool_t *pool,
struct rspamd_task *task,
- struct mime_text_part *part,
+ struct rspamd_mime_text_part *part,
gboolean is_html)
{
struct rspamd_url_mimepart_cbdata mcbd;
#include "fstring.h"
struct rspamd_task;
-struct mime_text_part;
+struct rspamd_mime_text_part;
enum rspamd_url_flags {
RSPAMD_URL_FLAG_PHISHED = 1 << 0,
*/
void rspamd_url_text_extract (rspamd_mempool_t *pool,
struct rspamd_task *task,
- struct mime_text_part *part,
+ struct rspamd_mime_text_part *part,
gboolean is_html);
/*
gint rc, err_idx;
guint i;
const gchar *language = NULL;
- struct mime_text_part *tp;
+ struct rspamd_mime_text_part *tp;
struct rspamd_task **ptask;
lua_State *L = db->L;
GString *tb;
struct rspamd_task *task)
{
struct rspamd_image *img;
- struct mime_part *part;
- struct mime_text_part *tp;
+ struct rspamd_mime_part *part;
+ struct rspamd_mime_text_part *tp;
GList *cur;
GArray *ar;
rspamd_ftok_t elt;
rspamd_stat_process_tokenize (struct rspamd_stat_ctx *st_ctx,
struct rspamd_task *task)
{
- struct mime_text_part *part;
+ struct rspamd_mime_text_part *part;
GArray *words;
gchar *sub;
guint i, reserved_len = 0;
free_lmtp_task (struct rspamd_lmtp_proto *lmtp, gboolean is_soft)
{
GList *part;
- struct mime_part *p;
+ struct rspamd_mime_part *p;
struct rspamd_task *task = lmtp->task;
if (lmtp) {
debug_task ("free pointer %p", lmtp->task);
while ((part = g_list_first (lmtp->task->parts))) {
lmtp->task->parts = g_list_remove_link (lmtp->task->parts, part);
- p = (struct mime_part *)part->data;
+ p = (struct rspamd_mime_part *)part->data;
g_byte_array_free (p->content, FALSE);
g_list_free_1 (part);
}
};
-static struct mime_text_part *
+static struct rspamd_mime_text_part *
lua_check_textpart (lua_State * L)
{
void *ud = rspamd_lua_check_udata (L, 1, "rspamd{textpart}");
luaL_argcheck (L, ud != NULL, 1, "'textpart' expected");
- return ud ? *((struct mime_text_part **)ud) : NULL;
+ return ud ? *((struct rspamd_mime_text_part **)ud) : NULL;
}
-static struct mime_part *
+static struct rspamd_mime_part *
lua_check_mimepart (lua_State * L)
{
void *ud = rspamd_lua_check_udata (L, 1, "rspamd{mimepart}");
luaL_argcheck (L, ud != NULL, 1, "'mimepart' expected");
- return ud ? *((struct mime_part **)ud) : NULL;
+ return ud ? *((struct rspamd_mime_part **)ud) : NULL;
}
static gint
lua_textpart_is_utf (lua_State * L)
{
- struct mime_text_part *part = lua_check_textpart (L);
+ struct rspamd_mime_text_part *part = lua_check_textpart (L);
if (part == NULL || IS_PART_EMPTY (part)) {
lua_pushboolean (L, FALSE);
static gint
lua_textpart_get_content (lua_State * L)
{
- struct mime_text_part *part = lua_check_textpart (L);
+ struct rspamd_mime_text_part *part = lua_check_textpart (L);
struct rspamd_lua_text *t;
if (part == NULL || IS_PART_EMPTY (part)) {
static gint
lua_textpart_get_length (lua_State * L)
{
- struct mime_text_part *part = lua_check_textpart (L);
+ struct rspamd_mime_text_part *part = lua_check_textpart (L);
if (part == NULL) {
lua_pushnil (L);
static gint
lua_textpart_get_raw_length (lua_State * L)
{
- struct mime_text_part *part = lua_check_textpart (L);
+ struct rspamd_mime_text_part *part = lua_check_textpart (L);
if (part == NULL) {
lua_pushnil (L);
static gint
lua_textpart_get_lines_count (lua_State * L)
{
- struct mime_text_part *part = lua_check_textpart (L);
+ struct rspamd_mime_text_part *part = lua_check_textpart (L);
if (part == NULL) {
lua_pushnil (L);
static gint
lua_textpart_get_words_count (lua_State *L)
{
- struct mime_text_part *part = lua_check_textpart (L);
+ struct rspamd_mime_text_part *part = lua_check_textpart (L);
if (part == NULL) {
lua_pushnil (L);
static gint
lua_textpart_is_empty (lua_State * L)
{
- struct mime_text_part *part = lua_check_textpart (L);
+ struct rspamd_mime_text_part *part = lua_check_textpart (L);
if (part == NULL) {
lua_pushnil (L);
static gint
lua_textpart_is_html (lua_State * L)
{
- struct mime_text_part *part = lua_check_textpart (L);
+ struct rspamd_mime_text_part *part = lua_check_textpart (L);
if (part == NULL) {
lua_pushnil (L);
static gint
lua_textpart_get_html (lua_State * L)
{
- struct mime_text_part *part = lua_check_textpart (L);
+ struct rspamd_mime_text_part *part = lua_check_textpart (L);
struct html_content **phc;
if (part == NULL || part->html == NULL) {
static gint
lua_textpart_get_language (lua_State * L)
{
- struct mime_text_part *part = lua_check_textpart (L);
+ struct rspamd_mime_text_part *part = lua_check_textpart (L);
if (part != NULL) {
if (part->lang_code != NULL && part->lang_code[0] != '\0') {
static gint
lua_textpart_get_mimepart (lua_State * L)
{
- struct mime_text_part *part = lua_check_textpart (L);
- struct mime_part **pmime;
+ struct rspamd_mime_text_part *part = lua_check_textpart (L);
+ struct rspamd_mime_part **pmime;
if (part != NULL) {
if (part->mime_part != NULL) {
- pmime = lua_newuserdata (L, sizeof (struct mime_part *));
+ pmime = lua_newuserdata (L, sizeof (struct rspamd_mime_part *));
rspamd_lua_setclass (L, "rspamd{mimepart}", -1);
*pmime = part->mime_part;
static gint
lua_mimepart_get_content (lua_State * L)
{
- struct mime_part *part = lua_check_mimepart (L);
+ struct rspamd_mime_part *part = lua_check_mimepart (L);
struct rspamd_lua_text *t;
if (part == NULL) {
static gint
lua_mimepart_get_length (lua_State * L)
{
- struct mime_part *part = lua_check_mimepart (L);
+ struct rspamd_mime_part *part = lua_check_mimepart (L);
if (part == NULL) {
lua_pushnil (L);
static gint
lua_mimepart_get_type (lua_State * L)
{
- struct mime_part *part = lua_check_mimepart (L);
+ struct rspamd_mime_part *part = lua_check_mimepart (L);
if (part == NULL) {
lua_pushnil (L);
static gint
lua_mimepart_get_filename (lua_State * L)
{
- struct mime_part *part = lua_check_mimepart (L);
+ struct rspamd_mime_part *part = lua_check_mimepart (L);
if (part == NULL || part->filename == NULL) {
lua_pushnil (L);
lua_mimepart_get_header_common (lua_State *L, gboolean full, gboolean raw)
{
gboolean strong = FALSE;
- struct mime_part *part = lua_check_mimepart (L);
+ struct rspamd_mime_part *part = lua_check_mimepart (L);
const gchar *name;
name = luaL_checkstring (L, 2);
{
guint i;
struct rspamd_task *task = lua_check_task (L, 1);
- struct mime_text_part *part, **ppart;
+ struct rspamd_mime_text_part *part, **ppart;
if (task != NULL) {
lua_newtable (L);
for (i = 0; i < task->text_parts->len; i ++) {
part = g_ptr_array_index (task->text_parts, i);
- ppart = lua_newuserdata (L, sizeof (struct mime_text_part *));
+ ppart = lua_newuserdata (L, sizeof (struct rspamd_mime_text_part *));
*ppart = part;
rspamd_lua_setclass (L, "rspamd{textpart}", -1);
/* Make it array */
{
guint i;
struct rspamd_task *task = lua_check_task (L, 1);
- struct mime_part *part, **ppart;
+ struct rspamd_mime_part *part, **ppart;
if (task != NULL) {
lua_newtable (L);
for (i = 0; i < task->parts->len; i ++) {
part = g_ptr_array_index (task->parts, i);
- ppart = lua_newuserdata (L, sizeof (struct mime_part *));
+ ppart = lua_newuserdata (L, sizeof (struct rspamd_mime_part *));
*ppart = part;
rspamd_lua_setclass (L, "rspamd{mimepart}", -1);
/* Make it array */
{
struct rspamd_multipattern *trie = lua_check_trie (L, 1);
struct rspamd_task *task = lua_check_task (L, 2);
- struct mime_text_part *part;
+ struct rspamd_mime_text_part *part;
const gchar *text;
gsize len, i;
gboolean found = FALSE;
}
static gboolean
-check_part (struct mime_text_part *part, gboolean raw_mode)
+check_part (struct rspamd_mime_text_part *part, gboolean raw_mode)
{
guchar *p, *p1;
gunichar c, t;
chartable_symbol_callback (struct rspamd_task *task, void *unused)
{
guint i;
- struct mime_text_part *part;
+ struct rspamd_mime_text_part *part;
for (i = 0; i < task->text_parts->len; i ++) {
part = g_ptr_array_index (task->text_parts, i);
}
static GArray *
-fuzzy_preprocess_words (struct mime_text_part *part, rspamd_mempool_t *pool)
+fuzzy_preprocess_words (struct rspamd_mime_text_part *part, rspamd_mempool_t *pool)
{
return part->normalized_words;
}
static void *
fuzzy_cmd_get_cached (struct fuzzy_rule *rule,
rspamd_mempool_t *pool,
- struct mime_text_part *part)
+ struct rspamd_mime_text_part *part)
{
gchar key[32];
gint key_part;
static void
fuzzy_cmd_set_cached (struct fuzzy_rule *rule,
rspamd_mempool_t *pool,
- struct mime_text_part *part,
+ struct rspamd_mime_text_part *part,
struct rspamd_fuzzy_encrypted_shingle_cmd *data)
{
gchar key[32];
gint flag,
guint32 weight,
rspamd_mempool_t *pool,
- struct mime_text_part *part)
+ struct rspamd_mime_text_part *part)
{
struct rspamd_fuzzy_shingle_cmd *shcmd;
struct rspamd_fuzzy_encrypted_shingle_cmd *encshcmd, *cached;
fuzzy_generate_commands (struct rspamd_task *task, struct fuzzy_rule *rule,
gint c, gint flag, guint32 value)
{
- struct mime_text_part *part;
- struct mime_part *mime_part;
+ struct rspamd_mime_text_part *part;
+ struct rspamd_mime_part *mime_part;
struct rspamd_image *image;
struct fuzzy_cmd_io *io;
guint i;
struct redirector_param param;
struct suffix_item *suffix = user_data;
guint i, j;
- struct mime_text_part *part;
+ struct rspamd_mime_text_part *part;
struct html_image *img;
struct rspamd_url *url;
struct tokenizer;
struct rspamd_stat_classifier;
struct rspamd_classifier_config;
-struct mime_part;
+struct rspamd_mime_part;
struct rspamd_dns_resolver;
struct rspamd_task;
struct rspamd_cryptobox_library_ctx;