[Xfce4-commits] <postler:master> Implement quoting of a message for reply

Christian Dywan noreply at xfce.org
Mon Jun 21 20:12:10 CEST 2010


Updating branch refs/heads/master
         to 8e59981845b5723a954273ad3885fa2903f1c56e (commit)
       from 211893923ce725d001f9a44adedca50b13658d64 (commit)

commit 8e59981845b5723a954273ad3885fa2903f1c56e
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sun Jun 20 20:24:41 2010 +0200

    Implement quoting of a message for reply

 postler/postler-app.vala      |    7 ++++-
 postler/postler-bureau.vala   |    2 +-
 postler/postler-composer.vala |   14 ++++-------
 postler/postler-content.vala  |   49 ++++++++++++++++++++++++++++++++++++++++-
 postler/postler-reader.vala   |    6 +++++
 5 files changed, 65 insertions(+), 13 deletions(-)

diff --git a/postler/postler-app.vala b/postler/postler-app.vala
index ece74d4..5e19ec8 100644
--- a/postler/postler-app.vala
+++ b/postler/postler-app.vala
@@ -146,8 +146,11 @@ public class Postler.App : Unique.App {
         return true;
     }
 
-    public static bool spawn_module (string name, string location) {
-        string command = argv0 + " --module " + name + " '" + location + "'";
+    public static bool spawn_module (string name, string parameter1,
+        string? parameter2=null) {
+        string command = argv0 + " --module " + name + " '" + parameter1 + "'";
+        if (parameter2 != null)
+            command += " '" + parameter2 + "'";
         try {
             var info = GLib.AppInfo.create_from_commandline (command, "", 0);
             if (info.launch (null, null))
diff --git a/postler/postler-bureau.vala b/postler/postler-bureau.vala
index d2665d3..9a6427f 100644
--- a/postler/postler-bureau.vala
+++ b/postler/postler-bureau.vala
@@ -108,7 +108,7 @@ public class Postler.Bureau : Gtk.Window {
 
         Postler.App.spawn_module ("compose", (recipient != null ? recipient : "")
             + (prefix != null ? "?subject=" + prefix + content.subject : "")
-            + "&from=" + sender);
+            + "&from=" + sender, content.last_location);
     }
 
     void action_message_new () {
diff --git a/postler/postler-composer.vala b/postler/postler-composer.vala
index 5529635..81efdfb 100644
--- a/postler/postler-composer.vala
+++ b/postler/postler-composer.vala
@@ -26,6 +26,8 @@ public class Postler.Composer : Gtk.Window {
     Gtk.Entry entry_copy;
     Gtk.Entry entry_subject;
 
+    public string subject { get { return entry_subject.text; } }
+
     const string ui_markup = """
         <ui>
             <menubar>
@@ -270,16 +272,10 @@ public class Postler.Composer : Gtk.Window {
             settings.set ("enable-spell-checking", true,
                           "spell-checking-languages", languages, null);
         }
+    }
 
-        string body = "";
-        try {
-            string signature = "";
-            GLib.FileUtils.get_contents (Environment.get_home_dir () + "/.signature",
-                                         out signature);
-            body += "\n\n--\n" + signature;
-        } catch (GLib.FileError error) { }
-        content.load_string (body,
-            "text/plain", "UTF-8", "about:blank");
+    public bool prepare_reply (string? location=null, bool quote=false) {
+        return content.prepare_reply (location, quote);
     }
 
     public bool add_field (string field, string data) {
diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index a4ca1a3..64ba595 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -220,6 +220,54 @@ public class Postler.Content : WebKit.WebView {
         return "";
     }
 
+    public bool prepare_reply (string? location, bool quote) {
+        var body = new StringBuilder ();
+
+        if (location != null) {
+            var contents = File.new_for_path (location);
+            try {
+                var stream = new DataInputStream (contents.read (null));
+                /* Skip the header */
+                string line;
+                while ((line = stream.read_line (null, null)) != null) {
+                    if (line == "")
+                        break;
+                }
+
+                size_t length;
+                while ((line = stream.read_line (out length, null)) != null) {
+                    /* TODO: Handle encoding */
+                    for (int i = 0; i < length; i += (quote ? 78 : 80))
+                        body.append ((quote ? "> " : "")
+                            + line.substring (i, (long)(length - i)) + "\n");
+                }
+                body.append_c ('\n');
+            } catch (GLib.Error error) {
+                load_string ("""
+                    <title>%s</title>
+                    <body>
+                    <h1>%s</h1>
+                    <p>%s</p>
+                    </body>
+                    """.
+                    printf (_("Error"), _("Error"),
+                        error.message),
+                    "text/html", "UTF-8", "about:blank");
+                GLib.critical (_("Failed to quote message \"%s\": %s"),
+                    contents.get_path (), error.message);
+            }
+        }
+
+        try {
+            string signature = "";
+            GLib.FileUtils.get_contents (Environment.get_home_dir () + "/.signature",
+                                         out signature);
+            body.append ("\n\n--\n" + signature);
+        } catch (GLib.FileError error) { }
+        load_string (body.str, "text/plain", "UTF-8", "about:blank");
+        return true;
+    }
+
     public bool display (string location) {
         last_location = location;
         subject = _("(No subject)");
@@ -280,7 +328,6 @@ public class Postler.Content : WebKit.WebView {
             reply = "";
             organization = "";
             x_mailer = "";
-            /* Skip the header */
             string previous_line = "";
             while ((line = stream.read_line (null, null)) != null) {
                 if (line == "")
diff --git a/postler/postler-reader.vala b/postler/postler-reader.vala
index 9396475..de122ea 100644
--- a/postler/postler-reader.vala
+++ b/postler/postler-reader.vala
@@ -97,6 +97,12 @@ public class Postler.Reader {
                             GLib.warning (_("Invalid field \"%s\" was ignored."),
                                           pieces[1] != null ? pieces[0] : field);
                     }
+                    if (filenames[1] != null) {
+                        composer.prepare_reply (filenames[1],
+                            composer.subject.has_prefix ("Re: "));
+                    } else {
+                        composer.prepare_reply ();
+                    }
                 }
                 instance.destroy.connect (Gtk.main_quit);
                 instance.show ();



More information about the Xfce4-commits mailing list