浏览代码

- update isyncmaxuid properly

Oswald Buddenhagen 22 年之前
父节点
当前提交
a4f2725bad
共有 3 个文件被更改,包括 11 次插入8 次删除
  1. 0 2
      TODO
  2. 3 3
      src/maildir.c
  3. 8 3
      src/sync.c

+ 0 - 2
TODO

@@ -1,7 +1,5 @@
 add support for syncing with other: and shared: via NAMESPACE
 
---fast downloads the last message again if no new messages have arrived
-
 isync gets confused when new mail is delivered while in the middle of an
 IMAP session.  need to handled those asynchronous notifications properly.
 

+ 3 - 3
src/maildir.c

@@ -198,9 +198,6 @@ maildir_open (const char *path, int flags)
     if (read_uid (m->path, "isyncmaxuid", &m->maxuid) == -1)
 	goto err;
 
-    if (flags & OPEN_FAST)
-	return m;
-
     snprintf (buf, sizeof (buf), "%s/isyncuidmap", m->path);
     m->db = dbm_open (buf, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
     if (m->db == NULL)
@@ -209,6 +206,9 @@ maildir_open (const char *path, int flags)
 	goto err;
     }
 
+    if (flags & OPEN_FAST)
+	return m;
+
     cur = &m->msgs;
     for (; count < 2; count++)
     {

+ 8 - 3
src/sync.c

@@ -94,8 +94,6 @@ sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags,
     if (mbox->maxuid == 0 || imap->maxuid > mbox->maxuid)
     {
 	mbox->maxuid = imap->maxuid;
-	if (maildir_update_maxuid (mbox))
-	    return -1;
     }
 
     /* if we are --fast mode, the mailbox wont have been loaded, so
@@ -153,11 +151,13 @@ sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags,
 
 		cur->size = sb.st_size;
 		cur->uid = imap_append_message (imap, fd, cur);
-		/* if the server gave us back a uid, update the db */
 		if (cur->uid != (unsigned int) -1) {
+		    /* update the db */
 		    set_uid (mbox->db, cur->file, cur->uid);
 		    if (!cur->uid)
 			printf("warning: no uid for new messge %s\n", cur->file);
+		    else if (cur->uid > mbox->maxuid)
+		    	mbox->maxuid = cur->uid;
 		}
 
 		close (fd);
@@ -373,6 +373,8 @@ sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags,
 		{
 		    /* update the db with the UID mapping for this file */
 		    set_uid (mbox->db, p + 1, cur->uid);
+		    if (cur->uid > mbox->maxuid)
+		    	mbox->maxuid = cur->uid;
 		}
 	    }
 
@@ -383,5 +385,8 @@ sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags,
 
     info (" %d messages\n", fetched);
 
+    if (maildir_update_maxuid (mbox))
+	return -1;
+
     return 0;
 }