[Xfce4-commits] <postler:master> Add moving of messages and filename generation

Christian Dywan noreply at xfce.org
Sat Jul 10 00:24:04 CEST 2010


Updating branch refs/heads/master
         to e8b479a9a5a465b5a5f005b9b16b3a2ed527bf65 (commit)
       from 1e897eb58ba839170ddf21dfb4748e119f3f0923 (commit)

commit e8b479a9a5a465b5a5f005b9b16b3a2ed527bf65
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sun Jun 27 21:50:01 2010 +0200

    Add moving of messages and filename generation
    
    Messages.ensure_folder() creates 'new' and 'cur' folders.
    
    Messages.generate_maildir_filename() generates a unique filename
    much like mbsync does.
    
    Messages.move_selected() supersedes delete_selected() by
    allowing movement to a specified subfolder or removing.

 postler/postler-messages.vala |   65 +++++++++++++++++++++++++++++++++++++++--
 postler/wscript_build         |    2 +-
 2 files changed, 63 insertions(+), 4 deletions(-)

diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index a534802..ee8bf77 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -570,8 +570,39 @@ public class Postler.Messages : Gtk.TreeView {
         selected_location = location;
     }
 
+    public static bool ensure_folder (string folder) {
+        if (DirUtils.create_with_parents (folder + "/new", 0700) != 0
+         || DirUtils.create_with_parents (folder + "/cur", 0700) != 0)
+            return false;
+        return true;
+    }
+
     public void delete_selected () {
         /* TODO: Optionally move to waste bin if deleting from inbox */
+        move_selected (null);
+    }
+
+    static uint maildir_sequence_number = 0;
+    public static string generate_maildir_filename (string flags="") {
+        /* format "time:pid_sequence.host:2,FLAGS"
+           This is the format used by mbsync. */
+        var now = GLib.TimeVal ();
+        now.get_current_time ();
+        if (maildir_sequence_number == uint.MAX)
+            maildir_sequence_number = 0;
+        else
+            maildir_sequence_number++;
+        return "%lu.%d_%u.%s,U=%u:2,%s".printf (
+            now.tv_sec,
+            Posix.getpid (),
+            maildir_sequence_number,
+            Environment.get_host_name ().replace ("/", "_").replace (":", "."),
+            maildir_sequence_number,
+            flags);
+    }
+
+    public void move_selected (string? destination_folder) {
+        string? destination_path = null;
         GLib.List<Gtk.TreePath> paths;
         var references = new GLib.List<Gtk.TreeRowReference> ();
 
@@ -587,7 +618,31 @@ public class Postler.Messages : Gtk.TreeView {
                 sort.get (sort_iter, Columns.LOCATION, out location);
                 var file = File.new_for_path (location);
                 try {
-                    file.delete (null);
+                    if (destination_folder == null)
+                        file.delete (null);
+                    else {
+                        if (destination_path == null) {
+                            File? parent = file.get_parent ();
+                            if (parent != null)
+                                parent = parent.get_parent ();
+                            if (parent != null)
+                                parent = parent.get_parent ();
+                            if (parent != null)
+                                destination_path = parent.get_path ()
+                                    + "/" + destination_folder;
+                            if (parent == null || !ensure_folder (destination_path)) {
+                                GLib.critical (_("Folders for moving messages "
+                                    + "couldn't be created."));
+                                return;
+                            }
+                        }
+                        /* FIXME: Provide a way to retain or specify flags */
+                        string filename = destination_path + "/cur/"
+                            + generate_maildir_filename ("S");
+                        var destination_file = File.new_for_path (filename);
+                        file.move (destination_file, 0, null, null);
+                    }
+
                     Gtk.TreeIter child_iter;
                     sort.convert_iter_to_child_iter (out child_iter, sort_iter);
                     string next_path = sort.get_string_from_iter (sort_iter);
@@ -597,8 +652,12 @@ public class Postler.Messages : Gtk.TreeView {
                     }
                     content.clear ();
                 } catch (GLib.Error error) {
-                    GLib.critical (_("Failed to delete message \"%s\": %s"),
-                        location, error.message);
+                    unowned string message;
+                    if (destination_folder == null)
+                        message = _("Failed to delete message \"%s\": %s");
+                    else
+                        message = _("Failed to move message \"%s\": %s");
+                    GLib.critical (message, location, error.message);
                 }
             }
         }
diff --git a/postler/wscript_build b/postler/wscript_build
index b8b4c4b..9f1de5f 100644
--- a/postler/wscript_build
+++ b/postler/wscript_build
@@ -14,6 +14,6 @@ obj.target = 'postler'
 obj.includes = '. ..'
 obj.find_sources_in_dirs ('.')
 obj.uselib = 'GIO GTK UNIQUE WEBKIT'
-obj.packages = 'config postler gio-2.0 gtk+-2.0 unique-1.0 webkit-1.0'
+obj.packages = 'config postler posix gio-2.0 gtk+-2.0 unique-1.0 webkit-1.0'
 obj.vapi_dirs = '.'
 



More information about the Xfce4-commits mailing list