diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-08-02 18:36:31 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-08-02 18:36:31 +0100 |
commit | 2e5b95fddd7ee32bc023bbe64d26901e45b9bdac (patch) | |
tree | 76a400bf584b7dbf60be6ce7fbdd4b5eb6723e33 /src/libmime/mime_parser.c | |
parent | 64c4be01551d970c281c0e79c54ea16b972348d7 (diff) | |
download | rspamd-2e5b95fddd7ee32bc023bbe64d26901e45b9bdac.tar.gz rspamd-2e5b95fddd7ee32bc023bbe64d26901e45b9bdac.zip |
[Fix] Fix processing of multipart parts with no headers
Issue: #1783
Closes: #1783
Diffstat (limited to 'src/libmime/mime_parser.c')
-rw-r--r-- | src/libmime/mime_parser.c | 47 |
1 files changed, 29 insertions, 18 deletions
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; |