diff options
author | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2005-03-14 11:11:50 +0000 |
---|---|---|
committer | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2005-03-14 11:11:50 +0000 |
commit | bdb6a57dffe028e673708ae1bd26207c6a8ad08e (patch) | |
tree | 588d104215ac3e6fb7fc2daac09e805a1073deb4 /src | |
parent | 136e1e02a3c4f5fb7b7e96e2bc88ac7d5fe9f779 (diff) |
do a strict check for code conversion when sending.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@167 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'src')
-rw-r--r-- | src/codeconv.c | 47 | ||||
-rw-r--r-- | src/codeconv.h | 10 | ||||
-rw-r--r-- | src/compose.c | 34 |
3 files changed, 62 insertions, 29 deletions
diff --git a/src/codeconv.c b/src/codeconv.c index cf41cdea..f172a27c 100644 --- a/src/codeconv.c +++ b/src/codeconv.c @@ -411,7 +411,7 @@ static void conv_sjistoutf8(gchar *outbuf, gint outlen, const gchar *inbuf) { gchar *tmpstr; - tmpstr = conv_iconv_strdup(inbuf, CS_SHIFT_JIS, CS_UTF_8); + tmpstr = conv_iconv_strdup(inbuf, CS_SHIFT_JIS, CS_UTF_8, NULL); if (tmpstr) { strncpy2(outbuf, tmpstr, outlen); g_free(tmpstr); @@ -443,7 +443,7 @@ static void conv_euctoutf8(gchar *outbuf, gint outlen, const gchar *inbuf) } } - tmpstr = conv_iconv_strdup_with_cd(inbuf, cd); + tmpstr = conv_iconv_strdup_with_cd(inbuf, cd, NULL); if (tmpstr) { strncpy2(outbuf, tmpstr, outlen); g_free(tmpstr); @@ -493,7 +493,7 @@ static void conv_utf8toeuc(gchar *outbuf, gint outlen, const gchar *inbuf) } } - tmpstr = conv_iconv_strdup_with_cd(inbuf, cd); + tmpstr = conv_iconv_strdup_with_cd(inbuf, cd, NULL); if (tmpstr) { strncpy2(outbuf, tmpstr, outlen); g_free(tmpstr); @@ -812,7 +812,7 @@ void conv_localetodisp(gchar *outbuf, gint outlen, const gchar *inbuf) gchar *tmpstr; tmpstr = conv_iconv_strdup(inbuf, conv_get_locale_charset_str(), - CS_INTERNAL); + CS_INTERNAL, NULL); if (tmpstr) { strncpy2(outbuf, tmpstr, outlen); g_free(tmpstr); @@ -855,7 +855,7 @@ gint conv_convert(CodeConverter *conv, gchar *outbuf, gint outlen, gchar *str; str = conv_iconv_strdup - (inbuf, conv->src_encoding, conv->dest_encoding); + (inbuf, conv->src_encoding, conv->dest_encoding, NULL); if (!str) return -1; else { @@ -870,6 +870,13 @@ gint conv_convert(CodeConverter *conv, gchar *outbuf, gint outlen, gchar *conv_codeset_strdup(const gchar *inbuf, const gchar *src_code, const gchar *dest_code) { + return conv_codeset_strdup_full(inbuf, src_code, dest_code, NULL); +} + +gchar *conv_codeset_strdup_full(const gchar *inbuf, + const gchar *src_code, const gchar *dest_code, + gint *error) +{ gchar *buf; size_t len; CodeConvFunc conv_func; @@ -878,13 +885,17 @@ gchar *conv_codeset_strdup(const gchar *inbuf, if (conv_func != conv_noconv) { len = (strlen(inbuf) + 1) * 3; buf = g_malloc(len); - if (!buf) return NULL; + if (!buf) { + if (error) + *error = -1; + return NULL; + } conv_func(buf, len, inbuf); return g_realloc(buf, strlen(buf) + 1); } - return conv_iconv_strdup(inbuf, src_code, dest_code); + return conv_iconv_strdup(inbuf, src_code, dest_code, error); } CodeConvFunc conv_get_code_conv_func(const gchar *src_charset_str, @@ -973,7 +984,8 @@ CodeConvFunc conv_get_code_conv_func(const gchar *src_charset_str, } gchar *conv_iconv_strdup(const gchar *inbuf, - const gchar *src_code, const gchar *dest_code) + const gchar *src_code, const gchar *dest_code, + gint *error) { iconv_t cd; gchar *outbuf; @@ -984,17 +996,20 @@ gchar *conv_iconv_strdup(const gchar *inbuf, dest_code = CS_INTERNAL; cd = iconv_open(dest_code, src_code); - if (cd == (iconv_t)-1) + if (cd == (iconv_t)-1) { + if (error) + *error = -1; return NULL; + } - outbuf = conv_iconv_strdup_with_cd(inbuf, cd); + outbuf = conv_iconv_strdup_with_cd(inbuf, cd, error); iconv_close(cd); return outbuf; } -gchar *conv_iconv_strdup_with_cd(const gchar *inbuf, iconv_t cd) +gchar *conv_iconv_strdup_with_cd(const gchar *inbuf, iconv_t cd, gint *error) { const gchar *inbuf_p; gchar *outbuf; @@ -1005,6 +1020,7 @@ gchar *conv_iconv_strdup_with_cd(const gchar *inbuf, iconv_t cd) size_t out_left; size_t n_conv; size_t len; + gint error_ = 0; inbuf_p = inbuf; in_size = strlen(inbuf); @@ -1026,7 +1042,8 @@ gchar *conv_iconv_strdup_with_cd(const gchar *inbuf, iconv_t cd) while ((n_conv = iconv(cd, (ICONV_CONST gchar **)&inbuf_p, &in_left, &outbuf_p, &out_left)) == (size_t)-1) { if (EILSEQ == errno) { - //g_print("iconv(): at %d: %s\n", in_size - in_left, g_strerror(errno)); + /* g_print("iconv(): at %d: %s\n", in_size - in_left, g_strerror(errno)); */ + error_ = -1; inbuf_p++; in_left--; if (out_left == 0) { @@ -1035,12 +1052,14 @@ gchar *conv_iconv_strdup_with_cd(const gchar *inbuf, iconv_t cd) *outbuf_p++ = SUBST_CHAR; out_left--; } else if (EINVAL == errno) { + error_ = -1; break; } else if (E2BIG == errno) { EXPAND_BUF(); } else { g_warning("conv_iconv_strdup(): %s\n", g_strerror(errno)); + error_ = -1; break; } } @@ -1052,6 +1071,7 @@ gchar *conv_iconv_strdup_with_cd(const gchar *inbuf, iconv_t cd) } else { g_warning("conv_iconv_strdup(): %s\n", g_strerror(errno)); + error_ = -1; break; } } @@ -1062,6 +1082,9 @@ gchar *conv_iconv_strdup_with_cd(const gchar *inbuf, iconv_t cd) outbuf = g_realloc(outbuf, len + 1); outbuf[len] = '\0'; + if (error) + *error = error_; + return outbuf; } diff --git a/src/codeconv.h b/src/codeconv.h index e2b3edda..4ffa10ec 100644 --- a/src/codeconv.h +++ b/src/codeconv.h @@ -187,15 +187,21 @@ gint conv_convert (CodeConverter *conv, gchar *conv_codeset_strdup (const gchar *inbuf, const gchar *src_code, const gchar *dest_code); +gchar *conv_codeset_strdup_full (const gchar *inbuf, + const gchar *src_code, + const gchar *dest_code, + gint *error); CodeConvFunc conv_get_code_conv_func (const gchar *src_charset_str, const gchar *dest_charset_str); gchar *conv_iconv_strdup (const gchar *inbuf, const gchar *src_code, - const gchar *dest_code); + const gchar *dest_code, + gint *error); gchar *conv_iconv_strdup_with_cd (const gchar *inbuf, - iconv_t cd); + iconv_t cd, + gint *error); const gchar *conv_get_charset_str (CharSet charset); CharSet conv_get_charset_from_str (const gchar *charset); diff --git a/src/compose.c b/src/compose.c index 9b03f12f..3e96e034 100644 --- a/src/compose.c +++ b/src/compose.c @@ -2529,28 +2529,22 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, out_codeset = CS_US_ASCII; encoding = ENC_7BIT; } else { + gint error = 0; + out_codeset = conv_get_outgoing_charset_str(); if (!strcasecmp(out_codeset, CS_US_ASCII)) out_codeset = CS_ISO_8859_1; - if (prefs_common.encoding_method == CTE_BASE64) - encoding = ENC_BASE64; - else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE) - encoding = ENC_QUOTED_PRINTABLE; - else if (prefs_common.encoding_method == CTE_8BIT) - encoding = ENC_8BIT; - else - encoding = procmime_get_encoding_for_charset - (out_codeset); - - buf = conv_codeset_strdup(chars, src_codeset, out_codeset); - if (!buf) { + buf = conv_codeset_strdup_full(chars, src_codeset, out_codeset, + &error); + if (!buf || error != 0) { AlertValue aval; gchar *msg; - msg = g_strdup_printf(_("Can't convert the character encoding of the message from\n" - "%s to %s.\n" - "Send it anyway?"), src_codeset, out_codeset); + msg = g_strdup_printf(_("Can't convert the character encoding of the message body from %s to %s.\n" + "Send it as %s anyway?"), + src_codeset, out_codeset, + src_codeset); aval = alertpanel (_("Error"), msg, _("Yes"), _("+No"), NULL); g_free(msg); @@ -2566,6 +2560,16 @@ static gint compose_write_to_file(Compose *compose, const gchar *file, chars = NULL; } } + + if (prefs_common.encoding_method == CTE_BASE64) + encoding = ENC_BASE64; + else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE) + encoding = ENC_QUOTED_PRINTABLE; + else if (prefs_common.encoding_method == CTE_8BIT) + encoding = ENC_8BIT; + else + encoding = procmime_get_encoding_for_charset + (out_codeset); } g_free(chars); |