aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2017-11-16 08:08:35 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2017-11-16 08:08:35 +0000
commitb59eb52101fecc88c07271d08e06bdb34c58f3ce (patch)
treea3358e858e4a949620ebf7c812f6527eab7d4661
parent7fb480447736bd7e7371c53e5def624724028240 (diff)
supported insertion of UTF-16 text on compose.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@3574 ee746299-78ed-0310-b773-934348b2243d
-rw-r--r--ChangeLog9
-rw-r--r--src/compose.c37
2 files changed, 41 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 58f4881b..0b14a1a8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,14 @@
2017-11-16
+ * src/compose.c: compose_insert_file(): supported insertion of
+ UTF-16/UTF-16BE/UTF-16LE text.
+
+2017-11-16
+
* libsylph/codeconv.[ch]: conv_check_file_encoding(): added detection
of UTF-16/UTF-16BE/UTF-16LE.
- src/compose.c: automatically convert attached UTF-16 text file to
- UTF-8.
+ * src/compose.c: automatically convert attached UTF-16 text file to
+ UTF-8 on sending.
2017-11-15
diff --git a/src/compose.c b/src/compose.c
index 418c85d5..ea4d145c 100644
--- a/src/compose.c
+++ b/src/compose.c
@@ -2212,14 +2212,41 @@ static void compose_insert_file(Compose *compose, const gchar *file,
FILE *fp;
gboolean prev_autowrap;
CharSet enc;
+ gchar *tmp_file = NULL;
g_return_if_fail(file != NULL);
enc = conv_check_file_encoding(file);
- if ((fp = g_fopen(file, "rb")) == NULL) {
- FILE_OP_ERROR(file, "fopen");
- return;
+ if (enc == C_UTF_16 || enc == C_UTF_16BE || enc == C_UTF_16LE) {
+ gchar *src = NULL;
+ gsize len = 0, dlen = 0;
+ gchar *dest;
+
+ g_file_get_contents(file, &src, &len, NULL);
+ dest = g_convert(src, len, CS_UTF_8, conv_get_charset_str(enc), NULL, &dlen, NULL);
+ tmp_file = get_tmp_file();
+ if (g_file_set_contents(tmp_file, dest, dlen, NULL) == FALSE) {
+ g_warning("compose_insert_file: Cannot convert UTF-16 file %s to UTF-8\n", file);
+ g_free(tmp_file);
+ tmp_file = NULL;
+ }
+ g_free(dest);
+ g_free(src);
+ }
+
+ if (tmp_file) {
+ if ((fp = g_fopen(tmp_file, "rb")) == NULL) {
+ FILE_OP_ERROR(tmp_file, "fopen");
+ g_unlink(tmp_file);
+ g_free(tmp_file);
+ return;
+ }
+ } else {
+ if ((fp = g_fopen(file, "rb")) == NULL) {
+ FILE_OP_ERROR(file, "fopen");
+ return;
+ }
}
prev_autowrap = compose->autowrap;
@@ -2263,6 +2290,10 @@ static void compose_insert_file(Compose *compose, const gchar *file,
}
fclose(fp);
+ if (tmp_file) {
+ g_unlink(tmp_file);
+ g_free(tmp_file);
+ }
compose->autowrap = prev_autowrap;
if (compose->autowrap)