2005-02-25 [paul] 1.0.1cvs15.12
[claws.git] / src / codeconv.c
index 4633d369e84e5d97196be8a81095b09e335bb392..89a2e5aa36491390cc2466aaeca5a3d221cc41c4 100644 (file)
@@ -655,7 +655,7 @@ static void conv_unreadable_latin(gchar *str)
                /* convert CR+LF -> LF */
                if (*p == '\r' && *(p + 1) == '\n')
                        memmove(p, p + 1, strlen(p));
-               else if ((*p & 0xff) >= 0x7f)
+               else if ((*p & 0xff) >= 0x7f && (*p & 0xff) <= 0x9f)
                        *p = SUBST_CHAR;
                p++;
        }
@@ -795,6 +795,8 @@ void conv_utf8todisp(gchar *outbuf, gint outlen, const gchar *inbuf)
 static void conv_anytodisp(gchar *outbuf, gint outlen, const gchar *inbuf)
 {
        conv_anytoutf8(outbuf, outlen, inbuf);
+       if (g_utf8_validate(outbuf, -1, NULL) != TRUE)
+               conv_unreadable_8bit(outbuf);
 }
 
 static void conv_ustodisp(gchar *outbuf, gint outlen, const gchar *inbuf)
@@ -813,7 +815,7 @@ void conv_localetodisp(gchar *outbuf, gint outlen, const gchar *inbuf)
                strncpy2(outbuf, tmpstr, outlen);
                g_free(tmpstr);
        } else
-               strncpy2(outbuf, inbuf, outlen);
+               conv_utf8todisp(outbuf, outlen, inbuf);
 }
 
 static void conv_noconv(gchar *outbuf, gint outlen, const gchar *inbuf)
@@ -1543,57 +1545,33 @@ void conv_unmime_header_overwrite(gchar *str)
 {
        gchar *buf;
        gint buflen;
-       CharSet cur_charset;
 
-       cur_charset = conv_get_locale_charset();
+       buflen = strlen(str) * 2 + 1;
+       Xalloca(buf, buflen, return);
 
-       if (cur_charset == C_EUC_JP) {
-               buflen = strlen(str) * 2 + 1;
-               Xalloca(buf, buflen, return);
+       if (conv_get_locale_charset() == C_EUC_JP)
                conv_anytodisp(buf, buflen, str);
-               unmime_header(str, buf);
-       } else {
-               buflen = strlen(str) + 1;
-               Xalloca(buf, buflen, return);
-               unmime_header(buf, str);
-               strncpy2(str, buf, buflen);
-       }
+       else
+               conv_localetodisp(buf, buflen, str);
+
+       unmime_header(str, buf);
 }
 
 void conv_unmime_header(gchar *outbuf, gint outlen, const gchar *str,
                        const gchar *charset)
 {
-       CharSet cur_charset;
-
-       cur_charset = conv_get_locale_charset();
+       gchar *buf;
+       gint buflen;
 
-       if (cur_charset == C_EUC_JP) {
-               gchar *buf;
-               gint buflen;
+       buflen = strlen(str) * 2 + 1;
+       Xalloca(buf, buflen, return);
 
-               buflen = strlen(str) * 2 + 1;
-               Xalloca(buf, buflen, return);
+       if (conv_get_locale_charset() == C_EUC_JP)
                conv_anytodisp(buf, buflen, str);
-               unmime_header(outbuf, buf);
-       } else {
-               gchar *tmp = NULL;
-               unmime_header(outbuf, str);
-
-               if (outbuf && !g_utf8_validate(outbuf, -1, NULL)) {
-                       if (conv_get_locale_charset() != C_INTERNAL)
-                               tmp = conv_codeset_strdup(outbuf,
-                                       conv_get_locale_charset_str(),
-                                       CS_INTERNAL);
-
-                       if (tmp) {
-                               strncpy(outbuf, tmp, outlen-1);
-                               g_free(tmp);
-                       } else {
-                               conv_unreadable_8bit(outbuf);
-                       }
-               }
-       }
+       else
+               conv_localetodisp(buf, buflen, str);
 
+       unmime_header(outbuf, buf);
 }
 
 #define MAX_LINELEN            76