Merge remote-tracking branch 'jakub-kicinski/for-master'
authorColin Leroy <colin@colino.net>
Thu, 18 Dec 2014 09:18:48 +0000 (10:18 +0100)
committerColin Leroy <colin@colino.net>
Thu, 18 Dec 2014 09:18:48 +0000 (10:18 +0100)
src/codeconv.c
src/compose.c
src/procmime.c

index 98981e135f92daf3a64e33703d135382e47b19bc..85dabf61f61962fbfad932390ad108e4ef14463d 100644 (file)
@@ -749,8 +749,17 @@ gchar *conv_codeset_strdup(const gchar *inbuf,
        size_t len;
        CodeConvFunc conv_func;
 
-       if (!strcmp2(src_code, dest_code))
+       if (!strcmp2(src_code, dest_code)) {
+               CharSet dest_charset = conv_get_charset_from_str(dest_code);
+               if (dest_charset == C_UTF_8) {
+                       /* ensure valid UTF-8 if target is UTF-8 */
+                       if (!g_utf8_validate(inbuf, -1, NULL)) {
+                               return NULL;
+                       }
+               }
+               /* otherwise, try for a lucky day */
                return g_strdup(inbuf);
+       }
 
        src_code = conv_get_fallback_for_private_encoding(src_code);
        conv_func = conv_get_code_conv_func(src_code, dest_code);
index 8f89975584ded9060cdd7e66fc242a81cd8ed24d..03dbf485edffdcb959e65de230a7c070ca7f245c 100644 (file)
@@ -3643,9 +3643,18 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
 
                if (g_utf8_validate(buf, -1, NULL) == TRUE)
                        str = g_strdup(buf);
-               else
+               else {
                        str = conv_codeset_strdup
                                (buf, cur_encoding, CS_INTERNAL);
+                       if (!str) {
+                               alertpanel_error(_("Unable to insert the file "
+                               "because converting to the internal encoding "
+                               "failed. This may be caused by a binary file "
+                               "or a wrongly encoded text file. If you are "
+                               "sure this is the right file then try "
+                               "attaching it instead."));
+                       }
+               }
                if (!str) continue;
 
                /* strip <CR> if DOS/Windows file,
index a4630261dea75726d1c5b416d823ca8342541c72..20401d86c52d16653f93f3456e9f0aa32b5f69cb 100644 (file)
@@ -819,7 +819,7 @@ gboolean procmime_scan_text_content(MimeInfo *mimeinfo,
                }
                ertf_parser_destroy(parser);
                conv_code_converter_destroy(conv);
-       } else if (mimeinfo->type == MIMETYPE_TEXT) {
+       } else if (mimeinfo->type == MIMETYPE_TEXT && mimeinfo->disposition != DISPOSITIONTYPE_ATTACHMENT) {
                while (SC_FGETS(buf, sizeof(buf), tmpfp) != NULL) {
                        str = conv_codeset_strdup(buf, src_codeset, CS_UTF_8);
                        if (str) {