/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999,2000 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2001 Hiroyuki Yamamoto
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
}
}
+ /* don't convert if src and dest codeset are identical */
+ if (src_codeset && dest_codeset &&
+ !strcasecmp(src_codeset, dest_codeset))
+ return g_strdup(inbuf);
+
#if HAVE_LIBJCONV
if (src_codeset) {
codesets = &src_codeset;
n_codesets = 1;
} else
codesets = jconv_info_get_pref_codesets(&n_codesets);
- if (!dest_codeset)
+ if (!dest_codeset) {
dest_codeset = conv_get_current_charset_str();
+ /* don't convert if current codeset is US-ASCII */
+ if (!strcasecmp(dest_codeset, CS_US_ASCII))
+ return g_strdup(inbuf);
+ }
if (jconv_alloc_conv(inbuf, strlen(inbuf), &buf, &len,
codesets, n_codesets,
code_conv = conv_jistodisp;
else if (!strcasecmp(charset, CS_US_ASCII))
code_conv = conv_ustodisp;
+ else if (!strncasecmp(charset, CS_ISO_8859_1, 10))
+ code_conv = conv_latintodisp;
+#if !HAVE_LIBJCONV
else if (!strncasecmp(charset, "ISO-8859-", 9))
code_conv = conv_latintodisp;
+#endif
else if (!strcasecmp(charset, CS_SHIFT_JIS) ||
!strcasecmp(charset, "SHIFT-JIS") ||
!strcasecmp(charset, "SJIS") ||
gchar *const name;
} charsets[] = {
{C_US_ASCII, CS_US_ASCII},
+ {C_US_ASCII, CS_ANSI_X3_4_1968},
{C_UTF_8, CS_UTF_8},
{C_ISO_8859_1, CS_ISO_8859_1},
{C_ISO_8859_2, CS_ISO_8859_2},
{"lt_LT" , C_ISO_8859_13},
{"lv_LV" , C_ISO_8859_13},
- {"C" , C_US_ASCII},
- {"POSIX" , C_US_ASCII},
+ {"C" , C_US_ASCII},
+ {"POSIX" , C_US_ASCII},
+ {"ANSI_X3.4-1968" , C_US_ASCII},
};
#endif /* !HAVE_LIBJCONV */
const gchar *conv_get_current_charset_str(void)
{
-#if HAVE_LIBJCONV
- return jconv_info_get_current_codeset();
-#else
static const gchar *codeset = NULL;
if (!codeset)
codeset = conv_get_charset_str(conv_get_current_charset());
return codeset ? codeset : "US-ASCII";
-#endif
}
CharSet conv_get_outgoing_charset(void)
/* skip US-ASCII and UTF-8 */
pref_codesets = jconv_info_get_pref_codesets(&n_pref_codesets);
for (i = 0; i < n_pref_codesets; i++) {
- for (j = 2; j < sizeof(charsets) / sizeof(charsets[0]); j++) {
+ for (j = 3; j < sizeof(charsets) / sizeof(charsets[0]); j++) {
if (!strcasecmp(pref_codesets[i], charsets[j].name)) {
out_charset = charsets[j].charset;
return out_charset;
return str ? str : "US-ASCII";
}
+const gchar *conv_get_current_locale(void)
+{
+ gchar *cur_locale;
+
+ cur_locale = g_getenv("LC_ALL");
+ if (!cur_locale) cur_locale = g_getenv("LANG");
+ if (!cur_locale) cur_locale = setlocale(LC_CTYPE, NULL);
+
+ debug_print("current locale: %s\n",
+ cur_locale ? cur_locale : "(none)");
+
+ return cur_locale;
+}
+
void conv_unmime_header_overwrite(gchar *str)
{
gchar *buf;
cur_charset = conv_get_current_charset();
#if HAVE_LIBJCONV
- Xstrdup_a(buf, str, {return;});
+ Xstrdup_a(buf, str, return);
outlen = strlen(str) + 1;
UnMimeHeaderConv(buf, str, outlen);
- if (cur_charset == C_EUC_JP)
- conv_unreadable_eucjp(str);
+ if (cur_charset == C_EUC_JP) {
+ gchar *tmp;
+ gint len;
+
+ len = strlen(str) * 2 + 1;
+ Xalloca(tmp, len, return);
+ conv_jistodisp(tmp, len, str);
+ strncpy2(str, tmp, outlen);
+ }
#else
if (cur_charset == C_EUC_JP) {
gchar *tmp;
gint len;
- Xstrdup_a(buf, str, {return;});
+ Xstrdup_a(buf, str, return);
outlen = strlen(str) + 1;
UnMimeHeader(buf);
len = strlen(buf) * 2 + 1;
gchar *buf;
CharSet cur_charset;
- Xstrdup_a(buf, str, {return;});
cur_charset = conv_get_current_charset();
+ Xstrdup_a(buf, str, return);
#if HAVE_LIBJCONV
UnMimeHeaderConv(buf, outbuf, outlen);
- if (cur_charset == C_EUC_JP)
- conv_unreadable_eucjp(outbuf);
#else
UnMimeHeader(buf);
+ strncpy2(outbuf, buf, outlen);
+#endif
if (cur_charset == C_EUC_JP) {
- gchar *tmp;
gint len;
- len = strlen(buf) * 2 + 1;
- Xalloca(tmp, len, {strncpy2(outbuf, buf, outlen); return;});
- conv_jistodisp(tmp, len, buf);
- strncpy2(outbuf, tmp, outlen);
- } else
+ len = strlen(outbuf) * 2 + 1;
+ Xalloca(buf, len, return);
+ conv_jistodisp(buf, len, outbuf);
strncpy2(outbuf, buf, outlen);
-#endif
+ }
}
#define MAX_ENCLEN 75
gchar *mimehdr_enctype = "?B?";
const gchar *mimehdr_charset;
- //g_print("src = %s\n", src);
+ /* g_print("src = %s\n", src); */
mimehdr_charset = conv_get_outgoing_charset_str();
/* convert to wide-character string */
strlen(mimehdr_charset) + strlen(mimehdr_enctype);
mimehdr_begin_len = strlen(mimehdr_init) +
strlen(mimehdr_charset) + strlen(mimehdr_enctype);
- //line_len = 1;
+ /* line_len = 1; */
line_len = header_len;
destp = dest;
*dest = '\0';
}
/* g_free(raw); */
src_codeset = conv_get_current_charset_str();
- //printf ("tmp = %s, tlen = %d, mbl\n",
- // tmp, tlen, mbl);
+ /* printf ("tmp = %s, tlen = %d, mbl\n",
+ tmp, tlen, mbl); */
if (jconv_alloc_conv(tmp, tlen + mbl,
&raw_new, &raw_new_len,
&src_codeset, 1,
break;
}
}
- } else {
- if ((line_len + tlen + mbl +
- (*(wtmpp + 1) ? 0 : nspc) +
- (line_len > 1 ? 1 : 0))
- > MAX_LINELEN) {
- g_free(raw_new);
- if (1 + tlen + mbl +
- (*(wtmpp + 1) ? 0 : nspc)
- >= MAX_LINELEN) {
- *tmpp = '\0';
- break;
- }
- *destp++ = '\n';
- *destp++ = ' ';
- line_len = 1;
- continue;
+ } else if ((line_len + tlen + mbl +
+ (*(wtmpp + 1) ? 0 : nspc) +
+ (line_len > 1 ? 1 : 0))
+ > MAX_LINELEN) {
+ g_free(raw_new);
+ if (1 + tlen + mbl +
+ (*(wtmpp + 1) ? 0 : nspc)
+ >= MAX_LINELEN) {
+ *tmpp = '\0';
+ break;
}
+ *destp++ = '\n';
+ *destp++ = ' ';
+ line_len = 1;
+ continue;
}
tmpp += mbl;
wtmpp++;
}
- //g_print("tmp = %s, tlen = %d, mb_seqlen = %d\n",
- // tmp, tlen, mb_seqlen);
+ /*
+ g_print("tmp = %s, tlen = %d, mb_seqlen = %d\n",
+ tmp, tlen, mb_seqlen);
+ */
if (tlen == 0 || raw_len == 0) {
g_free(tmp);
g_free(tmp);
g_free(raw);
- //g_print("line_len = %d\n\n", line_len);
+ /* g_print("line_len = %d\n\n", line_len); */
} while (*wtmpp != (wchar_t)0);
while (iswspace(*wsrcp)) {
g_free(wsrc);
- //g_print("dest = %s\n", dest);
+ /* g_print("dest = %s\n", dest); */
}
#else /* !HAVE_LIBJCONV */
gchar *mimehdr_enctype = "?B?";
const gchar *mimehdr_charset;
- //g_print("src = %s\n", src);
+ /* g_print("src = %s\n", src); */
mimehdr_charset = conv_get_outgoing_charset_str();
if (strcmp(mimehdr_charset, "ISO-2022-JP") != 0) {
/* currently only supports Japanese */
strlen(mimehdr_charset) + strlen(mimehdr_enctype);
mimehdr_begin_len = strlen(mimehdr_init) +
strlen(mimehdr_charset) + strlen(mimehdr_enctype);
- //line_len = 1;
+ /* line_len = 1; */
line_len = header_len;
destp = dest;
*dest = '\0';
break;
}
}
- } else {
- if ((line_len + tlen + mbl +
- (*(wtmpp + 1) ? 0 : nspc) +
- (line_len > 1 ? 1 : 0))
- > MAX_LINELEN) {
- if (1 + tlen + mbl +
- (*(wtmpp + 1) ? 0 : nspc)
- >= MAX_LINELEN) {
- *tmpp = '\0';
- break;
- }
- *destp++ = '\n';
- *destp++ = ' ';
- line_len = 1;
- continue;
+ } else if ((line_len + tlen + mbl +
+ (*(wtmpp + 1) ? 0 : nspc) +
+ (line_len > 1 ? 1 : 0))
+ > MAX_LINELEN) {
+ if (1 + tlen + mbl +
+ (*(wtmpp + 1) ? 0 : nspc)
+ >= MAX_LINELEN) {
+ *tmpp = '\0';
+ break;
}
+ *destp++ = '\n';
+ *destp++ = ' ';
+ line_len = 1;
+ continue;
}
tmpp += mbl;
wtmpp++;
}
- //g_print("tmp = %s, tlen = %d, mb_seqlen = %d\n",
- // tmp, tlen, mb_seqlen);
+ /* g_print("tmp = %s, tlen = %d, mb_seqlen = %d\n",
+ tmp, tlen, mb_seqlen);
+ */
if (tlen == 0) {
g_free(tmp);
}
g_free(tmp);
- //g_print("line_len = %d\n\n", line_len);
+ /* g_print("line_len = %d\n\n", line_len); */
} while (*wtmpp != (wchar_t)0);
while (iswspace(*wsrcp)) {
g_free(wsrc);
- //g_print("dest = %s\n", dest);
+ /* g_print("dest = %s\n", dest); */
}
#endif /* HAVE_LIBJCONV */