/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2003 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2005 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
*out = '\0';
}
+#define JIS_HWDAKUTEN 0x5e
+#define JIS_HWHANDAKUTEN 0x5f
+
+static gint conv_jis_hantozen(guchar *outbuf, guchar jis_code, guchar sound_sym)
+{
+ static guint16 h2z_tbl[] = {
+ /* 0x20 - 0x2f */
+ 0x0000, 0x2123, 0x2156, 0x2157, 0x2122, 0x2126, 0x2572, 0x2521,
+ 0x2523, 0x2525, 0x2527, 0x2529, 0x2563, 0x2565, 0x2567, 0x2543,
+ /* 0x30 - 0x3f */
+ 0x213c, 0x2522, 0x2524, 0x2526, 0x2528, 0x252a, 0x252b, 0x252d,
+ 0x252f, 0x2531, 0x2533, 0x2535, 0x2537, 0x2539, 0x253b, 0x253d,
+ /* 0x40 - 0x4f */
+ 0x253f, 0x2541, 0x2544, 0x2546, 0x2548, 0x254a, 0x254b, 0x254c,
+ 0x254d, 0x254e, 0x254f, 0x2552, 0x2555, 0x2558, 0x255b, 0x255e,
+ /* 0x50 - 0x5f */
+ 0x255f, 0x2560, 0x2561, 0x2562, 0x2564, 0x2566, 0x2568, 0x2569,
+ 0x256a, 0x256b, 0x256c, 0x256d, 0x256f, 0x2573, 0x212b, 0x212c
+ };
+
+ static guint16 dakuten_tbl[] = {
+ /* 0x30 - 0x3f */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x252c, 0x252e,
+ 0x2530, 0x2532, 0x2534, 0x2536, 0x2538, 0x253a, 0x253c, 0x253e,
+ /* 0x40 - 0x4f */
+ 0x2540, 0x2542, 0x2545, 0x2547, 0x2549, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x2550, 0x2553, 0x2556, 0x2559, 0x255c, 0x0000
+ };
+
+ static guint16 handakuten_tbl[] = {
+ /* 0x4a - 0x4e */
+ 0x2551, 0x2554, 0x2557, 0x255a, 0x255d
+ };
+
+ guint16 out_code;
+
+ jis_code &= 0x7f;
+ sound_sym &= 0x7f;
+
+ if (jis_code < 0x21 || jis_code > 0x5f)
+ return 0;
+
+ if (sound_sym == JIS_HWDAKUTEN &&
+ jis_code >= 0x36 && jis_code <= 0x4e) {
+ out_code = dakuten_tbl[jis_code - 0x30];
+ if (out_code != 0) {
+ *outbuf = out_code >> 8;
+ *(outbuf + 1) = out_code & 0xff;
+ return 2;
+ }
+ }
+
+ if (sound_sym == JIS_HWHANDAKUTEN &&
+ jis_code >= 0x4a && jis_code <= 0x4e) {
+ out_code = handakuten_tbl[jis_code - 0x4a];
+ *outbuf = out_code >> 8;
+ *(outbuf + 1) = out_code & 0xff;
+ return 2;
+ }
+
+ out_code = h2z_tbl[jis_code - 0x20];
+ *outbuf = out_code >> 8;
+ *(outbuf + 1) = out_code & 0xff;
+ return 1;
+}
+
void conv_euctojis(gchar *outbuf, gint outlen, const gchar *inbuf)
{
const guchar *in = inbuf;
JISState state = JIS_ASCII;
while (*in != '\0') {
- if (isascii(*in)) {
+ if (IS_ASCII(*in)) {
K_OUT();
*out++ = *in++;
} else if (iseuckanji(*in)) {
K_OUT();
*out++ = SUBST_CHAR;
in++;
- if (*in != '\0' && !isascii(*in)) {
+ if (*in != '\0' && !IS_ASCII(*in)) {
*out++ = SUBST_CHAR;
in++;
}
}
} else if (iseuchwkana1(*in)) {
- in++;
- if (iseuchwkana2(*in)) {
- HW_IN();
- *out++ = *in++ & 0x7f;
+ if (iseuchwkana2(*(in + 1))) {
+ if (prefs_common.allow_jisx0201_kana) {
+ HW_IN();
+ in++;
+ *out++ = *in++ & 0x7f;
+ } else {
+ guchar jis_ch[2];
+ gint len;
+
+ if (iseuchwkana1(*(in + 2)) &&
+ iseuchwkana2(*(in + 3)))
+ len = conv_jis_hantozen
+ (jis_ch,
+ *(in + 1), *(in + 3));
+ else
+ len = conv_jis_hantozen
+ (jis_ch,
+ *(in + 1), '\0');
+ if (len == 0)
+ in += 2;
+ else {
+ K_IN();
+ in += len * 2;
+ *out++ = jis_ch[0];
+ *out++ = jis_ch[1];
+ }
+ }
} else {
K_OUT();
- if (*in != '\0' && !isascii(*in)) {
+ in++;
+ if (*in != '\0' && !IS_ASCII(*in)) {
*out++ = SUBST_CHAR;
in++;
}
*out++ = *in++ & 0x7f;
} else {
K_OUT();
- if (*in != '\0' && !isascii(*in)) {
+ if (*in != '\0' && !IS_ASCII(*in)) {
*out++ = SUBST_CHAR;
in++;
- if (*in != '\0' && !isascii(*in)) {
+ if (*in != '\0' && !IS_ASCII(*in)) {
*out++ = SUBST_CHAR;
in++;
}
guchar *out = outbuf;
while (*in != '\0') {
- if (isascii(*in)) {
+ if (IS_ASCII(*in)) {
*out++ = *in++;
} else if (issjiskanji1(*in)) {
if (issjiskanji2(*(in + 1))) {
} else {
*out++ = SUBST_CHAR;
in++;
- if (*in != '\0' && !isascii(*in)) {
+ if (*in != '\0' && !IS_ASCII(*in)) {
*out++ = SUBST_CHAR;
in++;
}
return (gboolean)valid_eucjp_tbl[c1 - 0xa2][c2 - 0xa0];
if (c1 == 0xcf) {
- if (c2 >= 0xd4 && c2 <= 0xff)
+ if (c2 >= 0xd4 && c2 <= 0xfe)
return FALSE;
} else if (c1 == 0xf4) {
- if (c2 >= 0xa7 && c2 <= 0xff)
+ if (c2 >= 0xa7 && c2 <= 0xfe)
return FALSE;
}
register guchar *p = str;
while (*p != '\0') {
- if (isascii(*p)) {
+ if (IS_ASCII(*p)) {
/* convert CR+LF -> LF */
if (*p == '\r' && *(p + 1) == '\n')
memmove(p, p + 1, strlen(p));
/* substitute unprintable code */
*p++ = SUBST_CHAR;
if (*p != '\0') {
- if (isascii(*p))
+ if (IS_ASCII(*p))
p++;
else
*p++ = SUBST_CHAR;
/* convert CR+LF -> LF */
if (*p == '\r' && *(p + 1) == '\n')
memmove(p, p + 1, strlen(p));
- else if (!isascii(*p)) *p = SUBST_CHAR;
+ else if (!IS_ASCII(*p)) *p = SUBST_CHAR;
p++;
}
}
if (guessed == C_US_ASCII)
return C_ISO_2022_JP;
p += 2;
- } else if (isascii(*p)) {
+ } else if (IS_ASCII(*p)) {
p++;
} else if (iseuckanji(*p) && iseuckanji(*(p + 1))) {
if (*p >= 0xfd && *p <= 0xfe)
switch (src_charset) {
case C_ISO_2022_JP:
case C_ISO_2022_JP_2:
+ case C_ISO_2022_JP_3:
if (dest_charset == C_AUTO &&
conv_get_current_charset() == C_EUC_JP)
code_conv = conv_jistodisp;
case C_ISO_8859_13:
case C_ISO_8859_14:
case C_ISO_8859_15:
- if (dest_charset == C_AUTO)
+ if (dest_charset == C_AUTO &&
+ (conv_get_current_charset() == src_charset ||
+ MB_CUR_MAX > 1))
code_conv = conv_latintodisp;
break;
case C_SHIFT_JIS:
if (dest_charset == C_AUTO &&
conv_get_current_charset() == C_EUC_JP)
code_conv = conv_euctodisp;
- else if (dest_charset == C_ISO_2022_JP ||
- dest_charset == C_ISO_2022_JP_2)
+ else if (dest_charset == C_ISO_2022_JP ||
+ dest_charset == C_ISO_2022_JP_2 ||
+ dest_charset == C_ISO_2022_JP_3)
code_conv = conv_euctojis;
break;
default:
const gchar *inbuf_p;
gchar *outbuf;
gchar *outbuf_p;
- gint in_size;
- gint in_left;
- gint out_size;
- gint out_left;
- gint n_conv;
- gint len;
+ size_t in_size;
+ size_t in_left;
+ size_t out_size;
+ size_t out_left;
+ size_t n_conv;
+ size_t len;
if (!src_code)
src_code = conv_get_outgoing_charset_str();
dest_code = conv_get_current_charset_str();
/* don't convert if current codeset is US-ASCII */
- if (!strcasecmp(dest_code, CS_US_ASCII))
+ if (!g_strcasecmp(dest_code, CS_US_ASCII))
return g_strdup(inbuf);
/* don't convert if src and dest codeset are identical */
- if (!strcasecmp(src_code, dest_code))
+ if (!g_strcasecmp(src_code, dest_code))
return g_strdup(inbuf);
cd = iconv_open(dest_code, src_code);
}
while ((n_conv = iconv(cd, (ICONV_CONST gchar **)&inbuf_p, &in_left,
- &outbuf_p, &out_left)) < 0) {
+ &outbuf_p, &out_left)) == (size_t)-1) {
if (EILSEQ == errno) {
inbuf_p++;
in_left--;
}
}
- while ((n_conv = iconv(cd, NULL, NULL, &outbuf_p, &out_left)) < 0) {
+ while ((n_conv = iconv(cd, NULL, NULL, &outbuf_p, &out_left)) ==
+ (size_t)-1) {
if (E2BIG == errno) {
EXPAND_BUF();
} else {
{C_KOI8_U, CS_KOI8_U},
{C_ISO_2022_JP, CS_ISO_2022_JP},
{C_ISO_2022_JP_2, CS_ISO_2022_JP_2},
+ {C_ISO_2022_JP_3, CS_ISO_2022_JP_3},
{C_EUC_JP, CS_EUC_JP},
{C_EUC_JP, CS_EUCJP},
{C_SHIFT_JIS, CS_SHIFT_JIS},
{"ru_RU" , C_ISO_8859_5 , C_KOI8_R},
{"tg_TJ" , C_KOI8_T , C_KOI8_T},
{"ru_UA" , C_KOI8_U , C_KOI8_U},
+ {"uk_UA.CP1251" , C_WINDOWS_1251, C_KOI8_U},
{"uk_UA" , C_KOI8_U , C_KOI8_U},
{"be_BY" , C_WINDOWS_1251, C_WINDOWS_1251},
/* "ja_JP.EUC" matches with "ja_JP.eucJP", "ja_JP.EUC" and
"ja_JP". "ja_JP" matches with "ja_JP.xxxx" and "ja" */
- if (!strncasecmp(cur_locale, locale_table[i].locale,
+ if (!g_strncasecmp(cur_locale, locale_table[i].locale,
strlen(locale_table[i].locale))) {
cur_charset = locale_table[i].charset;
return cur_charset;
} else if ((p = strchr(locale_table[i].locale, '_')) &&
!strchr(p + 1, '.')) {
if (strlen(cur_locale) == 2 &&
- !strncasecmp(cur_locale, locale_table[i].locale, 2)) {
+ !g_strncasecmp(cur_locale, locale_table[i].locale, 2)) {
cur_charset = locale_table[i].charset;
return cur_charset;
}
for (i = 0; i < sizeof(locale_table) / sizeof(locale_table[0]); i++) {
const gchar *p;
- if (!strncasecmp(cur_locale, locale_table[i].locale,
+ if (!g_strncasecmp(cur_locale, locale_table[i].locale,
strlen(locale_table[i].locale))) {
out_charset = locale_table[i].out_charset;
break;
} else if ((p = strchr(locale_table[i].locale, '_')) &&
!strchr(p + 1, '.')) {
if (strlen(cur_locale) == 2 &&
- !strncasecmp(cur_locale, locale_table[i].locale, 2)) {
+ !g_strncasecmp(cur_locale, locale_table[i].locale, 2)) {
out_charset = locale_table[i].out_charset;
break;
}
const gchar *str;
if (prefs_common.outgoing_charset) {
- if (!isalpha(prefs_common.outgoing_charset[0])) {
+ if (!isalpha((guchar)prefs_common.outgoing_charset[0])) {
g_free(prefs_common.outgoing_charset);
prefs_common.outgoing_charset = g_strdup(CS_AUTO);
} else if (strcmp(prefs_common.outgoing_charset, CS_AUTO) != 0)
case C_EUC_CN:
case C_ISO_2022_JP:
case C_ISO_2022_JP_2:
+ case C_ISO_2022_JP_3:
case C_ISO_2022_KR:
case C_ISO_2022_CN:
case C_SHIFT_JIS:
gchar *cur_locale;
cur_locale = g_getenv("LC_ALL");
- if (!cur_locale) cur_locale = g_getenv("LC_CTYPE");
- if (!cur_locale) cur_locale = g_getenv("LANG");
- if (!cur_locale) cur_locale = setlocale(LC_CTYPE, NULL);
+ if (!cur_locale || !strlen(cur_locale))
+ cur_locale = g_getenv("LC_CTYPE");
+ if (!cur_locale || !strlen(cur_locale))
+ cur_locale = g_getenv("LANG");
+ if (!cur_locale || !strlen(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;
- gint buflen;
- CharSet cur_charset;
-
- cur_charset = conv_get_current_charset();
-
- if (cur_charset == C_EUC_JP) {
- buflen = strlen(str) * 2 + 1;
- Xalloca(buf, buflen, return);
- 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);
- }
-}
-
void conv_unmime_header(gchar *outbuf, gint outlen, const gchar *str,
const gchar *charset)
{
#define MIMESEP_BEGIN "=?"
#define MIMESEP_END "?="
-#define B64LEN(len) ((len) / 3 * 4 + ((len) % 3 ? 4 : 0))
-
#define LBREAK_IF_REQUIRED(cond, is_plain_text) \
{ \
- if (len - (destp - dest) < MAX_LINELEN + 2) { \
+ if (len - (destp - (guchar *)dest) < MAX_LINELEN + 2) { \
*destp = '\0'; \
return; \
} \
\
if ((cond) && *srcp) { \
- if (destp > dest && left < MAX_LINELEN - 1) { \
+ if (destp > (guchar *)dest && left < MAX_LINELEN - 1) { \
if (isspace(*(destp - 1))) \
destp--; \
else if (is_plain_text && isspace(*srcp)) \
gint mimestr_len;
gchar *mimesep_enc;
gint left;
- const gchar *srcp = src;
- gchar *destp = dest;
+ const guchar *srcp = src;
+ guchar *destp = dest;
gboolean use_base64;
if (MB_CUR_MAX > 1) {
gchar *part_str;
gchar *out_str;
gchar *enc_str;
- const gchar *p = srcp;
+ const guchar *p = srcp;
gint out_str_len;
gint out_enc_str_len;
gint mime_block_len;