From ac897cf7f407d3781f1bb54e9449746b2deac446 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 26 Mar 2016 21:07:52 +0000 Subject: [PATCH] [Feature] Use HTTP Content-Type on non mime input if possible --- src/libmime/message.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/libmime/message.c b/src/libmime/message.c index a843f3836..9c50750d9 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -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); -- 2.39.5