]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Use HTTP Content-Type on non mime input if possible
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 26 Mar 2016 21:07:52 +0000 (21:07 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 26 Mar 2016 21:07:52 +0000 (21:07 +0000)
src/libmime/message.c

index a843f3836631dfc7811cf7d9018ffca484e07052..9c50750d945cc345a4dc6ed7b81ab938e43969d8 100644 (file)
@@ -1481,6 +1481,7 @@ rspamd_message_from_data (struct rspamd_task *task, GByteArray *data,
        GMimeContentType *ct = NULL;
        const char *mb = NULL;
        gchar *mid;
+       rspamd_ftok_t srch, *tok;
 
        g_assert (data != NULL);
 
@@ -1491,7 +1492,20 @@ rspamd_message_from_data (struct rspamd_task *task, GByteArray *data,
                                rspamd_task_get_sender (task));
        }
 
-       if (task->cfg->libs_ctx) {
+       srch.begin = "Content-Type";
+       srch.len = sizeof ("Content-Type") - 1;
+       tok = g_hash_table_lookup (task->request_headers, &srch);
+
+       if (tok) {
+               /* We have Content-Type defined */
+               gchar *ct_cpy = g_malloc (tok->len + 1);
+
+               rspamd_strlcpy (ct_cpy, tok->begin, tok->len + 1);
+               ct = g_mime_content_type_new_from_string (ct_cpy);
+               g_free (ct_cpy);
+       }
+       else if (task->cfg->libs_ctx) {
+               /* Try to predict it by content (slow) */
                mb = magic_buffer (task->cfg->libs_ctx->libmagic,
                                data->data,
                                data->len);