Index: pan-glib-extensions.c
===================================================================
RCS file: /cvs/gnome/pan/pan/base/pan-glib-extensions.c,v
retrieving revision 1.45
diff -u -u -r1.45 pan-glib-extensions.c
--- pan-glib-extensions.c	27 Mar 2003 13:58:12 -0000	1.45
+++ pan-glib-extensions.c	8 Apr 2003 22:08:33 -0000
@@ -28,6 +28,9 @@
 #include <glib.h>
 
 #include <gmime/gmime-charset.h>
+#include <gmime/gmime-filter-charset.h>
+#include <gmime/gmime-stream-filter.h>
+#include <gmime/gmime-stream-mem.h>
 #include <gmime/gmime-utils.h>
 
 #include <iconv.h>
@@ -846,6 +849,51 @@
 	return retval;
 }
 
+static char*
+g_mime_charset_strdup (const char     * to_charset,
+                       const char     * from_charset,
+                       const char     * text,
+                       int              text_len)
+{
+	char * retval;
+	gssize out_len;
+	GMimeStream * in_stream;
+	GMimeStream * in_stream_filter;
+	GMimeFilter * charset_filter;
+	GMimeStream * out_stream;
+	GByteArray * byte_array;
+
+	/* set up an input stream with the desired charset filter */
+	in_stream = g_mime_stream_mem_new_with_buffer (text, text_len);
+	charset_filter = g_mime_filter_charset_new (from_charset, to_charset);
+	in_stream_filter = g_mime_stream_filter_new_with_stream (in_stream);
+	g_mime_stream_filter_add (GMIME_STREAM_FILTER(in_stream_filter), charset_filter);
+
+	/* set up an output stream attached to a byte array */
+	byte_array = g_byte_array_new ();
+	out_stream = g_mime_stream_mem_new ();
+	g_mime_stream_mem_set_byte_array (GMIME_STREAM_MEM(out_stream), byte_array);
+
+	/* write the input stream to the output stream */
+	out_len = g_mime_stream_write_to_stream (in_stream_filter, out_stream);
+
+	/* if the write was successful, zero-terminate the string and return it. */
+	if (out_len < 0)
+		retval = NULL;
+	else {
+		g_byte_array_append (byte_array, "", 1);
+		retval = byte_array->data;
+		g_byte_array_free (byte_array, FALSE);
+	}
+
+	/* cleanup */
+	g_object_unref (G_OBJECT(out_stream));
+	g_object_unref (G_OBJECT(in_stream_filter));
+	g_object_unref (G_OBJECT(in_stream));
+
+	return retval;
+}
+
 char*
 pan_body_to_utf8 (GMimePart     * part,
                   const char    * default_charset)
@@ -865,19 +913,13 @@
 	/* use the part's content-type charset, if it's got one */
 	if (retval == NULL) {
 		const char * charset = g_mime_object_get_content_type_parameter (GMIME_OBJECT (part), "charset");
-		if (is_nonempty_string (charset)) {
-			iconv_t cd = g_mime_iconv_open ("UTF-8", charset);
-			retval = g_mime_iconv_strndup (cd, content, content_len);
-			g_mime_iconv_close (cd);
-		}
+		if (is_nonempty_string (charset))
+			retval = g_mime_charset_strdup ("UTF-8", charset, content, content_len);
 	}
 
 	/* try the group's default charset */
-	if (retval==NULL && is_nonempty_string (default_charset)) {
-		iconv_t cd = g_mime_iconv_open ("UTF-8", default_charset);
-		retval = g_mime_iconv_strndup (cd, content, content_len);
-		g_mime_iconv_close (cd);
-	}
+	if (retval==NULL && is_nonempty_string (default_charset))
+		retval = g_mime_charset_strdup ("UTF-8", default_charset, content, content_len);
 
 	/* otherwise just use the text and hope for the best */
 	if (retval == NULL) {
