static void conv_ustodisp(gchar *outbuf, gint outlen, const gchar *inbuf);
static void conv_noconv(gchar *outbuf, gint outlen, const gchar *inbuf);
+static gboolean strict_mode = FALSE;
+
+void codeconv_set_strict(gboolean mode)
+{
+ strict_mode = mode;
+}
+
static void conv_jistoeuc(gchar *outbuf, gint outlen, const gchar *inbuf)
{
const guchar *in = inbuf;
{
gchar *tmpstr;
+ codeconv_set_strict(TRUE);
tmpstr = conv_iconv_strdup(inbuf, conv_get_locale_charset_str(),
CS_INTERNAL);
+ codeconv_set_strict(FALSE);
if (tmpstr && g_utf8_validate(tmpstr, -1, NULL)) {
strncpy2(outbuf, tmpstr, outlen);
g_free(tmpstr);
+ return;
} else if (tmpstr && !g_utf8_validate(tmpstr, -1, NULL)) {
g_free(tmpstr);
+ codeconv_set_strict(TRUE);
+ tmpstr = conv_iconv_strdup(inbuf,
+ conv_get_locale_charset_str_no_utf8(),
+ CS_INTERNAL);
+ codeconv_set_strict(FALSE);
+ }
+ if (tmpstr && g_utf8_validate(tmpstr, -1, NULL)) {
+ strncpy2(outbuf, tmpstr, outlen);
+ g_free(tmpstr);
+ return;
+ } else {
+ if (tmpstr)
+ g_free(tmpstr);
conv_utf8todisp(outbuf, outlen, inbuf);
- } else
- conv_utf8todisp(outbuf, outlen, inbuf);
+ }
}
static void conv_noconv(gchar *outbuf, gint outlen, const gchar *inbuf)
while ((n_conv = iconv(cd, (ICONV_CONST gchar **)&inbuf_p, &in_left,
&outbuf_p, &out_left)) == (size_t)-1) {
if (EILSEQ == errno) {
+ if (strict_mode) {
+ g_free(outbuf);
+ return NULL;
+ }
//g_print("iconv(): at %d: %s\n", in_size - in_left, g_strerror(errno));
inbuf_p++;
in_left--;
gchar *tmp;
gint i;
+ if (prefs_common.broken_are_utf8)
+ return conv_get_locale_charset();
+
if (cur_charset != -1)
return cur_charset;
out_str = conv_codeset_strdup
(part_str, cur_encoding, out_encoding);
if (!out_str) {
- g_warning("conv_encode_header(): code conversion failed\n");
- conv_unreadable_8bit(part_str);
- out_str = g_strdup(part_str);
+ if (strict_mode) {
+ *dest = '\0';
+ return;
+ } else {
+ g_warning("conv_encode_header(): code conversion failed\n");
+ conv_unreadable_8bit(part_str);
+ out_str = g_strdup(part_str);
+ }
}
out_str_len = strlen(out_str);