fix bug in header encoding, clean codeconv for glib2
authorColin Leroy <colin@colino.net>
Mon, 19 Jul 2004 19:50:54 +0000 (19:50 +0000)
committerColin Leroy <colin@colino.net>
Mon, 19 Jul 2004 19:50:54 +0000 (19:50 +0000)
ChangeLog-gtk2.claws
PATCHSETS
configure.ac
src/codeconv.c
src/compose.c

index fa0ac3f9b13e1cf46e057164c9b3cf3438e78242..8f48e23bd389cb5dcc7fa0323c8e488f66ecebe8 100644 (file)
@@ -1,3 +1,10 @@
+2004-07-19 [colin]     0.9.12cvs33.4
+
+       * src/compose.c
+               Fix outgoing charset bug in headers
+       * src/codeconv.c
+               Clean for glib2 - Patch by Alfons
+
 2004-07-19 [colin]     0.9.12cvs33.3
 
        * src/statusbar.c
index 63caa9a5f8dc82fc3dffc8f461a77dc786413185..77628e86430e14b3284fbaa1afb417c0e70a53cc 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
@@ -57,3 +57,4 @@
 ( cvs diff -u -r 1.87.2.8 -r 1.87.2.9 src/folder.h; cvs diff -u -r 1.207.2.9 -r 1.207.2.10 src/folderview.c; cvs diff -u -r 1.395.2.22 -r 1.395.2.23 src/summaryview.c; ) > 0.9.12cvs33.1.patchset
 ( cvs diff -u -r 1.94.2.21 -r 1.94.2.22 src/messageview.c; cvs diff -u -r 1.96.2.13 -r 1.96.2.14 src/textview.c; ) > 0.9.12cvs33.2.patchset
 ( cvs diff -u -r 1.5 -r 1.6 src/statusbar.c; ) > 0.9.12cvs33.3.patchset
+( cvs diff -u -r 1.382.2.28 -r 1.382.2.29 src/compose.c; cvs diff -u -r 1.65.2.7 -r 1.65.2.8 src/codeconv.c; ) > 0.9.12cvs33.4.patchset
index 388acb6f7ef0402539fdcd8437033a39ed3a752a..02468f0da48fb925caaf52da13fb6cc388c7fef8 100644 (file)
@@ -13,7 +13,7 @@ INTERFACE_AGE=0
 BINARY_AGE=0
 EXTRA_VERSION=33
 EXTRA_RELEASE=
-EXTRA_GTK2_VERSION=.3
+EXTRA_GTK2_VERSION=.4
 
 if test \( $EXTRA_VERSION -eq 0 \) -o \( "x$EXTRA_RELEASE" != "x" \); then
     VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}${EXTRA_RELEASE}${EXTRA_GTK2_VERSION}
index 48da432651fd090df61b3518a1532a8ed082b014..c69ad4a439d9c0e13f999c6971191c8bf3308191 100644 (file)
 #  include <locale.h>
 #endif
 
-#if HAVE_ICONV
-#  include <iconv.h>
-#endif
-
 #include "intl.h"
 #include "codeconv.h"
 #include "unmime.h"
@@ -784,7 +780,6 @@ void conv_code_converter_destroy(CodeConverter *conv)
 gint conv_convert(CodeConverter *conv, gchar *outbuf, gint outlen,
                  const gchar *inbuf)
 {
-#if HAVE_ICONV
        if (conv->code_conv_func != conv_noconv)
                conv->code_conv_func(outbuf, outlen, inbuf);
        else {
@@ -798,9 +793,6 @@ gint conv_convert(CodeConverter *conv, gchar *outbuf, gint outlen,
                        g_free(str);
                }
        }
-#else /* !HAVE_ICONV */
-       conv->code_conv_func(outbuf, outlen, inbuf);
-#endif
 
        return 0;
 }
@@ -822,11 +814,7 @@ gchar *conv_codeset_strdup(const gchar *inbuf,
                return g_realloc(buf, strlen(buf) + 1);
        }
 
-#if HAVE_ICONV
        return conv_iconv_strdup(inbuf, src_code, dest_code);
-#else
-       return g_strdup(inbuf);
-#endif /* HAVE_ICONV */
 }
 
 CodeConvFunc conv_get_code_conv_func(const gchar *src_charset_str,
@@ -914,25 +902,20 @@ CodeConvFunc conv_get_code_conv_func(const gchar *src_charset_str,
        return code_conv;
 }
 
-#if HAVE_ICONV
 gchar *conv_iconv_strdup(const gchar *inbuf,
-                        const gchar *src_code, const gchar *dest_code)
+                        const gchar *isrc_code, const gchar *idest_code)
 {
-       iconv_t cd;
-       const gchar *inbuf_p;
+       /* presumably GLib 2's function handles the conversion details,
+        * whether iconv is sitting below, or something else */
        gchar *outbuf;
-       gchar *outbuf_p;
-       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();
-       if (!dest_code)
-               dest_code = conv_get_current_charset_str();
+       gsize read_len, written_len;
+       gchar *src_code = conv_get_outgoing_charset_str();
+       gchar *dest_code = conv_get_current_charset_str();
+       
+       if (isrc_code)
+               src_code = isrc_code;
+       if (idest_code)
+               dest_code = idest_code;
 
        /* don't convert if current codeset is US-ASCII */
        if (!strcasecmp(dest_code, CS_US_ASCII))
@@ -942,70 +925,19 @@ gchar *conv_iconv_strdup(const gchar *inbuf,
        if (!strcasecmp(src_code, dest_code))
                return g_strdup(inbuf);
 
-       cd = iconv_open(dest_code, src_code);
-       if (cd == (iconv_t)-1)
-               return NULL;
-
-       inbuf_p = inbuf;
-       in_size = strlen(inbuf);
-       in_left = in_size;
-       out_size = (in_size + 1) * 2;
-       outbuf = g_malloc(out_size);
-       outbuf_p = outbuf;
-       out_left = out_size;
-
-#define EXPAND_BUF()                           \
-{                                              \
-       len = outbuf_p - outbuf;                \
-       out_size *= 2;                          \
-       outbuf = g_realloc(outbuf, out_size);   \
-       outbuf_p = outbuf + len;                \
-       out_left = out_size - len;              \
-}
-
-       while ((n_conv = iconv(cd, (ICONV_CONST gchar **)&inbuf_p, &in_left,
-                              &outbuf_p, &out_left)) == (size_t)-1) {
-               if (EILSEQ == errno) {
-                       inbuf_p++;
-                       in_left--;
-                       if (out_left == 0) {
-                               EXPAND_BUF();
-                       }
-                       *outbuf_p++ = SUBST_CHAR;
-                       out_left--;
-               } else if (EINVAL == errno) {
-                       break;
-               } else if (E2BIG == errno) {
-                       EXPAND_BUF();
-               } else {
-                       g_warning("conv_iconv_strdup(): %s\n",
-                                 g_strerror(errno));
-                       break;
-               }
-       }
+       /* FIXME: unchecked inbuf? Can't see at this level. */
+       outbuf = g_convert(inbuf, strlen(inbuf), dest_code, src_code,
+                          &read_len, &written_len, NULL);
 
-       while ((n_conv = iconv(cd, NULL, NULL, &outbuf_p, &out_left)) ==
-              (size_t)-1) {
-               if (E2BIG == errno) {
-                       EXPAND_BUF();
-               } else {
-                       g_warning("conv_iconv_strdup(): %s\n",
-                                 g_strerror(errno));
-                       break;
-               }
-       }
-
-#undef EXPAND_BUF
-
-       len = outbuf_p - outbuf;
-       outbuf = g_realloc(outbuf, len + 1);
-       outbuf[len] = '\0';
-
-       iconv_close(cd);
-
-       return outbuf;
+       if (outbuf == NULL && strcasecmp(src_code, CS_ISO_8859_15)) 
+               /* also try iso-8859-15 */
+               outbuf = conv_iconv_strdup(inbuf, CS_ISO_8859_15, idest_code);
+       if (outbuf == NULL)
+               g_warning(_("Valid locale type set? (Currently: %s to %s)\n"),
+                         src_code, dest_code);
+       
+       return outbuf;                     
 }
-#endif /* HAVE_ICONV */
 
 static const struct {
        CharSet charset;
@@ -1409,15 +1341,6 @@ CharSet conv_get_outgoing_charset(void)
                }
        }
 
-#if !HAVE_ICONV
-       /* encoding conversion without iconv() is only supported
-          on Japanese locale for now */
-       if (out_charset == C_ISO_2022_JP)
-               return out_charset;
-       else
-               return conv_get_current_charset();
-#endif
-
        return out_charset;
 }
 
index 3cdaba8c66b418a28d486009cc68940b4163695f..da29ffd02f2271ac185cad307769cff4e61f6f64 100644 (file)
@@ -4660,8 +4660,8 @@ static void compose_convert_header(gchar *dest, gint len, gchar *src,
        g_return_if_fail(dest != NULL);
 
        if (len < 1) return;
-
-       tmpstr = conv_codeset_strdup(src, CS_UTF_8, conv_get_current_charset_str());
+       
+       tmpstr = conv_codeset_strdup(src, CS_UTF_8, conv_get_outgoing_charset_str());
 
        subst_char(tmpstr, '\n', ' ');
        subst_char(tmpstr, '\r', ' ');