From e415626203bec3746f7ce9d4d6681e3b938dd05d Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 14 Dec 2016 12:33:37 +0000 Subject: [Minor] More features to mime parser --- src/libmime/message.h | 2 ++ src/libmime/mime_parser.c | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/libmime/message.h b/src/libmime/message.h index 3dd32c4db..b6a1f998f 100644 --- a/src/libmime/message.h +++ b/src/libmime/message.h @@ -38,6 +38,8 @@ struct rspamd_mime_part { struct rspamd_content_type *ct; rspamd_ftok_t raw_data; rspamd_ftok_t parsed_data; + struct rspamd_mime_part *parent_part; + GPtrArray *children; enum rspamd_cte cte; GByteArray *content; GMimeObject *parent; diff --git a/src/libmime/mime_parser.c b/src/libmime/mime_parser.c index 27eedb644..782eca784 100644 --- a/src/libmime/mime_parser.c +++ b/src/libmime/mime_parser.c @@ -257,6 +257,7 @@ rspamd_mime_parse_normal_part (struct rspamd_task *task, g_assert_not_reached (); } + g_ptr_array_add (task->parts, part); msg_debug_mime ("parsed data part %T/%T of length %z (%z orig), %s cte", &part->ct->type, &part->ct->subtype, part->parsed_data.len, part->raw_data.len, rspamd_cte_to_string (part->cte)); @@ -294,9 +295,15 @@ rspamd_mime_process_multipart_node (struct rspamd_task *task, str.len = end - start; hdr_pos = rspamd_string_find_eoh (&str, &body_pos); + + if (multipart->children == NULL) { + multipart->children = g_ptr_array_sized_new (2); + } + npart = rspamd_mempool_alloc0 (task->task_pool, sizeof (struct rspamd_mime_part)); - npart->parent = multipart; + npart->parent_part = multipart; + g_ptr_array_add (multipart->children, npart); if (hdr_pos > 0 && hdr_pos < str.len) { @@ -492,6 +499,8 @@ rspamd_mime_parse_multipart_part (struct rspamd_task *task, return FALSE; } + g_ptr_array_add (task->parts, part); + cbdata.multipart = part; cbdata.task = task; cbdata.st = st; @@ -536,6 +545,10 @@ rspamd_mime_parse_message (struct rspamd_task *task, return FALSE; } + if (part) { + g_ptr_array_add (task->parts, part); + } + /* Parse headers */ if (st->cur_part == NULL) { p = task->msg.begin; @@ -676,7 +689,7 @@ rspamd_mime_parse_message (struct rspamd_task *task, sizeof (struct rspamd_mime_part)); npart->raw_data.begin = pbegin; npart->raw_data.len = plen; - npart->parent = part; + npart->parent_part = part; npart->ct = sel; if (st->cur_part == NULL) { -- cgit v1.2.3