]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Core: Improve raw files scan
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 5 Jan 2019 14:50:01 +0000 (14:50 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 5 Jan 2019 14:50:01 +0000 (14:50 +0000)
src/libmime/message.c
src/libmime/mime_parser.c
src/libmime/mime_parser.h

index b75eb6b680502793e8526ca0ec20e4115b99a660..a15485339799352928b48030d25edc4502f6025d 100644 (file)
@@ -712,7 +712,8 @@ rspamd_message_process_text_part_maybe (struct rspamd_task *task,
        gboolean found_html = FALSE, found_txt = FALSE;
        enum rspamd_action_type act;
 
-       if (IS_CT_TEXT (mime_part->ct)) {
+       if (IS_CT_TEXT (mime_part->ct) && (!mime_part->detected_ct ||
+                                                                          IS_CT_TEXT (mime_part->detected_ct))) {
                html_tok.begin = "html";
                html_tok.len = 4;
                xhtml_tok.begin = "xhtml";
@@ -899,6 +900,7 @@ rspamd_message_from_data (struct rspamd_task *task, const guchar *start,
        const char *mb = NULL;
        gchar *mid;
        rspamd_ftok_t srch, *tok;
+       gchar cdbuf[1024];
 
        g_assert (start != NULL);
 
@@ -923,11 +925,26 @@ rspamd_message_from_data (struct rspamd_task *task, const guchar *start,
                        srch.len = strlen (mb);
                        ct = rspamd_content_type_parse (srch.begin, srch.len,
                                        task->task_pool);
-                       msg_warn_task ("construct fake mime of type: %s", mb);
 
                        if (!part->ct) {
+                               msg_info_task ("construct fake mime of type: %s", mb);
                                part->ct = ct;
                        }
+                       else {
+                               /* Check sanity */
+                               if (IS_CT_TEXT (part->ct)) {
+                                       RSPAMD_FTOK_FROM_STR (&srch, "application");
+
+                                       if (rspamd_ftok_cmp (&ct->type, &srch) == 0) {
+                                               msg_info_task ("construct fake mime of type: %s", mb);
+                                               part->ct = ct;
+                                       }
+                               }
+                               else {
+                                       msg_info_task ("construct fake mime of type: %T/%T, detected %s",
+                                                       &part->ct->type, &part->ct->subtype, mb);
+                               }
+                       }
 
                        part->detected_ct = ct;
                }
@@ -937,6 +954,27 @@ rspamd_message_from_data (struct rspamd_task *task, const guchar *start,
        part->raw_data.len = len;
        part->parsed_data.begin = start;
        part->parsed_data.len = len;
+       part->id = task->parts->len;
+       part->raw_headers =  g_hash_table_new_full (rspamd_strcase_hash,
+                       rspamd_strcase_equal, NULL, rspamd_ptr_array_free_hard);
+       part->headers_order = g_queue_new ();
+
+
+
+       tok = rspamd_task_get_request_header (task, "Filename");
+
+       if (tok) {
+               rspamd_snprintf (cdbuf, sizeof (cdbuf), "inline; filename=\"%T\"", tok);
+       }
+       else {
+               rspamd_snprintf (cdbuf, sizeof (cdbuf), "inline");
+       }
+
+       part->cd = rspamd_content_disposition_parse (cdbuf, strlen (cdbuf),
+                       task->task_pool);
+
+       g_ptr_array_add (task->parts, part);
+       rspamd_mime_parser_calc_digest (part);
 
        /* Generate message ID */
        mid = rspamd_mime_message_id_generate ("localhost.localdomain");
@@ -1041,7 +1079,6 @@ rspamd_message_parse (struct rspamd_task *task)
                }
        }
        else {
-               task->flags &= ~RSPAMD_TASK_FLAG_MIME;
                rspamd_message_from_data (task, p, len);
        }
 
index 242c656f097df82878af52d4dd5ccef6c87b674e..1dc3d85d89c6147f4f216648ba9d961f039a75d6 100644 (file)
@@ -405,7 +405,7 @@ rspamd_mime_part_get_cd (struct rspamd_task *task, struct rspamd_mime_part *part
        part->cd = cd;
 }
 
-static void
+void
 rspamd_mime_parser_calc_digest (struct rspamd_mime_part *part)
 {
        /* Blake2b applied to string 'rspamd' */
index c0b7dec7e9ed63a1e63f87106e290c68a4b1f67b..5164ea4d54726055baa2d23a298e5843f30d90ba 100644 (file)
@@ -19,6 +19,7 @@
 #include "config.h"
 
 struct rspamd_task;
+struct rspamd_mime_part;
 
 enum rspamd_mime_parse_error {
        RSPAMD_MIME_PARSE_OK = 0,
@@ -29,4 +30,6 @@ enum rspamd_mime_parse_error {
 enum rspamd_mime_parse_error rspamd_mime_parse_task (struct rspamd_task *task,
                GError **err);
 
+void rspamd_mime_parser_calc_digest (struct rspamd_mime_part *part);
+
 #endif /* SRC_LIBMIME_MIME_PARSER_H_ */