[Xfce4-commits] <postler:master> En- and decore mailto string parts and don't use AppInfo

Christian Dywan noreply at xfce.org
Sat Mar 19 01:50:01 CET 2011


Updating branch refs/heads/master
         to b42ea7099b0f6a6c218172e2af2f356041fb8512 (commit)
       from e78b9e7ec5d8c22bca37281b55853be8444a6e65 (commit)

commit b42ea7099b0f6a6c218172e2af2f356041fb8512
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sat Mar 19 01:43:28 2011 +0100

    En- and decore mailto string parts and don't use AppInfo
    
    We need to encode the body in particular to prevent random
    ? and & to be mistaken for mailto string separators.
    
    Another point is to avoid GLib.AppInfo because it apparently
    mangles the encoded arguments.
    
    Fixes: https://bugs.launchpad.net/postler/+bug/734225

 postler/postler-app.vala    |    4 ++--
 postler/postler-bureau.vala |   19 ++++++++++++++-----
 postler/postler-reader.vala |    6 +++---
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/postler/postler-app.vala b/postler/postler-app.vala
index 7697eb1..2469061 100644
--- a/postler/postler-app.vala
+++ b/postler/postler-app.vala
@@ -193,8 +193,8 @@ public class Postler.App : Unique.App {
         if (arg2 != null)
             command += " " + Shell.quote (arg2);
         try {
-            var info = GLib.AppInfo.create_from_commandline (command, "", 0);
-            if (info.launch (null, null))
+            /* Can't use GLib.AppInfo as it would mangle the arguments */
+            if (Process.spawn_command_line_async (command))
                 return true;
         }
         catch (GLib.Error error) {
diff --git a/postler/postler-bureau.vala b/postler/postler-bureau.vala
index 2aa10d3..aa994c5 100644
--- a/postler/postler-bureau.vala
+++ b/postler/postler-bureau.vala
@@ -114,12 +114,21 @@ public class Postler.Bureau : Gtk.Window {
         var clipboard = content.get_clipboard (Gdk.SELECTION_PRIMARY);
         string? selected = null;
         if (content.can_copy_clipboard ())
-            selected = clipboard.wait_for_text ();
+            selected = GLib.Uri.escape_string (clipboard.wait_for_text (), "", true);
 
-        Postler.App.spawn_module ("compose", (recipient != null ? recipient : "")
-            + (prefix != null ? "?subject=" + prefix + content.subject : "")
-            + "&from=" + chosen_from + "&part=" + part.to_string ()
-            + (selected != null ? "&body=" + selected : ""),
+        StringBuilder mailto = new StringBuilder (recipient);
+        char delimiter = '?';
+        if (prefix != null) {
+            mailto.append_printf ("?subject=%s%s", prefix, content.subject);
+            delimiter = '&';
+        }
+        mailto.append_printf ("%cfrom=%s", delimiter, chosen_from);
+        delimiter = '&';
+        mailto.append_printf ("&part=%d", part);
+        if (selected != null)
+            mailto.append_printf ("&body=%s", selected);
+
+        Postler.App.spawn_module ("compose", mailto.str,
             prefix != null ? content.last_location : null);
     }
 
diff --git a/postler/postler-reader.vala b/postler/postler-reader.vala
index c6ffe00..2d91fc0 100644
--- a/postler/postler-reader.vala
+++ b/postler/postler-reader.vala
@@ -128,14 +128,14 @@ public class Postler.Reader {
                 if (mailto.has_prefix ("mailto:"))
                     mailto = mailto.substring (7, -1);
 
-                    string[] fields = Soup.URI.decode (mailto).split_set ("?&");
+                    string[] fields = mailto.split_set ("?&");
                     foreach (var field in fields) {
                         string[] pieces = field.split ("=");
                         bool success;
                         if (pieces[0] != null && pieces[1] != null)
-                            success = composer.add_field (pieces[0], pieces[1]);
+                            success = composer.add_field (pieces[0], Soup.URI.decode (pieces[1]));
                         else
-                            success = composer.add_field ("to", field);
+                            success = composer.add_field ("to", Soup.URI.decode (field));
                         if (!success)
                             GLib.warning (_("Invalid field \"%s\" was ignored."),
                                           pieces[1] != null ? pieces[0] : field);



More information about the Xfce4-commits mailing list