From 2e5b95fddd7ee32bc023bbe64d26901e45b9bdac Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 2 Aug 2017 18:36:31 +0100 Subject: [Fix] Fix processing of multipart parts with no headers Issue: #1783 Closes: #1783 --- src/libmime/mime_parser.c | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'src/libmime/mime_parser.c') diff --git a/src/libmime/mime_parser.c b/src/libmime/mime_parser.c index ea6110e8d..f1bb26862 100644 --- a/src/libmime/mime_parser.c +++ b/src/libmime/mime_parser.c @@ -544,7 +544,18 @@ rspamd_mime_process_multipart_node (struct rspamd_task *task, str.str = (gchar *)start; str.len = end - start; - hdr_pos = rspamd_string_find_eoh (&str, &body_pos); + if (*start == '\n' || *start == '\r') { + /* + * We have a part that starts from newline which means that + * there are completely no headers in this part, + * hence we assume it as a text part + */ + hdr_pos = 0; + body_pos = 0; + } + else { + hdr_pos = rspamd_string_find_eoh (&str, &body_pos); + } if (multipart->specific.mp.children == NULL) { multipart->specific.mp.children = g_ptr_array_sized_new (2); @@ -559,22 +570,22 @@ rspamd_mime_process_multipart_node (struct rspamd_task *task, g_ptr_array_add (multipart->specific.mp.children, npart); if (hdr_pos > 0 && hdr_pos < str.len) { - npart->raw_headers_str = str.str; - npart->raw_headers_len = hdr_pos; - npart->raw_data.begin = start + body_pos; - npart->raw_data.len = (end - start) - body_pos; - - if (task->raw_headers_content.len > 0) { - rspamd_mime_headers_process (task, npart->raw_headers, - npart->headers_order, - npart->raw_headers_str, - npart->raw_headers_len, - FALSE); - } + npart->raw_headers_str = str.str; + npart->raw_headers_len = hdr_pos; + npart->raw_data.begin = start + body_pos; + npart->raw_data.len = (end - start) - body_pos; + + if (npart->raw_headers_len > 0) { + rspamd_mime_headers_process (task, npart->raw_headers, + npart->headers_order, + npart->raw_headers_str, + npart->raw_headers_len, + FALSE); + } - hdrs = rspamd_message_get_header_from_hash (npart->raw_headers, - task->task_pool, - "Content-Type", FALSE); + hdrs = rspamd_message_get_header_from_hash (npart->raw_headers, + task->task_pool, + "Content-Type", FALSE); } else { @@ -606,8 +617,8 @@ rspamd_mime_process_multipart_node (struct rspamd_task *task, if (sel == NULL) { sel = rspamd_mempool_alloc0 (task->task_pool, sizeof (*sel)); - RSPAMD_FTOK_ASSIGN (&sel->type, "application"); - RSPAMD_FTOK_ASSIGN (&sel->subtype, "octet-stream"); + RSPAMD_FTOK_ASSIGN (&sel->type, "text"); + RSPAMD_FTOK_ASSIGN (&sel->subtype, "plain"); } npart->ct = sel; -- cgit v1.2.3