]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Allow to process filenames from content type
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 29 Mar 2017 15:57:46 +0000 (16:57 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 29 Mar 2017 16:02:39 +0000 (17:02 +0100)
src/libmime/content_type.h
src/libmime/mime_parser.c

index 57fe0e6a3925ae6817924a3dbd18cd6f70aca0a8..9d5393e0996fc257857fc75365335291fd653217 100644 (file)
@@ -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 */
 };
index f36b4848baf89cfb834e3a02ae5d05cea9d378e5..e994dc7959ce584c523cbda9c6f4e26590b7aedf 100644 (file)
@@ -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 ++) {