[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-sync-parse.c, 1.49.2.7, 1.49.2.8 mbox-sync-private.h, 1.56.2.7, 1.56.2.8 mbox-sync-rewrite.c, 1.62.2.11, 1.62.2.12 mbox-sync-update.c, 1.46.2.3, 1.46.2.4 mbox-sync.c, 1.181.2.14, 1.181.2.15

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


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

Modified Files:
      Tag: branch_1_0
	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.49.2.7
retrieving revision 1.49.2.8
diff -u -d -r1.49.2.7 -r1.49.2.8
--- mbox-sync-parse.c	10 Mar 2007 15:46:42 -0000	1.49.2.7
+++ mbox-sync-parse.c	10 Mar 2007 16:05:45 -0000	1.49.2.8
@@ -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.56.2.7
retrieving revision 1.56.2.8
diff -u -d -r1.56.2.7 -r1.56.2.8
--- mbox-sync-private.h	7 Mar 2007 15:38:20 -0000	1.56.2.7
+++ mbox-sync-private.h	10 Mar 2007 16:05:45 -0000	1.56.2.8
@@ -32,7 +32,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)
@@ -40,13 +39,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_t ARRAY_DEFINE(keywords, unsigned int);
 	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;
@@ -85,7 +88,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.62.2.11
retrieving revision 1.62.2.12
diff -u -d -r1.62.2.11 -r1.62.2.12
--- mbox-sync-rewrite.c	10 Mar 2007 11:54:35 -0000	1.62.2.11
+++ mbox-sync-rewrite.c	10 Mar 2007 16:05:45 -0000	1.62.2.12
@@ -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.46.2.3
retrieving revision 1.46.2.4
diff -u -d -r1.46.2.3 -r1.46.2.4
--- mbox-sync-update.c	16 Feb 2007 19:01:31 -0000	1.46.2.3
+++ mbox-sync-update.c	10 Mar 2007 16:05:45 -0000	1.46.2.4
@@ -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.181.2.14
retrieving revision 1.181.2.15
diff -u -d -r1.181.2.14 -r1.181.2.15
--- mbox-sync.c	7 Mar 2007 15:38:20 -0000	1.181.2.14
+++ mbox-sync.c	10 Mar 2007 16:05:45 -0000	1.181.2.15
@@ -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;
@@ -654,8 +655,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;
@@ -669,7 +669,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 +
@@ -765,7 +765,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 -
@@ -1078,7 +1078,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;
@@ -1092,7 +1092,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.
@@ -1113,11 +1113,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 {
@@ -1128,7 +1128,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) {
@@ -1153,7 +1153,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) {
@@ -1165,7 +1165,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