[Xfce4-commits] <postler:master> Always fallback decoded strings to UTF-8
Christian Dywan
noreply at xfce.org
Sat Jul 2 17:08:03 CEST 2011
Updating branch refs/heads/master
to 8d090cf81337fb2d72568e345fa9ac746aa79c25 (commit)
from 60b57d7cca761b2df2fd968f4a0792b7443b4224 (commit)
commit 8d090cf81337fb2d72568e345fa9ac746aa79c25
Author: Christian Dywan <christian at twotoasts.de>
Date: Fri Jul 1 00:15:13 2011 +0200
Always fallback decoded strings to UTF-8
Trying to send erroneously encoded strings via DBus will
abort because GLib.Variant aborts on malformed encoding.
postler/postler-messages.vala | 14 +++++++++++++-
1 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index d277de0..2157d1a 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -48,6 +48,18 @@ public class Postler.Messages : Gtk.TreeView {
selected_message = null;
}
+ static string fallback_to_utf8 (string text) {
+ var fallback = new StringBuilder.sized (text.size () * 2);
+ for (unowned string s = text; s.get_char () != 0 ; s = s.next_char ()) {
+ unichar character = s.get_char ();
+ if (character.iscntrl () || !character.validate ())
+ fallback.append_unichar ('�');
+ else
+ fallback.append_unichar (character);
+ }
+ return fallback.str;
+ }
+
static string escape_text (string text) {
/* Like Markup.escape_text, but including UTF-8 validation */
var escaped = new StringBuilder.sized (text.size () * 2);
@@ -367,7 +379,7 @@ public class Postler.Messages : Gtk.TreeView {
piece = piece.replace ("\nq\n=", "?q?=").replace ("\nQ\n=", "?Q?=");
decoded.append (decode_piece (piece, out charset));
}
- return decoded.str;
+ return fallback_to_utf8 (decoded.str);
}
public void clear () {
More information about the Xfce4-commits
mailing list