From: Vsevolod Stakhov Date: Wed, 29 Mar 2017 15:57:46 +0000 (+0100) Subject: [Feature] Allow to process filenames from content type X-Git-Tag: 1.5.5~85 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f92898a226c163e8084c3ffd9fff83ccdd66a802;p=rspamd.git [Feature] Allow to process filenames from content type --- diff --git a/src/libmime/content_type.h b/src/libmime/content_type.h index 57fe0e6a3..9d5393e09 100644 --- a/src/libmime/content_type.h +++ b/src/libmime/content_type.h @@ -50,13 +50,15 @@ struct rspamd_content_type { GHashTable *attrs; /* Can be empty */ }; +enum rspamd_contetn_disposition_type { + RSPAMD_CT_UNKNOWN = 0, + RSPAMD_CT_INLINE = 1, + RSPAMD_CT_ATTACHMENT = 2, +}; + struct rspamd_content_disposition { gchar *lc_data; - enum { - RSPAMD_CT_UNKNOWN = 0, - RSPAMD_CT_INLINE = 1, - RSPAMD_CT_ATTACHMENT = 2, - } type; + enum rspamd_contetn_disposition_type type; rspamd_ftok_t filename; GHashTable *attrs; /* Can be empty */ }; diff --git a/src/libmime/mime_parser.c b/src/libmime/mime_parser.c index f36b4848b..e994dc795 100644 --- a/src/libmime/mime_parser.c +++ b/src/libmime/mime_parser.c @@ -313,6 +313,7 @@ rspamd_mime_part_get_cd (struct rspamd_task *task, struct rspamd_mime_part *part guint i; GPtrArray *hdrs; struct rspamd_content_disposition *cd = NULL; + rspamd_ftok_t srch, *found; hdrs = rspamd_message_get_header_from_hash (part->raw_headers, task->task_pool, @@ -322,6 +323,23 @@ rspamd_mime_part_get_cd (struct rspamd_task *task, struct rspamd_mime_part *part if (hdrs == NULL) { cd = rspamd_mempool_alloc0 (task->task_pool, sizeof (*cd)); cd->type = RSPAMD_CT_INLINE; + + /* We can also have content dispositon definitions in Content-Type */ + if (part->ct) { + RSPAMD_FTOK_ASSIGN (&srch, "name"); + found = g_hash_table_lookup (part->ct->attrs, &srch); + + if (!found) { + RSPAMD_FTOK_ASSIGN (&srch, "filename"); + found = g_hash_table_lookup (part->ct->attrs, &srch); + } + + if (found) { + cd->type = RSPAMD_CT_ATTACHMENT; + memcpy (&cd->filename, found, sizeof (cd->filename)); + } + } + } else { for (i = 0; i < hdrs->len; i ++) {