? src/lib-storage/index/mbox/diff
Index: src/lib-storage/index/mbox/mbox-sync-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-private.h,v
retrieving revision 1.56.2.3
diff -u -r1.56.2.3 mbox-sync-private.h
--- src/lib-storage/index/mbox/mbox-sync-private.h	22 Jan 2007 12:44:11 -0000	1.56.2.3
+++ src/lib-storage/index/mbox/mbox-sync-private.h	30 Jan 2007 10:51:32 -0000
@@ -121,7 +121,6 @@
 	pool_t saved_keywords_pool;
 
 	uint32_t prev_msg_uid, next_uid, idx_next_uid;
-	uint32_t prev_next_uid, need_space_next_uid;
 	uint32_t seq, idx_seq, need_space_seq;
 	off_t expunged_space, space_diff;
 
Index: src/lib-storage/index/mbox/mbox-sync-rewrite.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-rewrite.c,v
retrieving revision 1.62.2.5
diff -u -r1.62.2.5 mbox-sync-rewrite.c
--- src/lib-storage/index/mbox/mbox-sync-rewrite.c	22 Jan 2007 12:44:11 -0000	1.62.2.5
+++ src/lib-storage/index/mbox/mbox-sync-rewrite.c	30 Jan 2007 10:51:32 -0000
@@ -319,6 +319,7 @@
 				uint32_t seq, uint32_t idx,
 				uoff_t expunged_space)
 {
+	uint32_t old_prev_msg_uid;
 	unsigned int first_mail_expunge_extra;
 
 	memset(mail_ctx, 0, sizeof(*mail_ctx));
@@ -332,6 +333,7 @@
 
 	/* mbox_sync_parse_next_mail() checks that UIDs are growing,
 	   so we have to fool it. */
+	old_prev_msg_uid = sync_ctx->prev_msg_uid;
 	sync_ctx->prev_msg_uid = mails[idx].uid == 0 ? 0 : mails[idx].uid-1;
 
 	first_mail_expunge_extra = 1 +
@@ -360,8 +362,7 @@
 			str_append_c(mail_ctx->header, '\n');
 	}
 
-	if (mail_ctx->mail.uid >= sync_ctx->next_uid)
-		sync_ctx->next_uid = mail_ctx->mail.uid + 1;
+	sync_ctx->prev_msg_uid = old_prev_msg_uid;
 }
 
 static int mbox_sync_read_and_move(struct mbox_sync_context *sync_ctx,
@@ -453,7 +454,6 @@
 	uoff_t offset, dest_offset, next_end_offset, next_move_diff;
 	uoff_t start_offset, expunged_space;
 	uint32_t idx, first_nonexpunged_idx, padding_per_mail;
-	uint32_t orig_prev_msg_uid, orig_next_uid;
 	unsigned int count;
 	int ret = 0;
 
@@ -483,11 +483,6 @@
 	}
 	i_assert(mails[first_nonexpunged_idx].space < 0);
 
-	/* broken UIDs are generated from next_uid */
-	orig_prev_msg_uid = sync_ctx->prev_msg_uid;
-	orig_next_uid = sync_ctx->next_uid;
-	sync_ctx->next_uid = sync_ctx->need_space_next_uid;
-
 	/* start moving backwards. */
 	while (idx > first_nonexpunged_idx) {
 		idx--;
@@ -564,8 +559,5 @@
 	i_assert(move_diff + (off_t)expunged_space >= 0);
 
 	i_stream_sync(sync_ctx->input);
-	sync_ctx->next_uid = orig_next_uid;
-	sync_ctx->need_space_next_uid = 0;
-	sync_ctx->prev_msg_uid = orig_prev_msg_uid;
 	return ret;
 }
Index: src/lib-storage/index/mbox/mbox-sync-update.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-update.c,v
retrieving revision 1.46.2.2
diff -u -r1.46.2.2 mbox-sync-update.c
--- src/lib-storage/index/mbox/mbox-sync-update.c	22 Jan 2007 12:44:11 -0000	1.46.2.2
+++ src/lib-storage/index/mbox/mbox-sync-update.c	30 Jan 2007 10:51:32 -0000
@@ -453,7 +453,11 @@
 		mbox_sync_update_xkeywords(ctx);
 	}
 
-	i_assert(ctx->mail.uid == 0 || ctx->mail.uid == mail->uid);
+	/* we might not have done the UID validity checks in same way this
+	   time, so just overwrite conflicting UIDs if uid_broken was set in
+	   first parse time */
+	i_assert(ctx->mail.uid == 0 || ctx->mail.uid_broken ||
+		 ctx->mail.uid == mail->uid);
 	ctx->mail.uid = mail->uid;
 
 	mbox_sync_update_x_imap_base(ctx);
Index: src/lib-storage/index/mbox/mbox-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync.c,v
retrieving revision 1.181.2.9
diff -u -r1.181.2.9 mbox-sync.c
--- src/lib-storage/index/mbox/mbox-sync.c	22 Jan 2007 12:44:11 -0000	1.181.2.9
+++ src/lib-storage/index/mbox/mbox-sync.c	30 Jan 2007 10:51:32 -0000
@@ -115,7 +115,6 @@
 		istream_raw_mbox_get_start_offset(sync_ctx->input);
 	mail_ctx->mail.offset =
 		istream_raw_mbox_get_header_offset(sync_ctx->input);
-	sync_ctx->prev_next_uid = sync_ctx->next_uid;
 
 	mbox_sync_parse_next_mail(sync_ctx->input, mail_ctx);
 	i_assert(sync_ctx->input->v_offset != mail_ctx->mail.from_offset ||
@@ -761,10 +760,6 @@
 		sync_ctx->need_space_seq = sync_ctx->seq;
 		sync_ctx->space_diff = 0;
 
-		/* remember what the next_uid was before we parsed this mail,
-		   so that rewriting can set it back */
-		sync_ctx->need_space_next_uid = sync_ctx->prev_next_uid;
-
 		if (sync_ctx->expunged_space > 0) {
 			/* create dummy message to describe the expunged data */
 			struct mbox_sync_mail mail;
