[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-sync-parse.c, 1.59, 1.60 mbox-sync-private.h, 1.64, 1.65 mbox-sync-rewrite.c, 1.74, 1.75 mbox-sync-update.c, 1.52, 1.53 mbox-sync.c, 1.202, 1.203

tss at dovecot.org tss at dovecot.org
Sat Mar 10 18:05:52 EET 2007


Update of /var/lib/cvs/dovecot/src/lib-storage/index/mbox
In directory talvi:/tmp/cvs-serv4571

Modified Files:
	mbox-sync-parse.c mbox-sync-private.h mbox-sync-rewrite.c 
	mbox-sync-update.c mbox-sync.c 
Log Message:
Cleaned up the code a bit. Fixed sync rewrite crashing with pseudo mails.



Index: mbox-sync-parse.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-parse.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- mbox-sync-parse.c	10 Mar 2007 15:46:44 -0000	1.59
+++ mbox-sync-parse.c	10 Mar 2007 16:05:48 -0000	1.60
@@ -253,7 +253,7 @@
 
 	/* this is the c-client style "FOLDER INTERNAL DATA" message.
 	   skip it. */
-	ctx->pseudo = TRUE;
+	ctx->mail.pseudo = TRUE;
 	return TRUE;
 }
 

Index: mbox-sync-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-private.h,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- mbox-sync-private.h	7 Mar 2007 15:38:24 -0000	1.64
+++ mbox-sync-private.h	10 Mar 2007 16:05:48 -0000	1.65
@@ -34,7 +34,6 @@
    header, because 'O' flag means non-recent but internally we want to use
    recent flag. */
 #define MBOX_NONRECENT_KLUDGE MAIL_RECENT
-#define MBOX_EXPUNGED 0x40
 
 #define STATUS_FLAGS_MASK (MAIL_SEEN|MBOX_NONRECENT_KLUDGE)
 #define XSTATUS_FLAGS_MASK (MAIL_ANSWERED|MAIL_FLAGGED|MAIL_DRAFT|MAIL_DELETED)
@@ -42,13 +41,17 @@
 extern struct mbox_flag_type mbox_xstatus_flags[];
 
 struct mbox_sync_mail {
+	/* uid=0 can mean that this mail describes an expunged area or that
+	   this is a pseudo message */
 	uint32_t uid;
 	uint32_t idx_seq;
 
 	ARRAY_TYPE(keyword_indexes) keywords;
 	uint8_t flags;
 
-	unsigned int uid_broken:1;
+	uint8_t uid_broken:1;
+	uint8_t expunged:1;
+	uint8_t pseudo:1;
 
 	uoff_t from_offset;
 	uoff_t body_size;
@@ -87,7 +90,6 @@
 	unsigned int have_eoh:1;
 	unsigned int need_rewrite:1;
 	unsigned int seen_imapbase:1;
-	unsigned int pseudo:1;
 	unsigned int updated:1;
 	unsigned int recent:1;
 	unsigned int dirty:1;

Index: mbox-sync-rewrite.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-rewrite.c,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- mbox-sync-rewrite.c	10 Mar 2007 11:54:39 -0000	1.74
+++ mbox-sync-rewrite.c	10 Mar 2007 16:05:48 -0000	1.75
@@ -86,7 +86,7 @@
 
 	i_assert(size < SSIZE_T_MAX);
 
-	if (ctx->pseudo)
+	if (ctx->mail.pseudo)
 		start_pos = ctx->hdr_pos[MBOX_HDR_X_IMAPBASE];
 	else if (ctx->mail.space > 0) {
 		/* update the header using the existing offset.
@@ -331,14 +331,16 @@
 		istream_raw_mbox_get_header_offset(sync_ctx->input);
 	mail_ctx->mail.body_size = mails[idx].body_size;
 
-	/* only expunged mails have uid=0 */
-	i_assert(mails[idx].uid != 0);
-
 	/* This will force the UID to be the one that we originally assigned
 	   to it, regardless of whether it's broken or not in the file. */
 	orig_next_uid = sync_ctx->next_uid;
-	sync_ctx->next_uid = mails[idx].uid;
-	sync_ctx->prev_msg_uid = mails[idx].uid - 1;
+	if (mails[idx].uid != 0) {
+		sync_ctx->next_uid = mails[idx].uid;
+		sync_ctx->prev_msg_uid = mails[idx].uid - 1;
+	} else {
+		i_assert(mails[idx].pseudo);
+		sync_ctx->prev_msg_uid = 0;
+	}
 
 	first_mail_expunge_extra = 1 +
 		sync_ctx->first_mail_crlf_expunged ? 1 : 0;
@@ -353,6 +355,7 @@
 	}
 
 	mbox_sync_parse_next_mail(sync_ctx->input, mail_ctx);
+	i_assert(mail_ctx->mail.pseudo == mails[idx].pseudo);
 
 	/* set next_uid back before updating the headers. this is important
 	   if we're updating the first message to make X-IMAP[base] header
@@ -486,7 +489,7 @@
 	start_offset = mails[0].from_offset;
 	for (first_nonexpunged_idx = 0;; first_nonexpunged_idx++) {
 		i_assert(first_nonexpunged_idx != idx);
-		if ((mails[first_nonexpunged_idx].flags & MBOX_EXPUNGED) == 0)
+		if (!mails[first_nonexpunged_idx].expunged)
 			break;
                 expunged_space += mails[first_nonexpunged_idx].space;
 	}
@@ -507,8 +510,7 @@
 
 		next_end_offset = mails[idx].offset;
 
-		if (mails[idx].space <= 0 &&
-		    (mails[idx].flags & MBOX_EXPUNGED) == 0) {
+		if (mails[idx].space <= 0 && !mails[idx].expunged) {
 			/* give space to this mail. end_offset is left to
 			   contain this message's From-line (ie. below we
 			   move only headers + body). */
@@ -544,7 +546,7 @@
 			}
 
 			move_diff += mails[idx].space;
-			if ((mails[idx].flags & MBOX_EXPUNGED) == 0) {
+			if (!mails[idx].expunged) {
 				move_diff -= padding_per_mail;
 				mails[idx].space = padding_per_mail;
 

Index: mbox-sync-update.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-update.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- mbox-sync-update.c	16 Feb 2007 19:01:35 -0000	1.52
+++ mbox-sync-update.c	10 Mar 2007 16:05:48 -0000	1.53
@@ -211,7 +211,7 @@
 		str_append_c(ctx->header, '\n');
 	}
 
-	if (ctx->hdr_pos[MBOX_HDR_X_UID] == (size_t)-1 && !ctx->pseudo) {
+	if (ctx->hdr_pos[MBOX_HDR_X_UID] == (size_t)-1 && !ctx->mail.pseudo) {
 		str_append(ctx->header, "X-UID: ");
 		ctx->hdr_pos[MBOX_HDR_X_UID] = str_len(ctx->header);
 		str_printfa(ctx->header, "%u\n", ctx->mail.uid);
@@ -384,7 +384,7 @@
 	uint8_t old_flags;
 	bool keywords_changed;
 
-	i_assert(ctx->mail.uid != 0 || ctx->pseudo);
+	i_assert(ctx->mail.uid != 0 || ctx->mail.pseudo);
 
 	old_flags = ctx->mail.flags;
 

Index: mbox-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync.c,v
retrieving revision 1.202
retrieving revision 1.203
diff -u -d -r1.202 -r1.203
--- mbox-sync.c	7 Mar 2007 15:38:24 -0000	1.202
+++ mbox-sync.c	10 Mar 2007 16:05:48 -0000	1.203
@@ -124,7 +124,8 @@
 					       mail_ctx->content_length);
 	i_assert(mail_ctx->mail.body_size < OFF_T_MAX);
 
-	if ((mail_ctx->mail.flags & MAIL_RECENT) != 0 && !mail_ctx->pseudo) {
+	if ((mail_ctx->mail.flags & MAIL_RECENT) != 0 &&
+	    !mail_ctx->mail.pseudo) {
 		if (!sync_ctx->mbox->ibox.keep_recent) {
 			/* need to add 'O' flag to Status-header */
 			mail_ctx->need_rewrite = TRUE;
@@ -651,8 +652,7 @@
 
 	mails = array_get(&sync_ctx->mails, &count);
 	for (i = 0; i < count; i++) {
-		if (mails[i].idx_seq == 0 ||
-		    (mails[i].flags & MBOX_EXPUNGED) != 0)
+		if (mails[i].idx_seq == 0 || mails[i].expunged)
 			continue;
 
 		sync_ctx->moved_offsets = TRUE;
@@ -666,7 +666,7 @@
 {
 	struct mbox_sync_context *sync_ctx = mail_ctx->sync_ctx;
 
-	mail_ctx->mail.flags = MBOX_EXPUNGED;
+	mail_ctx->mail.expunged = TRUE;
 	mail_ctx->mail.offset = mail_ctx->mail.from_offset;
 	mail_ctx->mail.space =
 		mail_ctx->body_offset - mail_ctx->mail.from_offset +
@@ -762,7 +762,7 @@
 			struct mbox_sync_mail mail;
 
 			memset(&mail, 0, sizeof(mail));
-			mail.flags = MBOX_EXPUNGED;
+			mail.expunged = TRUE;
 			mail.offset = mail.from_offset =
 				(sync_ctx->dest_first_mail ? 1 : 0) +
 				mail_ctx->mail.from_offset -
@@ -1074,7 +1074,7 @@
 		if (mail_ctx->mail.uid_broken)
 			uids_broken = TRUE;
 
-		if (mail_ctx->pseudo)
+		if (mail_ctx->mail.pseudo)
 			uid = 0;
 
 		rec = NULL; ret = 1;
@@ -1088,7 +1088,7 @@
 			/* UID found but it's broken */
 			uid = 0;
 		} else if (uid == 0 &&
-			   !mail_ctx->pseudo &&
+			   !mail_ctx->mail.pseudo &&
 			   (sync_ctx->delay_writes ||
 			    sync_ctx->idx_seq <= messages_count)) {
 			/* If we can't use/store X-UID header, use MD5 sum.
@@ -1109,11 +1109,11 @@
 		   message just get the first sync record so we can jump to
 		   it with partial seeking. */
 		if (mbox_sync_read_index_syncs(sync_ctx,
-					       mail_ctx->pseudo ? 1 : uid,
+					       mail_ctx->mail.pseudo ? 1 : uid,
 					       &expunged) < 0)
 			return -1;
 
-		if (mail_ctx->pseudo) {
+		if (mail_ctx->mail.pseudo) {
 			/* if it was set, it was for the next message */
 			expunged = FALSE;
 		} else {
@@ -1124,7 +1124,7 @@
 			}
 		}
 
-		if (uid == 0 && !mail_ctx->pseudo) {
+		if (uid == 0 && !mail_ctx->mail.pseudo) {
 			/* missing/broken X-UID. all the rest of the mails
 			   need new UIDs. */
 			while (sync_ctx->idx_seq <= messages_count) {
@@ -1149,7 +1149,7 @@
 			sync_ctx->prev_msg_uid = mail_ctx->mail.uid;
 		}
 
-		if (!mail_ctx->pseudo)
+		if (!mail_ctx->mail.pseudo)
 			mail_ctx->mail.idx_seq = sync_ctx->idx_seq;
 
 		if (!expunged) {
@@ -1161,7 +1161,7 @@
 			mbox_sync_handle_expunge(mail_ctx);
 		}
 
-		if (!mail_ctx->pseudo) {
+		if (!mail_ctx->mail.pseudo) {
 			if (!expunged) {
 				if (mbox_sync_update_index(mail_ctx, rec) < 0)
 					return -1;



More information about the dovecot-cvs mailing list