[Xfce4-commits] <postler:master> Update .uidvalidity number read by mbsync

Christian Dywan noreply at xfce.org
Wed Feb 23 04:44:01 CET 2011


Updating branch refs/heads/master
         to 09afc48af24f1e48c80fe3d112e4d088daa7b37b (commit)
       from db4f0cbb25d411754bd1ea04c1c2227ff9132a6f (commit)

commit 09afc48af24f1e48c80fe3d112e4d088daa7b37b
Author: Christian Dywan <christian at twotoasts.de>
Date:   Tue Feb 22 23:49:13 2011 +0100

    Update .uidvalidity number read by mbsync
    
    If the U= in the maildir filename is too low, mbsync stops
    updating the folder containing such a file. To avoid that
    we read the number, use the next one and update the file.

 postler/postler-composer.vala |    6 ++----
 postler/postler-folders.vala  |    6 ++----
 postler/postler-messages.vala |   30 ++++++++++++++++++++++++------
 3 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/postler/postler-composer.vala b/postler/postler-composer.vala
index 288a23f..588be4e 100644
--- a/postler/postler-composer.vala
+++ b/postler/postler-composer.vala
@@ -255,8 +255,7 @@ public class Postler.Composer : Gtk.Window {
 
         try {
             if (draft_filename == null) {
-                draft_filename = drafts + "/cur/"
-                    + Postler.Messages.generate_maildir_filename ("D");
+                draft_filename = Postler.Messages.generate_filename (drafts + "/cur/", "D");
             } else {
                 FileUtils.remove (draft_filename);
             }
@@ -323,8 +322,7 @@ public class Postler.Composer : Gtk.Window {
 
                 try {
                     /* TODO: Put in /Queue/new/ first and move on success */
-                    string filename = sent + "/cur/"
-                        + Postler.Messages.generate_maildir_filename ("S");
+                    string filename = Postler.Messages.generate_filename (sent + "/cur/", "S");
                     FileUtils.set_contents (filename, message, -1);
                     FileUtils.chmod (filename, 0700);
                     client.sent.connect ((account, file, message) => {
diff --git a/postler/postler-folders.vala b/postler/postler-folders.vala
index b959417..5af7660 100644
--- a/postler/postler-folders.vala
+++ b/postler/postler-folders.vala
@@ -587,8 +587,7 @@ public class Postler.Folders : Gtk.TreeView {
                     if (body.len == 0)
                         continue;
 
-                    string filename = path +
-                        Postler.Messages.generate_maildir_filename ("S");
+                    string filename = Postler.Messages.generate_filename (path, "S");
                     FileUtils.set_contents (filename, body.str, -1);
                     FileUtils.chmod (filename, 0700);
                     body = new GLib.StringBuilder ();
@@ -596,8 +595,7 @@ public class Postler.Folders : Gtk.TreeView {
                 body.append (line + "\n");
             }
             if (body.len != 0) {
-                string filename = path +
-                    Postler.Messages.generate_maildir_filename ("S");
+                string filename = Postler.Messages.generate_filename (path, "S");
                 FileUtils.set_contents (filename, body.str, -1);
                 FileUtils.chmod (filename, 0700);
             }
diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index b9da8ea..43696ff 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -939,22 +939,40 @@ public class Postler.Messages : Gtk.TreeView {
             move_selected (FolderType.TRASH);
     }
 
-    static uint maildir_sequence_number = 0;
-    public static string generate_maildir_filename (string flags="") {
-        /* format "time:pid_sequence.host:2,FLAGS"
+    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 == uint.MAX)
+        if (maildir_sequence_number == uint32.MAX)
             maildir_sequence_number = 0;
         else
             maildir_sequence_number++;
-        return "%lu.%d_%u.%s,U=%u:2,%s".printf (
+        /* Update .uidvalidity number, also read and updated by mbsync */
+        uint32 uid_sequence = maildir_sequence_number;
+        string uid_file = folder.slice (0, -4) + ".uidvalidity";
+        try {
+            string contents;
+            FileUtils.get_contents (uid_file, out contents, null);
+            string[] parts = contents.split ("\n");
+            if (parts[0] != null && parts[1] != null) {
+                uint32 old_uid_sequence = (uint32)(parts[1].to_uint64 ());
+                FileUtils.set_contents (uid_file, "%s\n%u\n".printf (
+                    parts[0], old_uid_sequence + 1), -1);
+                uid_sequence = old_uid_sequence + 1;
+            }
+        }
+        catch (Error error) {
+            GLib.critical (_("Failed to read folder validity: %s"), error.message);
+        }
+        return folder + "%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,
+            uid_sequence,
             flags);
     }
 



More information about the Xfce4-commits mailing list