* src/codeconv.c
[claws.git] / src / codeconv.c
index 9061b602073a163c76f602b63dd1d7e6eff2deb2..566efdda66c98083fac7b7b1bbccaddd4fad32d9 100644 (file)
@@ -362,8 +362,12 @@ gchar *conv_codeset_strdup(const gchar *inbuf,
                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,
@@ -371,11 +375,11 @@ gchar *conv_codeset_strdup(const gchar *inbuf,
            == 0)
                return buf;
        else
-               return NULL;
+               return g_strdup(inbuf);
 #else /* !HAVE_LIBJCONV */
        if (src_codeset) {
                if (!strcasecmp(src_codeset, CS_EUC_JP) ||
-                   !strcasecmp(src_codeset, "EUCJP"))
+                   !strcasecmp(src_codeset, CS_EUCJP))
                        src_charset = C_EUC_JP;
                else if (!strcasecmp(src_codeset, CS_SHIFT_JIS) ||
                         !strcasecmp(src_codeset, "SHIFT-JIS") ||
@@ -431,7 +435,7 @@ CodeConvFunc conv_get_code_conv_func(const gchar *charset)
                 !strcasecmp(charset, "X-SJIS"))
                code_conv = conv_sjistodisp;
        else if (!strcasecmp(charset, CS_EUC_JP) ||
-                !strcasecmp(charset, "EUCJP"))
+                !strcasecmp(charset, CS_EUCJP))
                code_conv = conv_euctodisp;
        else
                code_conv = conv_noconv;
@@ -453,6 +457,7 @@ static const struct {
        {C_ISO_8859_7,          CS_ISO_8859_7},
        {C_ISO_8859_8,          CS_ISO_8859_8},
        {C_ISO_8859_9,          CS_ISO_8859_9},
+       {C_ISO_8859_11,         CS_ISO_8859_11},
        {C_ISO_8859_13,         CS_ISO_8859_13},
        {C_ISO_8859_15,         CS_ISO_8859_15},
        {C_BALTIC,              CS_BALTIC},
@@ -463,6 +468,7 @@ static const struct {
        {C_ISO_2022_JP,         CS_ISO_2022_JP},
        {C_ISO_2022_JP_2,       CS_ISO_2022_JP_2},
        {C_EUC_JP,              CS_EUC_JP},
+       {C_EUC_JP,              CS_EUCJP},
        {C_SHIFT_JIS,           CS_SHIFT_JIS},
        {C_ISO_2022_KR,         CS_ISO_2022_KR},
        {C_EUC_KR,              CS_EUC_KR},
@@ -471,6 +477,8 @@ static const struct {
        {C_GB2312,              CS_GB2312},
        {C_EUC_TW,              CS_EUC_TW},
        {C_BIG5,                CS_BIG5},
+       {C_TIS_620,             CS_TIS_620},
+       {C_WINDOWS_874,         CS_WINDOWS_874},
 };
 
 #if !HAVE_LIBJCONV
@@ -521,14 +529,19 @@ static const struct {
        {"iw_IL"        , C_ISO_8859_8},
        {"tr_TR"        , C_ISO_8859_9},
 
+       {"th_TH"        , C_TIS_620},
+       /* {"th_TH"     , C_WINDOWS_874}, */
+       /* {"th_TH"     , C_ISO_8859_11}, */
+
        {"lt_LT.iso88594"       , C_ISO_8859_4},
        {"lt_LT.ISO8859-4"      , C_ISO_8859_4},
        {"lt_LT.ISO_8859-4"     , C_ISO_8859_4},
        {"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 */
 
@@ -651,7 +664,7 @@ 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;
@@ -806,7 +819,6 @@ void conv_encode_header(gchar *dest, gint len, const gchar *src,
                strlen(mimehdr_charset) + strlen(mimehdr_enctype);
        mimehdr_begin_len = strlen(mimehdr_init) +
                strlen(mimehdr_charset) + strlen(mimehdr_enctype);
-       /* line_len = 1; */
        line_len = header_len;
        destp = dest;
        *dest = '\0';
@@ -869,8 +881,8 @@ void conv_encode_header(gchar *dest, gint len, const gchar *src,
                                }
                                /* 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,
@@ -878,6 +890,7 @@ void conv_encode_header(gchar *dest, gint len, const gchar *src,
                                    != 0) {
                                        g_warning("can't convert\n");
                                        tmpp[0] = '\0';
+                                       wtmpp++;
                                        continue;
                                }
                                if (!str_ascii) {
@@ -927,10 +940,8 @@ void conv_encode_header(gchar *dest, gint len, const gchar *src,
 
                                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);
@@ -985,7 +996,7 @@ void conv_encode_header(gchar *dest, gint len, const gchar *src,
 
        g_free(wsrc);
 
-       /* g_print("dest = %s\n", dest);  */
+       /* g_print("dest = %s\n", dest); */
 }
 #else /* !HAVE_LIBJCONV */
 
@@ -1018,7 +1029,6 @@ void conv_encode_header(gchar *dest, gint len, const gchar *src,
                      strlen(mimehdr_charset) + strlen(mimehdr_enctype);
        mimehdr_begin_len = strlen(mimehdr_init) +
                            strlen(mimehdr_charset) + strlen(mimehdr_enctype);
-       /* line_len = 1; */
        line_len = header_len;
        destp = dest;
        *dest = '\0';
@@ -1118,8 +1128,7 @@ void conv_encode_header(gchar *dest, gint len, const gchar *src,
                                wtmpp++;
                        }
                        /* g_print("tmp = %s, tlen = %d, mb_seqlen = %d\n",
-                               tmp, tlen, mb_seqlen);
-                       */                              
+                               tmp, tlen, mb_seqlen); */
 
                        if (tlen == 0) {
                                g_free(tmp);