[Xfce4-commits] <postler:master> Handle non-encoded in encoded words and lowercase encoding

Christian Dywan noreply at xfce.org
Sat Jun 26 03:22:05 CEST 2010


Updating branch refs/heads/master
         to e7f9007e6568a605cc675dfb1ba76c6a1bbbb19b (commit)
       from 5c8b02d4b3cdff2e8657e27d6f557a93f0390975 (commit)

commit e7f9007e6568a605cc675dfb1ba76c6a1bbbb19b
Author: Christian Dywan <christian at twotoasts.de>
Date:   Tue Jun 22 20:38:33 2010 +0200

    Handle non-encoded in encoded words and lowercase encoding
    
    An additional test case covers different encoding styles.

 postler/postler-messages.vala |   18 ++++++++++++------
 tests/parsing.vala            |   18 ++++++++++++++++++
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index 1d0a3b3..7f6eab3 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -225,17 +225,21 @@ public class Postler.Messages : Gtk.TreeView {
     }
 
     static string decode_piece (string encoded, out string charset) {
-        if (!(encoded[0] == '=' && encoded[1] == '?'))
+        if (!encoded.contains ("=?"))
             return encoded;
-        int token = 2;
+        int token1 = 0;
+        while (!(encoded[token1] == '=' && encoded[token1 + 1] == '?'))
+            token1++;
+        token1++;
+        int token = token1 + 1;
         while (encoded[token] != '?')
             token++;
-        charset = encoded[2:token].up ();
+        charset = encoded[token1:token].up ();
         /* Encoding aliases */
         if (charset == "KS_C_5601-1987")
             charset = "CP949";
         token++;
-        unichar encoding = encoded[token];
+        unichar encoding = encoded[token].toupper ();
         if (encoding != 'Q' && encoding != 'B')
             return encoded;
         token++;
@@ -253,12 +257,14 @@ public class Postler.Messages : Gtk.TreeView {
         else
             unquoted = pieces[0];
         try {
-            return GLib.convert (unquoted, -1, "UTF-8", charset, null) +
+            return encoded.substring (0, token1 - 1)
+                + GLib.convert (unquoted, -1, "UTF-8", charset, null) +
                 (pieces[1] != null ? pieces[1] : "");
         }
         catch (GLib.ConvertError error) {
             GLib.message (_("Failed to convert \"%s\": %s"), encoded, error.message);
-            return pieces[0] + (pieces[1] != null ? pieces[1] : "");
+            return encoded.substring (0, token1 - 1)
+                + pieces[0] + (pieces[1] != null ? pieces[1] : "");
         }
     }
 
diff --git a/tests/parsing.vala b/tests/parsing.vala
index c1cdb5d..691bb3e 100644
--- a/tests/parsing.vala
+++ b/tests/parsing.vala
@@ -55,10 +55,28 @@ void parsing_headers_mailer () {
     }
 }
 
+const TestCase[] encodeds = {
+    { "=?iso-8859-1?Q?Lila_L=F6ffel?=", "Lila Löffel" },
+    { "=?iso-8859-15?q?S=FCddeutsche?=", "Süddeutsche" },
+    { "=?iso-8859-15?q?S=FCddeutsche_?==?iso-8859-15?q?W=FCrste?=",
+      "Süddeutsche Würste" },
+    { "[Kritiker] =?iso-8859-15?q?S=FCddeutsche_?==?iso-8859-15?q?W=FCrste?=",
+      "[Kritiker] Süddeutsche Würste" }
+};
+
+void parsing_headers_encoded () {
+    string charset;
+    foreach (var encoded in encodeds) {
+        string decoded = Postler.Messages.parse_encoded (encoded.data, out charset);
+        assert_string_equal (decoded, encoded.expected);
+    }
+}
+
 void main (string[] args) {
     Test.init (ref args);
     Test.add_func ("/parsing/headers/address", parsing_headers_address);
     Test.add_func ("/parsing/headers/mailer", parsing_headers_mailer);
+    Test.add_func ("/parsing/headers/encoded", parsing_headers_encoded);
     Test.run ();
 }
 



More information about the Xfce4-commits mailing list