aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2010-01-08 23:29:42 +0800
committerMilan Crha <mcrha@redhat.com>2010-01-08 23:29:42 +0800
commitabaecf816e8b9f2c0afc754223c75e8634702b4c (patch)
treec88e4e571259683cfe0c2bee7d30f8676f138b02
parent79741ccd3f90c4c8aab672b508606d63c3899584 (diff)
downloadgsoc2013-evolution-abaecf816e8b9f2c0afc754223c75e8634702b4c.tar.gz
gsoc2013-evolution-abaecf816e8b9f2c0afc754223c75e8634702b4c.tar.zst
gsoc2013-evolution-abaecf816e8b9f2c0afc754223c75e8634702b4c.zip
Bug #606340 - Crash on non-utf8 letter in mail folder name
-rw-r--r--e-util/e-unicode.c26
-rw-r--r--e-util/e-unicode.h1
-rw-r--r--plugins/itip-formatter/itip-view.c46
-rw-r--r--shell/e-shell-sidebar.c5
4 files changed, 44 insertions, 34 deletions
diff --git a/e-util/e-unicode.c b/e-util/e-unicode.c
index 88f6d0605a..2e8969f718 100644
--- a/e-util/e-unicode.c
+++ b/e-util/e-unicode.c
@@ -211,6 +211,32 @@ e_utf8_from_locale_string_sized (const gchar *string, gint bytes)
}
/**
+ * e_utf8_ensure_valid:
+ * @string String to make valid UTF-8.
+ *
+ * Ensures the returned string will be valid UTF-8 string, thus gtk functions expecting
+ * only valid UTF-8 texts will not crash.
+ *
+ * Returned pointer should be freed with g_free.
+ **/
+gchar *
+e_utf8_ensure_valid (const gchar *string)
+{
+ gchar *res = g_strdup (string), *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;
+}
+
+/**
* e_unichar_to_utf8:
* @c: a ISO10646 character code
* @outbuf: output buffer, must have at least 6 bytes of space.
diff --git a/e-util/e-unicode.h b/e-util/e-unicode.h
index b22c5c988b..2979510aa6 100644
--- a/e-util/e-unicode.h
+++ b/e-util/e-unicode.h
@@ -47,6 +47,7 @@ gchar *e_utf8_to_charset_string_sized (const gchar *char
gint bytes);
gchar *e_utf8_from_locale_string_sized (const gchar *string,
gint bytes);
+gchar *e_utf8_ensure_valid (const gchar *string);
/*
* These are simple wrappers that save us some typing
*/
diff --git a/plugins/itip-formatter/itip-view.c b/plugins/itip-formatter/itip-view.c
index 6fd70cb1e9..9b240f484a 100644
--- a/plugins/itip-formatter/itip-view.c
+++ b/plugins/itip-formatter/itip-view.c
@@ -41,6 +41,7 @@
#include <mail/em-format-html.h>
#include <libedataserver/e-account-list.h>
#include <e-util/e-util.h>
+#include <e-util/e-unicode.h>
#include <calendar/gui/itip-utils.h>
#include "itip-view.h"
@@ -1246,25 +1247,6 @@ itip_view_get_item_type (ItipView *view)
return priv->type;
}
-/* ensures the returned text will be valid UTF-8 text, thus gtk functions expecting
- only valid UTF-8 texts will not crash. Returned pointer should be freed with g_free. */
-static gchar *
-ensure_utf8 (const gchar *text)
-{
- gchar *res = g_strdup (text), *p;
-
- if (!text)
- return res;
-
- p = res;
- while (!g_utf8_validate (p, -1, (const gchar **) &p)) {
- /* make all invalid characters appear as question marks */
- *p = '?';
- }
-
- return res;
-}
-
void
itip_view_set_organizer (ItipView *view, const gchar *organizer)
{
@@ -1278,7 +1260,7 @@ itip_view_set_organizer (ItipView *view, const gchar *organizer)
if (priv->organizer)
g_free (priv->organizer);
- priv->organizer = ensure_utf8 (organizer);
+ priv->organizer = e_utf8_ensure_valid (organizer);
set_sender_text (view);
}
@@ -1309,7 +1291,7 @@ itip_view_set_organizer_sentby (ItipView *view, const gchar *sentby)
if (priv->organizer_sentby)
g_free (priv->organizer_sentby);
- priv->organizer_sentby = ensure_utf8 (sentby);
+ priv->organizer_sentby = e_utf8_ensure_valid (sentby);
set_sender_text (view);
}
@@ -1340,7 +1322,7 @@ itip_view_set_attendee (ItipView *view, const gchar *attendee)
if (priv->attendee)
g_free (priv->attendee);
- priv->attendee = ensure_utf8 (attendee);
+ priv->attendee = e_utf8_ensure_valid (attendee);
set_sender_text (view);
}
@@ -1371,7 +1353,7 @@ itip_view_set_attendee_sentby (ItipView *view, const gchar *sentby)
if (priv->attendee_sentby)
g_free (priv->attendee_sentby);
- priv->attendee_sentby = ensure_utf8 (sentby);
+ priv->attendee_sentby = e_utf8_ensure_valid (sentby);
set_sender_text (view);
}
@@ -1402,7 +1384,7 @@ itip_view_set_proxy (ItipView *view, const gchar *proxy)
if (priv->proxy)
g_free (priv->proxy);
- priv->proxy = ensure_utf8 (proxy);
+ priv->proxy = e_utf8_ensure_valid (proxy);
set_sender_text (view);
}
@@ -1433,7 +1415,7 @@ itip_view_set_delegator (ItipView *view, const gchar *delegator)
if (priv->delegator)
g_free (priv->delegator);
- priv->delegator = ensure_utf8 (delegator);
+ priv->delegator = e_utf8_ensure_valid (delegator);
set_sender_text (view);
}
@@ -1464,7 +1446,7 @@ itip_view_set_summary (ItipView *view, const gchar *summary)
if (priv->summary)
g_free (priv->summary);
- priv->summary = summary ? g_strstrip (ensure_utf8 (summary)) : NULL;
+ priv->summary = summary ? g_strstrip (e_utf8_ensure_valid (summary)) : NULL;
set_summary_text (view);
}
@@ -1495,7 +1477,7 @@ itip_view_set_location (ItipView *view, const gchar *location)
if (priv->location)
g_free (priv->location);
- priv->location = location ? g_strstrip (ensure_utf8 (location)) : NULL;
+ priv->location = location ? g_strstrip (e_utf8_ensure_valid (location)) : NULL;
set_location_text (view);
}
@@ -1526,7 +1508,7 @@ itip_view_set_status (ItipView *view, const gchar *status)
if (priv->status)
g_free (priv->status);
- priv->status = status ? g_strstrip (ensure_utf8 (status)) : NULL;
+ priv->status = status ? g_strstrip (e_utf8_ensure_valid (status)) : NULL;
set_status_text (view);
}
@@ -1557,7 +1539,7 @@ itip_view_set_comment (ItipView *view, const gchar *comment)
if (priv->comment)
g_free (priv->comment);
- priv->comment = comment ? g_strstrip (ensure_utf8 (comment)) : NULL;
+ priv->comment = comment ? g_strstrip (e_utf8_ensure_valid (comment)) : NULL;
set_comment_text (view);
}
@@ -1588,7 +1570,7 @@ itip_view_set_description (ItipView *view, const gchar *description)
if (priv->description)
g_free (priv->description);
- priv->description = description ? g_strstrip (ensure_utf8 (description)) : NULL;
+ priv->description = description ? g_strstrip (e_utf8_ensure_valid (description)) : NULL;
set_description_text (view);
}
@@ -1702,7 +1684,7 @@ itip_view_add_upper_info_item (ItipView *view, ItipViewInfoItemType type, const
item = g_new0 (ItipViewInfoItem, 1);
item->type = type;
- item->message = ensure_utf8 (message);
+ item->message = e_utf8_ensure_valid (message);
item->id = priv->next_info_item_id++;
priv->upper_info_items = g_slist_append (priv->upper_info_items, item);
@@ -1797,7 +1779,7 @@ itip_view_add_lower_info_item (ItipView *view, ItipViewInfoItemType type, const
item = g_new0 (ItipViewInfoItem, 1);
item->type = type;
- item->message = ensure_utf8 (message);
+ item->message = e_utf8_ensure_valid (message);
item->id = priv->next_info_item_id++;
priv->lower_info_items = g_slist_append (priv->lower_info_items, item);
diff --git a/shell/e-shell-sidebar.c b/shell/e-shell-sidebar.c
index 517999bad5..5701321f24 100644
--- a/shell/e-shell-sidebar.c
+++ b/shell/e-shell-sidebar.c
@@ -22,6 +22,7 @@
#include "e-shell-sidebar.h"
#include <e-util/e-binding.h>
+#include <e-util/e-unicode.h>
#include <shell/e-shell-view.h>
#define E_SHELL_SIDEBAR_GET_PRIVATE(obj) \
@@ -604,7 +605,7 @@ e_shell_sidebar_set_primary_text (EShellSidebar *shell_sidebar,
g_return_if_fail (E_IS_SHELL_SIDEBAR (shell_sidebar));
g_free (shell_sidebar->priv->primary_text);
- shell_sidebar->priv->primary_text = g_strdup (primary_text);
+ shell_sidebar->priv->primary_text = e_utf8_ensure_valid (primary_text);
gtk_widget_queue_resize (GTK_WIDGET (shell_sidebar));
g_object_notify (G_OBJECT (shell_sidebar), "primary-text");
@@ -650,7 +651,7 @@ e_shell_sidebar_set_secondary_text (EShellSidebar *shell_sidebar,
g_return_if_fail (E_IS_SHELL_SIDEBAR (shell_sidebar));
g_free (shell_sidebar->priv->secondary_text);
- shell_sidebar->priv->secondary_text = g_strdup (secondary_text);
+ shell_sidebar->priv->secondary_text = e_utf8_ensure_valid (secondary_text);
gtk_widget_queue_resize (GTK_WIDGET (shell_sidebar));
g_object_notify (G_OBJECT (shell_sidebar), "secondary-text");