浏览代码

added BUGS section to manpage detailing the fact that we break the
maildir(5) spec by parsing the filename

change message delivery to use the method described in maildir(5)

Michael Elkins 24 年之前
父节点
当前提交
b3d09b1723
共有 2 个文件被更改,包括 35 次插入8 次删除
  1. 8 0
      isync.1
  2. 27 8
      sync.c

+ 8 - 0
isync.1

@@ -190,6 +190,14 @@ will then use the global value by default.
 .B ~/.isyncrc
 Default configuration file
 ..
+.SH BUGS
+maildir(5) states that readers should not attempt to parse the filename of a
+a message other than the :info field.  However, since
+.B isync
+relies on using the message UIDs that info must be inserted into the
+filename in a way which will be interoperable with existing readers.  So
+the UID is placed in the filename of the messages in the local maildir
+mailbox rather than the :info field.
 .SH SEE ALSO
 mutt(1), maildir(5)
 .P

+ 27 - 8
sync.c

@@ -25,6 +25,8 @@
 #include <time.h>
 #include <fcntl.h>
 #include <string.h>
+#include <sys/stat.h>
+#include <errno.h>
 #include "isync.h"
 
 static unsigned int MaildirCount = 0;
@@ -48,6 +50,7 @@ sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags)
     char *p;
     int fd;
     int ret;
+    struct stat sb;
 
     for (cur = mbox->msgs; cur; cur = cur->next)
     {
@@ -104,10 +107,22 @@ sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags)
 		continue;
 	    }
 
-	    /* create new file */
-	    snprintf (path, sizeof (path), "%s/tmp/%s.%ld_%d.%d.UID%d",
-		    mbox->path, Hostname, time (0), MaildirCount++,
-		    getpid (), cur->uid);
+	    for (;;)
+	    {
+		/* create new file */
+		snprintf (path, sizeof (path), "%s/tmp/%s.%ld_%d.%d.UID%d",
+			mbox->path, Hostname, time (0), MaildirCount++,
+			getpid (), cur->uid);
+
+		if (stat (path, &sb))
+		{
+		    if (errno == ENOENT)
+			break;
+		}
+
+		sleep (2);
+	    }
+
 
 	    if (cur->flags)
 	    {
@@ -146,11 +161,15 @@ sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags)
 
 		//          printf ("moving %s to %s\n", path, newpath);
 
-		if (rename (path, newpath))
-		    perror ("rename");
+		/* its ok if this fails, the next time we sync the message
+		 * will get pulled down
+		 */
+		if (link (path, newpath))
+		    perror ("link");
 	    }
-	    else
-		unlink(path);
+
+	    /* always remove the temp file */
+	    unlink (path);
 	}
     }
     puts ("");