JIS_AUXKANJI
} JISState;
-#define SUBST_CHAR '_'
+#define SUBST_CHAR 0x5f;
#define ESC '\033'
#define iseuckanji(c) \
}
}
+void conv_unreadable_utf8(gchar *str)
+{
+ register guchar *p = str;
+
+ while (*p != '\0') {
+ /* convert CR+LF -> LF */
+ printf("p %c (%d)\n", *p, *p);
+ if (*p == '\r' && *(p + 1) == '\n')
+ memmove(p, p + 1, strlen(p));
+ else if (((*p & 0xff) >= 0x7f && (*p & 0xff) <= 0x9f)
+ || *p == 0xfc)
+ *p = SUBST_CHAR;
+ p++;
+ }
+}
+
void conv_unreadable_locale(gchar *str)
{
switch (conv_get_current_charset()) {
case C_EUC_JP:
conv_unreadable_eucjp(str);
break;
+ case C_UTF_8:
+ conv_unreadable_utf8(str);
+ break;
default:
break;
}
const gchar *conv_get_current_locale(void)
{
- const gchar *cur_locale;
+ static const gchar *cur_locale = NULL;
+ if (cur_locale != NULL)
+ return cur_locale;
+
cur_locale = g_getenv("LC_ALL");
if (!cur_locale || !strlen(cur_locale))
cur_locale = g_getenv("LC_CTYPE");
if (!cur_locale || !strlen(cur_locale))
cur_locale = setlocale(LC_CTYPE, NULL);
-/* debug_print("current locale: %s\n",
- cur_locale ? cur_locale : "(none)"); */
+ if (cur_locale && strlen(cur_locale)) {
+ gchar *tmp = g_strdup(cur_locale);
+ cur_locale = g_strdup(tmp);
+ g_free(tmp);
+ }
return cur_locale;
}
void conv_unmime_header(gchar *outbuf, gint outlen, const gchar *str,
const gchar *charset)
{
- CharSet cur_charset;
const gchar *locale;
- cur_charset = conv_get_current_charset();
-
+ memset(outbuf, 0, outlen);
+
#warning FIXME_GTK2
/* Should we always ensure to convert? */
locale = conv_get_current_locale();
Xalloca(buf, buflen, return);
conv_anytodisp(buf, buflen, str);
unmime_header(outbuf, buf);
- } else if (g_utf8_validate(str, -1, NULL)) {
- unmime_header(outbuf, str);
} else {
- gchar *buf;
- gint buflen;
- const gchar *src_codeset, *dest_codeset;
- src_codeset = conv_get_current_charset_str();
- dest_codeset = CS_UTF_8;
- buf = conv_codeset_strdup(str, src_codeset, dest_codeset);
- unmime_header(outbuf, buf);
+ gchar *tmp;
+ unmime_header(outbuf, str);
+ if (outbuf && !g_utf8_validate(outbuf, -1, NULL)) {
+ tmp = conv_codeset_strdup(outbuf,
+ conv_get_current_charset_str(),
+ CS_UTF_8);
+ if (tmp) {
+ strncpy(outbuf, tmp, outlen-1);
+ g_free(tmp);
+ }
+ }
}
}