before parsing the values, remove whitespace from Content-Type, Content-Transfer...
[claws.git] / src / procmime.c
index f33eff8aae113f484234d4ea3445a34f5039e8fc..ca8bcc13e973fa27d330e2bf56d361fb1f17c14c 100644 (file)
@@ -326,7 +326,7 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
                                : mimeinfo->encoding_type;
        gchar lastline[BUFFSIZE];
        memset(lastline, 0, BUFFSIZE);
-                  
+
        cm_return_val_if_fail(mimeinfo != NULL, FALSE);
 
        if (prefs_common.respect_flowed_format &&
@@ -349,6 +349,9 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
            ))
                return TRUE;
 
+       if (mimeinfo->type == MIMETYPE_MULTIPART || mimeinfo->type == MIMETYPE_MESSAGE)
+               return TRUE;
+
        infp = procmime_fopen(mimeinfo->data.filename, "rb");
        if (!infp) {
                perror("fopen");
@@ -768,6 +771,8 @@ gboolean procmime_scan_text_content(MimeInfo *mimeinfo,
                src_codeset = CS_GB18030;
        else if (!forced_charset && src_codeset && !strcasecmp(src_codeset, CS_GB2312))
                src_codeset = CS_GB18030;
+       else if (!forced_charset && src_codeset && !strcasecmp(src_codeset, CS_X_VIET_VPS))
+               src_codeset = CS_WINDOWS_874;
 
        if (mimeinfo->type == MIMETYPE_TEXT && !g_ascii_strcasecmp(mimeinfo->subtype, "html")) {
                SC_HTMLParser *parser;
@@ -804,7 +809,7 @@ gboolean procmime_scan_text_content(MimeInfo *mimeinfo,
                                g_free(str);
                        } else {
                                conv_fail = TRUE;
-                               if ((scan_ret = scan_callback(str, cb_data)) == TRUE)
+                               if ((scan_ret = scan_callback(buf, cb_data)) == TRUE)
                                        break;
                        }
                }
@@ -1145,12 +1150,11 @@ static GHashTable *procmime_get_mime_type_table(void)
 
                exts = g_strsplit(mime_type->extension, " ", 16);
                for (i = 0; exts[i] != NULL; i++) {
-                       /* use previously dup'd key on overwriting */
-                       if (g_hash_table_lookup(table, exts[i]))
-                               key = exts[i];
-                       else
+                       /* Don't overwrite previously inserted extension */
+                       if (!g_hash_table_lookup(table, exts[i])) {
                                key = g_strdup(exts[i]);
-                       g_hash_table_insert(table, key, mime_type);
+                               g_hash_table_insert(table, key, mime_type);
+                       }
                }
                g_strfreev(exts);
        }
@@ -1822,8 +1826,7 @@ static void parse_parameters(const gchar *parameters, GHashTable *table)
                g_hash_table_insert(table, g_strdup(attribute), g_strdup(value->str));
                g_string_free(value, TRUE);
        }
-       slist_free_strings(concatlist);
-       g_slist_free(concatlist);
+       slist_free_strings_full(concatlist);
 
        for (cur = convlist; cur != NULL; cur = g_slist_next(cur)) {
                gchar *attribute, *key, *value;
@@ -1835,6 +1838,8 @@ static void parse_parameters(const gchar *parameters, GHashTable *table)
                        continue;
 
                charset = value;
+               if (charset == NULL)
+                       continue;
                lang = strchr(charset, '\'');
                if (lang == NULL)
                        continue;
@@ -1854,8 +1859,7 @@ static void parse_parameters(const gchar *parameters, GHashTable *table)
 
                g_hash_table_insert(table, g_strdup(attribute), newvalue);
        }
-       slist_free_strings(convlist);
-       g_slist_free(convlist);
+       slist_free_strings_full(convlist);
 
        g_free(params);
 }      
@@ -2011,6 +2015,7 @@ static int procmime_parse_mimepart(MimeInfo *parent,
        mimeinfo->length = length;
 
        if (content_type != NULL) {
+               remove_space(content_type);
                procmime_parse_content_type(content_type, mimeinfo);
        } else {
                mimeinfo->type = MIMETYPE_TEXT;
@@ -2025,6 +2030,7 @@ static int procmime_parse_mimepart(MimeInfo *parent,
        }
 
        if (content_encoding != NULL) {
+               remove_space(content_encoding);
                procmime_parse_content_encoding(content_encoding, mimeinfo);
        } else {
                mimeinfo->encoding_type = ENC_UNKNOWN;
@@ -2046,6 +2052,7 @@ static int procmime_parse_mimepart(MimeInfo *parent,
                mimeinfo->location = NULL;
 
        if (content_disposition != NULL) 
+               remove_space(content_disposition);
                procmime_parse_content_disposition(content_disposition, mimeinfo);
        else
                mimeinfo->disposition = DISPOSITIONTYPE_UNKNOWN;
@@ -2459,7 +2466,7 @@ static gint procmime_write_message_rfc822(MimeInfo *mimeinfo, FILE *fp)
                                break;
                        if (skip && (buf[0] == ' ' || buf[0] == '\t'))
                                continue;
-                       if (g_ascii_strncasecmp(buf, "Mime-Version:", 13) == 0 ||
+                       if (g_ascii_strncasecmp(buf, "MIME-Version:", 13) == 0 ||
                            g_ascii_strncasecmp(buf, "Content-Type:", 13) == 0 ||
                            g_ascii_strncasecmp(buf, "Content-Transfer-Encoding:", 26) == 0 ||
                            g_ascii_strncasecmp(buf, "Content-Description:", 20) == 0 ||
@@ -2497,7 +2504,7 @@ static gint procmime_write_message_rfc822(MimeInfo *mimeinfo, FILE *fp)
                return -1;
 
        child = (MimeInfo *) childnode->data;
-       if (fprintf(fp, "Mime-Version: 1.0\n") < 0) {
+       if (fprintf(fp, "MIME-Version: 1.0\n") < 0) {
                g_warning("failed to write mime version");
                return -1;
        }