[Xfce4-commits] <postler:master> Remove double or single quotes around names

Christian Dywan noreply at xfce.org
Sun May 30 05:34:02 CEST 2010


Updating branch refs/heads/master
         to 5233fc5d8591e625eecbd17caa97cf9bb9eb22ab (commit)
       from 8bbd9b49ee148b16e83ad843c086557aad2df017 (commit)

commit 5233fc5d8591e625eecbd17caa97cf9bb9eb22ab
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sun May 30 05:05:08 2010 +0200

    Remove double or single quotes around names

 postler/postler-messages.vala |   15 ++++++++++++---
 tests/parsing.vala            |    4 +++-
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index 61d6301..70734b4 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -157,15 +157,24 @@ public class Postler.Messages : Gtk.TreeView {
         while (address[lower] != '<')
             lower--;
 
-        /* TODO: Strip double quotes */
-
         string recipient = address.slice (lower + 1, greater);
         if (lower == 0)
             return { recipient, recipient };
         /* TODO: Parse multiple addresses */
         if (">" in recipient)
             return { recipient, recipient };
-        return { address.slice (0, lower - 1), recipient };
+
+        /* Remove double or single quotes around the name */
+        long quote_open = 0;
+        long quote_close = lower - 1;
+        if (address[quote_open] == '\'' || address[quote_open] == '"') {
+            quote_open++;
+            quote_close--;
+            if (address[quote_close] == '\'' || address[quote_close] == '"')
+                quote_close = quote_close - 1;
+        }
+
+        return { address.substring (quote_open, quote_close), recipient };
     }
 
     public void clear () {
diff --git a/tests/parsing.vala b/tests/parsing.vala
index aee9a35..c1cdb5d 100644
--- a/tests/parsing.vala
+++ b/tests/parsing.vala
@@ -25,7 +25,9 @@ const TestCase[] addresses = {
     { "Klaus Kaufmann <klausk at heim.at>", "Klaus Kaufmann klausk at heim.at" },
     { "Klaus", null },
     { "kaufmann at heim.at", null },
-    { "<kaufmann at heim.at>", "kaufmann at heim.at kaufmann at heim.at" }
+    { "<kaufmann at heim.at>", "kaufmann at heim.at kaufmann at heim.at" },
+    { "'Klaus' <klaus at heim.at>", "Klaus klaus at heim.at" },
+    { "\"Klaus\" <klaus at heim.at>", "Klaus klaus at heim.at" }
 };
 
 void parsing_headers_address () {



More information about the Xfce4-commits mailing list