]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Rework|Minor] More updates for mime parsing
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 16 Dec 2016 16:38:59 +0000 (16:38 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 16 Dec 2016 16:38:59 +0000 (16:38 +0000)
src/libmime/message.h
src/libmime/mime_parser.c
src/libserver/protocol.c
src/libserver/re_cache.c
src/libserver/task.c

index 66981ca9e78d7ffb2f2e3dfc02af7f317badec8a..c4f0e7a8eb37dffb30d335c4a185c92f9dc04293 100644 (file)
@@ -36,6 +36,10 @@ enum rspamd_cte {
 
 struct rspamd_mime_text_part;
 
+struct rspamd_mime_multipart {
+       GPtrArray *children;
+};
+
 struct rspamd_mime_part {
        struct rspamd_content_type *ct;
        struct rspamd_content_disposition *cd;
@@ -48,7 +52,7 @@ struct rspamd_mime_part {
        enum rspamd_cte cte;
 
        union {
-               struct rspamd_mime_multipart *mp;
+               struct rspamd_mime_multipart mp;
                struct rspamd_mime_text_part *txt;
                struct rspamd_image *img;
                struct rspamd_archive *arch;
@@ -58,10 +62,6 @@ struct rspamd_mime_part {
        guchar digest[rspamd_cryptobox_HASHBYTES];
 };
 
-struct rspamd_mime_multipart {
-       GPtrArray *children;
-};
-
 #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)
index 7586a803eb2d8105eec165b69111e1a6e4b9fc5d..0b192b8d5af992d339237c0169ac2727b1f45222 100644 (file)
@@ -341,8 +341,8 @@ rspamd_mime_process_multipart_node (struct rspamd_task *task,
 
        hdr_pos = rspamd_string_find_eoh (&str, &body_pos);
 
-       if (multipart->children == NULL) {
-               multipart->children = g_ptr_array_sized_new (2);
+       if (multipart->specific.mp.children == NULL) {
+               multipart->specific.mp.children = g_ptr_array_sized_new (2);
        }
 
        npart = rspamd_mempool_alloc0 (task->task_pool,
@@ -350,7 +350,7 @@ rspamd_mime_process_multipart_node (struct rspamd_task *task,
        npart->parent_part = multipart;
        npart->raw_headers =  g_hash_table_new_full (rspamd_strcase_hash,
                        rspamd_strcase_equal, NULL, rspamd_ptr_array_free_hard);
-       g_ptr_array_add (multipart->children, npart);
+       g_ptr_array_add (multipart->specific.mp.children, npart);
 
        if (hdr_pos > 0 && hdr_pos < str.len) {
                        npart->raw_headers_str = str.str;
index a1a1ae8fe9083b39cefe286aba366f17707a9c8a..cdc7f263ace0b78e58b8db4c75e848902ce1db9a 100644 (file)
@@ -778,7 +778,7 @@ make_rewritten_subject (struct rspamd_metric *metric, struct rspamd_task *task)
                c = SPAM_SUBJECT;
        }
 
-       s = g_mime_message_get_subject (task->message);
+       s = task->subject;
 
        while (p < end) {
                if (*c == '\0') {
@@ -794,6 +794,7 @@ make_rewritten_subject (struct rspamd_metric *metric, struct rspamd_task *task)
                }
                p++;
        }
+
        res = g_mime_utils_header_encode_text (subj_buf);
 
        rspamd_mempool_add_destructor (task->task_pool,
@@ -897,8 +898,11 @@ rspamd_metric_result_ucl (struct rspamd_task *task,
 
        if (action == METRIC_ACTION_REWRITE_SUBJECT) {
                subject = make_rewritten_subject (m, task);
-               ucl_object_insert_key (obj, ucl_object_fromstring (subject),
+
+               if (subject) {
+                       ucl_object_insert_key (obj, ucl_object_fromstring (subject),
                                "subject", 0, false);
+               }
        }
        /* Now handle symbols */
        g_hash_table_iter_init (&hiter, mres->symbols);
index 1e713dc86b3c256c5849be139d0843626a444391..e5298ff048a030dcd3282ea2fec447813ff2fe38 100644 (file)
@@ -884,8 +884,8 @@ rspamd_re_cache_exec_re (struct rspamd_task *task,
                                }
                                /* Select data for regexp */
                                if (re_class->type == RSPAMD_RE_RAWMIME) {
-                                       in = part->raw->data;
-                                       len = part->raw->len;
+                                       in = part->raw.begin;
+                                       len = part->raw.len;
                                        raw = TRUE;
                                }
                                else {
@@ -1022,9 +1022,9 @@ rspamd_re_cache_exec_re (struct rspamd_task *task,
                        for (i = 0; i < task->text_parts->len; i++) {
                                part = g_ptr_array_index (task->text_parts, i);
 
-                               if (part->orig) {
-                                       scvec[i] = (guchar *)part->orig->data;
-                                       lenvec[i] = part->orig->len;
+                               if (part->parsed.len > 0) {
+                                       scvec[i] = (guchar *)part->parsed.begin;
+                                       lenvec[i] = part->parsed.len;
                                }
                                else {
                                        scvec[i] = (guchar *)"";
index cee604acdb063ee257d02394912835321cc70f2e..656e177aa324ef3a2c497d5848add6053ca51757 100644 (file)
@@ -203,8 +203,11 @@ rspamd_task_free (struct rspamd_task *task)
                        if (p->raw_headers) {
                                g_hash_table_unref (p->raw_headers);
                        }
-                       if (p->children) {
-                               g_ptr_array_free (p->children, TRUE);
+
+                       if (IS_CT_MULTIPART (p->ct)) {
+                               if (p->specific.mp.children) {
+                                       g_ptr_array_free (p->specific.mp.children, TRUE);
+                               }
                        }
                }