[Xfce4-commits] <postler:master> Unify quoted printable decoding in one place

Christian Dywan noreply at xfce.org
Sun Jan 23 23:32:03 CET 2011


Updating branch refs/heads/master
         to 5c0e886cac32d4483034f8cc98a7ecf984ade617 (commit)
       from 1ce3388fd583950a5e1a94abe5eda1dfea561c40 (commit)

commit 5c0e886cac32d4483034f8cc98a7ecf984ade617
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sun Jan 23 23:24:56 2011 +0100

    Unify quoted printable decoding in one place

 postler/postler-content.vala  |   11 +++++++++--
 postler/postler-messages.vala |   26 ++++----------------------
 2 files changed, 13 insertions(+), 24 deletions(-)

diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index 9112909..cb34f95 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -369,12 +369,19 @@ public class Postler.Content : WebKit.WebView {
         "([a-zA-Z0-9.\\-]+@[a-zA-Z0-9.\\-]+[a-zA-Z0-9.]+)"
     };
 
+    static bool evaluate_hex (GLib.MatchInfo     match_info,
+                              GLib.StringBuilder result) {
+        string match = "0x" + match_info.fetch (2);
+        result.append_printf ("%c", (int)match.to_ulong (null));
+        return false;
+    }
+
     internal static string quoted_printable_decode (string quoted) {
         /* =20 is not hex-encoded, to faciliate quote handling */
         string unquoted = quoted.replace ("_", " ").replace ("=20", " ");
         try {
             var regex = new GLib.Regex ("([=]([0-9A-F][0-9A-F]))");
-            return regex.replace (unquoted, -1, 0, "&#x\\2;");
+            return regex.replace_eval (unquoted, -1, 0, 0, evaluate_hex);
         }
         catch (GLib.RegexError error) {
             GLib.critical (_("Failed to decode string \"%s\": %s"),
@@ -844,7 +851,7 @@ public class Postler.Content : WebKit.WebView {
                       && mime_type_is_text (message_part.mime_type))
                     line = line != "" ? (string)GLib.Base64.decode (line) : "";
                 try {
-                    if (charset != null)
+                    if (charset != null && charset != "UTF-8")
                         line = GLib.convert (line, -1, "UTF-8", charset, null);
                 }
                 catch (GLib.ConvertError error) { }
diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index 2d058aa..f65f976 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -333,26 +333,6 @@ public class Postler.Messages : Gtk.TreeView {
         delete_selected ();
     }
 
-    static bool evaluate_hex (GLib.MatchInfo     match_info,
-                              GLib.StringBuilder result) {
-        string match = "0x" + match_info.fetch (2);
-        result.append_printf ("%c", (int)match.to_ulong (null));
-        return false;
-    }
-
-    internal static string quoted_printable_decode (string quoted) {
-        string unquoted = quoted.replace (" =", " ").replace ("_", " ");
-        try {
-            var regex = new GLib.Regex ("([=]([0-9A-F][0-9A-F]))");
-            return regex.replace_eval (unquoted, -1, 0, 0, evaluate_hex);
-        }
-        catch (GLib.RegexError error) {
-            GLib.critical (_("Failed to decode string \"%s\": %s"),
-                           unquoted, error.message);
-        }
-        return unquoted;
-    }
-
     static string decode_piece (string encoded, out string charset) {
         if (!encoded.contains ("=?"))
             return encoded;
@@ -380,8 +360,10 @@ public class Postler.Messages : Gtk.TreeView {
         if (pieces == null || pieces[0] == null)
             return encoded;
         string unquoted;
-        if (encoding == 'Q')
-            unquoted = quoted_printable_decode (pieces[0]);
+        if (encoding == 'Q') {
+            unquoted = pieces[0].replace (" =", " ");
+            unquoted = Postler.Content.quoted_printable_decode (unquoted);
+        }
         else if (encoding == 'B') 
             unquoted = (string)GLib.Base64.decode (pieces[0]);
         else



More information about the Xfce4-commits mailing list