** Fix for bug #552986
authorMilan Crha <mcrha@redhat.com>
Tue, 9 Dec 2008 16:44:48 +0000 (16:44 +0000)
committerMilan Crha <mcrha@src.gnome.org>
Tue, 9 Dec 2008 16:44:48 +0000 (16:44 +0000)
2008-12-09  Milan Crha  <mcrha@redhat.com>

** Fix for bug #552986

* camel/camel-utf8.h: (camel_utf8_make_valid):
* camel/camel-utf8.c: (camel_utf8_make_valid): New utility function.

* camel/providers/pop3/camel-pop3-store.c: (pop3_connect):
Ensure error description is valid UTF-8 text before using it.

svn path=/trunk/; revision=9818

camel/ChangeLog
camel/camel-utf8.c
camel/camel-utf8.h
camel/providers/pop3/ChangeLog
camel/providers/pop3/camel-pop3-store.c

index dc44e14..01992d5 100644 (file)
@@ -1,3 +1,10 @@
+2008-12-09  Milan Crha  <mcrha@redhat.com>
+
+       ** Part of fix for bug #552986
+
+       * camel-utf8.h: (camel_utf8_make_valid):
+       * camel-utf8.c: (camel_utf8_make_valid): New utility function.
+
 2008-12-08  Jeff Cai <jeff.cai@sun.com>
 
        * camel-db.c: (camel_db_select):
index 1ce11a5..208f51e 100644 (file)
@@ -399,3 +399,27 @@ char *camel_ucs2_utf8(const char *ptr)
 
        return out;
 }
+
+/**
+ * camel_utf8_make_valid:
+ * @text: 
+ *
+ * Ensures the returned text will be valid UTF-8 string, with incorrect letters
+ * changed to question marks. Returned pointer should be freed with g_free.
+ **/
+char *
+camel_utf8_make_valid (const char *text)
+{
+       gchar *res = g_strdup (text), *p;
+
+       if (!res)
+               return res;
+
+       p = res;
+       while (!g_utf8_validate (p, -1, (const gchar **) &p)) {
+               /* make all invalid characters appear as question marks */
+               *p = '?';
+       }
+
+       return res;
+}
index 7ab5229..a67ff85 100644 (file)
@@ -40,6 +40,9 @@ char *camel_utf8_utf7(const char *ptr);
 char *camel_utf8_ucs2(const char *ptr);
 char *camel_ucs2_utf8(const char *ptr);
 
+/* make valid utf8 string */
+char *camel_utf8_make_valid (const char *text);
+
 G_END_DECLS
 
 #endif /* ! _CAMEL_UTF8_H */
index 35213db..44cfd1d 100644 (file)
@@ -1,3 +1,10 @@
+2008-12-09  Milan Crha  <mcrha@redhat.com>
+
+       ** Fix for bug #552986
+
+       * camel-pop3-store.c: (pop3_connect):
+       Ensure error description is valid UTF-8 text before using it.
+
 2008-10-02  Jeffrey Stedfast  <fejj@novell.com>
 
        * camel-pop3-store.c (pop3_try_authenticate): Return -1 if we fail
index 77b74c7..71fb9e4 100644 (file)
@@ -50,6 +50,7 @@
 #include "camel-tcp-stream-raw.h"
 #include "camel-tcp-stream.h"
 #include "camel-url.h"
+#include "camel-utf8.h"
 
 #ifdef HAVE_SSL
 #include "camel-tcp-stream-ssl.h"
@@ -610,7 +611,9 @@ pop3_connect (CamelService *service, CamelException *ex)
                
                /* we only re-prompt if we failed to authenticate, any other error and we just abort */
                if (status == 0 && camel_exception_get_id (ex) == CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE) {
-                       errbuf = g_markup_printf_escaped ("%s\n\n", camel_exception_get_description (ex));
+                       char *tmp = camel_utf8_make_valid (camel_exception_get_description (ex));
+                       errbuf = g_markup_printf_escaped ("%s\n\n", tmp);
+                       g_free (tmp);
                        camel_exception_clear (ex);
 
                        camel_session_forget_password (session, service, NULL, "password", ex);