From: Colin Leroy Date: Fri, 19 Dec 2014 15:23:00 +0000 (+0100) Subject: Better fix for bug #3349 (almost all the needed code was there :-) X-Git-Tag: 3.12.0~196 X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=commitdiff_plain;h=2fc36b1cd471c4b3e11e5099a85a42415395de01;hp=6dfa9e5718df60aea5a12b5a4ae28da28a29f54e Better fix for bug #3349 (almost all the needed code was there :-) --- diff --git a/src/codeconv.c b/src/codeconv.c index 85dabf61f..565c0c273 100644 --- a/src/codeconv.c +++ b/src/codeconv.c @@ -751,7 +751,7 @@ gchar *conv_codeset_strdup(const gchar *inbuf, if (!strcmp2(src_code, dest_code)) { CharSet dest_charset = conv_get_charset_from_str(dest_code); - if (dest_charset == C_UTF_8) { + if (strict_mode && dest_charset == C_UTF_8) { /* ensure valid UTF-8 if target is UTF-8 */ if (!g_utf8_validate(inbuf, -1, NULL)) { return NULL; diff --git a/src/compose.c b/src/compose.c index 03dbf485e..e9ecf08b9 100644 --- a/src/compose.c +++ b/src/compose.c @@ -3578,6 +3578,7 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi struct stat file_stat; int ret; GString *file_contents = NULL; + ComposeInsertResult result = COMPOSE_INSERT_SUCCESS; cm_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE); @@ -3644,15 +3645,14 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi if (g_utf8_validate(buf, -1, NULL) == TRUE) str = g_strdup(buf); else { + codeconv_set_strict(TRUE); str = conv_codeset_strdup (buf, cur_encoding, CS_INTERNAL); + codeconv_set_strict(FALSE); + 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.")); + result = COMPOSE_INSERT_INVALID_CHARACTER; + break; } } if (!str) continue; @@ -3670,20 +3670,22 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi g_free(str); } - gtk_text_buffer_insert(buffer, &iter, file_contents->str, -1); - g_string_free(file_contents, TRUE); + if (result == COMPOSE_INSERT_SUCCESS) { + gtk_text_buffer_insert(buffer, &iter, file_contents->str, -1); - compose_changed_cb(NULL, compose); - g_signal_handlers_unblock_by_func(G_OBJECT(buffer), - G_CALLBACK(text_inserted), - compose); - compose->autowrap = prev_autowrap; - if (compose->autowrap) - compose_wrap_all(compose); + compose_changed_cb(NULL, compose); + g_signal_handlers_unblock_by_func(G_OBJECT(buffer), + G_CALLBACK(text_inserted), + compose); + compose->autowrap = prev_autowrap; + if (compose->autowrap) + compose_wrap_all(compose); + } + g_string_free(file_contents, TRUE); fclose(fp); - return COMPOSE_INSERT_SUCCESS; + return result; } static gboolean compose_attach_append(Compose *compose, const gchar *file,