[Xfce4-commits] <postler:master> Update uidvalidity when moving between folders

Christian Dywan noreply at xfce.org
Thu Feb 24 03:48:01 CET 2011


Updating branch refs/heads/master
         to 1be19a6e8a1ac2d6d77801f2a8911aca9f4a6602 (commit)
       from 4220e57ece2d427a78a1d2a803354a7ca44a569f (commit)

commit 1be19a6e8a1ac2d6d77801f2a8911aca9f4a6602
Author: Christian Dywan <christian at twotoasts.de>
Date:   Thu Feb 24 01:49:09 2011 +0100

    Update uidvalidity when moving between folders
    
    Move validity handling into obtain_uid_sequence() and provide
    update_filename() for moving messages between folders.
    
    Use the new function for moving selected messages and dragging
    messages into a new folder.

 postler/postler-folders.vala  |   16 +++++-----
 postler/postler-messages.vala |   65 +++++++++++++++++++++++-----------------
 2 files changed, 45 insertions(+), 36 deletions(-)

diff --git a/postler/postler-folders.vala b/postler/postler-folders.vala
index 5af7660..d870587 100644
--- a/postler/postler-folders.vala
+++ b/postler/postler-folders.vala
@@ -52,19 +52,19 @@ public class Postler.Folders : Gtk.TreeView {
         if (get_dest_row_at_pos (x, y, out path, out pos)) {
               Gtk.TreeIter iter;
               var tree_model = get_model ();
-              string new_location;
+              string destination_path;
               tree_model.get_iter_from_string (out iter, path.to_string ());
-              tree_model.get (iter, Columns.LOCATION, out new_location);
-              new_location += "/cur/";
+              tree_model.get (iter, Columns.LOCATION, out destination_path);
               foreach (string uri in selection_data.get_uris ()) {
                   try {
-                      string old_location = Filename.from_uri (uri, null);
-                      if (old_location.has_prefix (new_location))
+                      string location = Filename.from_uri (uri, null);
+                      if (location.has_prefix (destination_path + "/cur/"))
                           return;
 
-                      string filename = old_location.rstr ("/").replace ("/","");
-                      var source = GLib.File.new_for_path (old_location);
-                      var destination = GLib.File.new_for_path (new_location + filename);
+                      string new_location = Postler.Messages.update_filename (location,
+                          destination_path + "/cur/");
+                      var source = GLib.File.new_for_path (location);
+                      var destination = GLib.File.new_for_path (new_location);
                       source.move (destination, GLib.FileCopyFlags.NONE);
                   }
                   catch (Error error) {
diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index 43696ff..c85e7f9 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -233,13 +233,6 @@ public class Postler.Messages : Gtk.TreeView {
             model.get_iter_from_string (out iter, path.to_string ());
             string? location;
             model.get (iter, Columns.LOCATION, out location);
-            string bare_filename;
-            string flags = flags_from_filename (location, out bare_filename);
-            string filename;
-            if ("S" in flags)
-                filename = Path.get_basename (bare_filename) + ":" + flags;
-            else
-                filename = Path.get_basename (toggle_flag (location, 'S'));
             uris += ("file://" + location);
         }
         if (uris != null)
@@ -939,19 +932,9 @@ public class Postler.Messages : Gtk.TreeView {
             move_selected (FolderType.TRASH);
     }
 
-    static uint32 maildir_sequence_number = 0;
-    public static string generate_filename (string folder, string flags="")
-        requires (folder.has_suffix ("/cur/")) {
-        /* format "time.pid_sequence.host,U=uid:2,FLAGS"
-           This is the format used by mbsync. */
-        var now = GLib.TimeVal ();
-        now.get_current_time ();
-        if (maildir_sequence_number == uint32.MAX)
-            maildir_sequence_number = 0;
-        else
-            maildir_sequence_number++;
+    public static uint32 obtain_uid_sequence (string folder, uint32 fallback_sequence) {
         /* Update .uidvalidity number, also read and updated by mbsync */
-        uint32 uid_sequence = maildir_sequence_number;
+        uint32 uid_sequence = fallback_sequence;
         string uid_file = folder.slice (0, -4) + ".uidvalidity";
         try {
             string contents;
@@ -967,6 +950,21 @@ public class Postler.Messages : Gtk.TreeView {
         catch (Error error) {
             GLib.critical (_("Failed to read folder validity: %s"), error.message);
         }
+        return uid_sequence;
+    }
+
+    static uint32 maildir_sequence_number = 0;
+    public static string generate_filename (string folder, string flags="")
+        requires (folder.has_suffix ("/cur/")) {
+        /* format "time.pid_sequence.host,U=uid:2,FLAGS"
+           This is the format used by mbsync. */
+        var now = GLib.TimeVal ();
+        now.get_current_time ();
+        if (maildir_sequence_number == uint32.MAX)
+            maildir_sequence_number = 0;
+        else
+            maildir_sequence_number++;
+        uint32 uid_sequence = obtain_uid_sequence (folder, maildir_sequence_number);
         return folder + "%lu.%d_%u.%s,U=%u:2,%s".printf (
             now.tv_sec,
             Posix.getpid (),
@@ -976,6 +974,23 @@ public class Postler.Messages : Gtk.TreeView {
             flags);
     }
 
+    public static string update_filename (string location, string new_folder)
+        requires (new_folder.has_suffix ("/cur/")) {
+
+        string bare_filename;
+        string flags = flags_from_filename (location, out bare_filename);
+        string filename;
+        if ("S" in flags)
+            filename = Path.get_basename (bare_filename) + ":" + flags;
+        else
+            filename = Path.get_basename (toggle_flag (location, 'S'));
+        string[] parts = filename.split (",");
+        return_val_if_fail (parts[0] != null && parts[1] != null
+            && parts[2] != null && parts[3] == null, "");
+        uint32 uid_sequence = obtain_uid_sequence (new_folder, maildir_sequence_number);
+        return new_folder + parts[0] + ",U=" + uid_sequence.to_string () + ":2," + parts[2];
+    }
+
     public void move_selected (FolderType? type) {
         string? destination_path;
         if (type == null)
@@ -1005,16 +1020,10 @@ public class Postler.Messages : Gtk.TreeView {
                     if (destination_path == null)
                         file.delete (null);
                     else {
-                        string bare_filename;
-                        string flags = flags_from_filename (location, out bare_filename);
-                        string filename;
-                        if ("S" in flags)
-                            filename = Path.get_basename (bare_filename) + ":" + flags;
-                        else
-                            filename = Path.get_basename (toggle_flag (location, 'S'));
-                        string new_location = destination_path + "/cur/" + filename;
+                        string new_location = update_filename (location,
+                            destination_path + "/cur/");
                         var destination_file = File.new_for_path (new_location);
-                        file.move (destination_file, 0, null, null);
+                        file.move (destination_file, GLib.FileCopyFlags.NONE);
                     }
 
                     /* Move to next, more recent message row */



More information about the Xfce4-commits mailing list