changeset 7507:b776f2b8d827 HEAD

If we lose a maildir filename, make sure the message gets marked as expunged in index.
author Timo Sirainen <tss@iki.fi>
date Tue, 06 May 2008 02:52:51 +0300
parents 118ae423dbc4
children bec3cd8e8151
files src/lib-storage/index/maildir/maildir-mail.c
diffstat 1 files changed, 24 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/maildir/maildir-mail.c	Tue May 06 01:27:23 2008 +0300
+++ b/src/lib-storage/index/maildir/maildir-mail.c	Tue May 06 02:52:51 2008 +0300
@@ -6,6 +6,7 @@
 #include "maildir-storage.h"
 #include "maildir-filename.h"
 #include "maildir-uidlist.h"
+#include "maildir-sync.h"
 
 #include <stdlib.h>
 #include <fcntl.h>
@@ -143,13 +144,32 @@
 		       const char **fname_r)
 {
 	enum maildir_uidlist_rec_flag flags;
+	struct mail_index_view *view;
+	uint32_t seq;
+	bool exists;
 
 	*fname_r = maildir_uidlist_lookup(mbox->uidlist, mail->uid, &flags);
-	if (*fname_r == NULL) {
-		mail_set_expunged(mail);
-		return FALSE;
+	if (*fname_r != NULL)
+		return TRUE;
+
+	/* file exists in index file, but not in dovecot-uidlist anymore. */
+	mail_set_expunged(mail);
+
+	/* one reason this could happen is if we delayed opening
+	   dovecot-uidlist and we're trying to open a mail that got recently
+	   expunged. Let's test this theory first: */
+	(void)mail_index_refresh(mbox->ibox.index);
+	view = mail_index_view_open(mbox->ibox.index);
+	exists = mail_index_lookup_seq(view, mail->uid, &seq);
+	mail_index_view_close(&view);
+
+	if (exists) {
+		/* the message still exists in index. this means there's some
+		   kind of a desync, which doesn't get fixed if cur/ mtime is
+		   the same as in index. fix this by forcing a resync. */
+		(void)maildir_storage_sync_force(mbox, mail->uid);
 	}
-	return TRUE;
+	return FALSE;
 }
 
 static int maildir_get_pop3_state(struct index_mail *mail)