[Xfce4-commits] <postler:master> Move replying logic into content and apply to replies

Christian Dywan noreply at xfce.org
Thu Jun 30 23:38:02 CEST 2011


Updating branch refs/heads/master
         to 7723d8b5ccbd7c1b78ca1e4c698f3fd75561020a (commit)
       from 9caec846fe7f71a842137ab2d22ca8c338b50535 (commit)

commit 7723d8b5ccbd7c1b78ca1e4c698f3fd75561020a
Author: Christian Dywan <christian at twotoasts.de>
Date:   Thu Jun 30 23:34:57 2011 +0200

    Move replying logic into content and apply to replies

 postler/postler-bureau.vala  |   40 ++--------------------
 postler/postler-content.vala |   74 ++++++++++++++++++++++++++++-------------
 2 files changed, 54 insertions(+), 60 deletions(-)

diff --git a/postler/postler-bureau.vala b/postler/postler-bureau.vala
index ac86713..3fcd54f 100644
--- a/postler/postler-bureau.vala
+++ b/postler/postler-bureau.vala
@@ -108,40 +108,8 @@ public class Postler.Bureau : Gtk.Window {
         client.receive ();
     }
 
-    void compose_message (string? prefix=null, string? recipient=null, int part=0) {
-        string? chosen_from = content.choose_from ();
-        if (chosen_from == null) {
-            if (messages.account_info != null)
-                chosen_from = messages.account_info.address;
-            else
-                chosen_from = "";
-        }
-
-        var clipboard = content.get_clipboard (Gdk.SELECTION_PRIMARY);
-        string? selected = null;
-        if (content.can_copy_clipboard ())
-            selected = GLib.Uri.escape_string (clipboard.wait_for_text (), "", true);
-
-        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);
-            mailto.append_printf ("&in-reply-to=%s", content.message_id);
-        }
-
-        Postler.App.spawn_module ("compose", mailto.str,
-            prefix != null ? content.last_location : null);
-    }
-
     void action_message_new () {
-        compose_message ();
+        content.compose_message ();
     }
 
     unowned string? list_or_sender (string reply_to) {
@@ -183,16 +151,16 @@ public class Postler.Bureau : Gtk.Window {
         unowned string? reply = list_or_sender (content.message.reply_to
                                              ?? content.message.sender);
         if (reply != null)
-            compose_message ("Re: ", reply, content.current_part_index);
+            content.compose_message ("Re: ", reply);
     }
 
     void action_message_reply_all () {
         string reply = content.message.recipients + "," + content.message.sender;
-        compose_message ("Re: ", reply, content.current_part_index);
+        content.compose_message ("Re: ", reply);
     }
 
     void action_message_forward () {
-        compose_message ("Fw: ", null, content.current_part_index);
+        content.compose_message ("Fw: ", null);
     }
 
     void action_message_unread () {
diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index c99f7f8..c0a934d 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -207,9 +207,13 @@ public class Postler.Content : WebKit.WebView {
         return "<a href=\"%s\">%s</a>".printf (uri, markup);
     }
 
-    internal static string linkify_address (string addresses, string? arguments, bool inherit=false) {
+    internal static string linkify_address (string mailto, bool inherit=false) {
         var linkified = new StringBuilder ();
 
+        string[] parts = mailto.split ("?", 2);
+        string addresses = parts[0];
+        string arguments = parts[1] != null ? ("?" + parts[1]) : "";
+
         int count = 0;
         foreach (string address in addresses.split (",")) {
             if (address == "")
@@ -226,8 +230,7 @@ public class Postler.Content : WebKit.WebView {
                 continue;
             if (linkified.len > 0)
                linkified.append (", ");
-            linkified.append_printf ("<a href=\"mailto:%s\"",
-                quoted + (arguments != null ? arguments : ""));
+            linkified.append_printf ("<a href=\"mailto:%s%s\"", quoted, arguments);
             if (inherit)
                  linkified.append (" style=\"color:inherit\"");
             linkified.append ("\" title=\"" + quoted + "\">" + name + "</a>");
@@ -616,20 +619,49 @@ public class Postler.Content : WebKit.WebView {
         return selected_account != null ? (selected_account.address ?? "") : "";
     }
 
-    public string? choose_from () {
+    public string? choose_from (Message the_message) {
         /* See if recipient is among the accounts, otherwise pick a fallback */
-        string? recipient = message.get_field ("to");
+        string? recipient = the_message.get_field ("to");
         if (recipient != null) {
             string from = Postler.Contact.address_from_string (recipient);
             var accounts = new Accounts ();
-            foreach (var info in accounts.get_infos ())
-                if (info.address != null && from in info.address)
-                    return from;
+            foreach (var info in accounts.get_infos ()) {
+                foreach (string address in info.address.split (",")) {
+                    if (Contact.equal (from, address))
+                        return from;
+                }
+            }
         }
-        if (selected_account == null || selected_account.address == null)
-            return null;
+        if (selected_account != null && selected_account.address != null)
+            return selected_account.address.split (",")[0];
+
+        return null;
+    }
+
+    public string reply_uri (Message the_message, string? prefix=null, string? recipients=null) {
+        string chosen_from = choose_from (the_message);
+        var clipboard = get_clipboard (Gdk.SELECTION_PRIMARY);
+        string? selected = null;
+        if (can_copy_clipboard ())
+            selected = GLib.Uri.escape_string (clipboard.wait_for_text (), "", true);
+        StringBuilder mailto = new StringBuilder (recipients ?? the_message.sender);
+        char delimiter = '?';
+        if (prefix != null) {
+            mailto.append_printf ("?subject=%s%s", prefix, the_message.subject);
+            delimiter = '&';
+        }
+        if (chosen_from != null)
+            mailto.append_printf ("%cfrom=%s", delimiter, chosen_from);
+        delimiter = '&';
+        mailto.append_printf ("&in-reply-to=%s", the_message.id);
+        if (selected != null)
+            mailto.append_printf ("&body=%s", selected);
+        return mailto.str;
+    }
 
-        return selected_account.address.split (",")[0];
+    public void compose_message (string? prefix=null, string? recipients=null) {
+        string mailto = reply_uri (message, prefix, recipients);
+        Postler.App.spawn_module ("compose", mailto, prefix != null ? last_location : null);
     }
 
     public async bool display (Message the_message, AccountInfo? account_info=null) {
@@ -731,14 +763,13 @@ public class Postler.Content : WebKit.WebView {
                     linkify_icon ("contact-new", _("Add contact"), "contact:%s:%s".printf (
                         sender_name, html_escape (Contact.address_from_string (child.sender))))));
                 }
-                /* FIXME: Move Bureau.compose_message () here */
                 reply_chunk.append ("""
                     <div class="actions">
-                    <a href="mailto:%s?subject=Re: %s" class="button">%s</a>
-                    <a href="mailto:%s?subject=Fw: %s" class="button">%s</a></div>
+                    <a href="mailto:%s" class="button">%s</a>
+                    <a href="mailto:%s" class="button">%s</a></div>
                     """.printf (
-                    child.sender, child.subject, _("Reply"),
-                    child.sender, child.subject, _("Forward")));
+                    reply_uri (child, "Re: "), _("Reply"),
+                    reply_uri (child, "Fw: "), _("Forward")));
 
                 string reply_markup;
                 if (sender_name == _("You"))
@@ -747,7 +778,7 @@ public class Postler.Content : WebKit.WebView {
                     reply_markup = content_template.replace ("%message%", reply_chunk.str);
                 reply_markup = reply_markup.replace ("\"%sender%\"", ("\"" + child.sender + "\""));
                 /* Do inherit colors, to match Adium and Empathy */
-                reply_markup = reply_markup.replace ("%sender%", linkify_address (child.sender, null, true));
+                reply_markup = reply_markup.replace ("%sender%", linkify_address (child.sender, true));
                 reply_markup = reply_markup.replace ("%time{%X}%", format_date (child.date));
                 string avatar_uri = "Incoming/buddy_icon.png";
                 if (child.avatar != null && child.avatar.get_path () != null) {
@@ -800,17 +831,13 @@ public class Postler.Content : WebKit.WebView {
                 message = thread.nth_data (0);
             last_location = message.get_path ();
             subject = message.subject;
-            string arguments = "?subject=Re: " + subject;
-            string? chosen_from = choose_from ();
-            if (chosen_from != null)
-                arguments += "?from=" + html_escape (chosen_from);
             list_post = message.get_field ("list-post");
             if (list_post != null)
                 list_post = Postler.Contact.address_from_string (list_post);
             list_unsubscribe = message.get_field ("list-unsubscribe");
             if (list_unsubscribe != null) {
                 list_unsubscribe = Postler.Contact.address_from_string (list_unsubscribe);
-                list_unsubscribe = linkify_address (list_unsubscribe, null);
+                list_unsubscribe = linkify_address (list_unsubscribe);
             }
 
             /* Emoticons */
@@ -847,8 +874,7 @@ public class Postler.Content : WebKit.WebView {
                          style_sheet.replace ("ButtonText", color_to_rgb (style.fg[state])),
                          content_stylesheet,
                          message.subject,
-                         /* FIXME: Merge all recipients here? */
-                         linkify_address (message.recipients, arguments),
+                         linkify_address (reply_uri (message, "Re: ", message.recipients)),
                          reply != null || message.organization != null
                                        || message.application != null
                                        || list_unsubscribe != null



More information about the Xfce4-commits mailing list