[dovecot-cvs] dovecot/src/lib-index/mbox Makefile.am,1.5,1.6 mbox-append.c,1.42,1.43 mbox-index.c,1.76,1.77 mbox-index.h,1.30,1.31 mbox-open.c,1.20,1.21 mbox-rewrite.c,1.58,1.59 mbox-sync-full.c,1.14,1.15 mbox-sync.c,1.32,1.33 mbox-rebuild.c,1.24,NONE

cras at procontrol.fi cras at procontrol.fi
Thu Aug 7 00:15:36 EEST 2003


Update of /home/cvs/dovecot/src/lib-index/mbox
In directory danu:/tmp/cvs-serv13163/lib-index/mbox

Modified Files:
	Makefile.am mbox-append.c mbox-index.c mbox-index.h 
	mbox-open.c mbox-rewrite.c mbox-sync-full.c mbox-sync.c 
Removed Files:
	mbox-rebuild.c 
Log Message:
Index cache file rewrite. It's not finished yet and mbox support is
completely broken. But it's getting difficult to maintain outside cvs :)



Index: Makefile.am
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/Makefile.am,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- Makefile.am	12 May 2003 06:14:50 -0000	1.5
+++ Makefile.am	6 Aug 2003 20:15:32 -0000	1.6
@@ -12,7 +12,6 @@
 	mbox-index.c \
 	mbox-lock.c \
 	mbox-open.c \
-	mbox-rebuild.c \
 	mbox-rewrite.c \
 	mbox-sync.c \
 	mbox-sync-full.c

Index: mbox-append.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-append.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- mbox-append.c	8 May 2003 05:08:29 -0000	1.42
+++ mbox-append.c	6 Aug 2003 20:15:32 -0000	1.43
@@ -7,19 +7,21 @@
 #include "md5.h"
 #include "mbox-index.h"
 #include "mail-index-util.h"
+#include "mail-cache.h"
 
 static int mbox_index_append_next(struct mail_index *index,
+                                  struct mail_index_record *rec,
+				  struct mail_cache_transaction_ctx *trans_ctx,
 				  struct istream *input)
 {
-	struct mail_index_record *rec;
-	struct mail_index_update *update;
         struct mbox_header_context ctx;
-	time_t internal_date;
+	enum mail_index_record_flag index_flags;
+	time_t received_date;
 	uoff_t abs_start_offset, eoh_offset;
 	const unsigned char *data;
 	unsigned char md5_digest[16];
 	size_t size, pos;
-	int ret, dirty;
+	int dirty;
 
 	/* get the From-line */
 	pos = 0;
@@ -40,14 +42,14 @@
 		index_set_error(index, "Error indexing mbox file %s: "
 				"From-line not found where expected",
 				index->mailbox_path);
-		index->set_flags |= MAIL_INDEX_FLAG_FSCK;
+		index->set_flags |= MAIL_INDEX_HDR_FLAG_FSCK;
 		return -1;
 	}
 
 	/* parse the From-line */
-	internal_date = mbox_from_parse_date(data + 5, size - 5);
-	if (internal_date == (time_t)-1)
-		internal_date = ioloop_time;
+	received_date = mbox_from_parse_date(data + 5, size - 5);
+	if (received_date == (time_t)-1)
+		received_date = ioloop_time;
 
 	i_stream_skip(input, pos+1);
 	abs_start_offset = input->start_offset + input->v_offset;
@@ -57,19 +59,16 @@
 	mbox_skip_header(input);
 	eoh_offset = input->v_offset;
 
-	/* add message to index */
-	rec = index->append_begin(index);
-	if (rec == NULL)
-		return -1;
-
-	update = index->update_begin(index, rec);
+	index_flags = 0;
 
-	index->update_field_raw(update, DATA_HDR_INTERNAL_DATE,
-				&internal_date, sizeof(internal_date));
+	if (!mail_cache_add(trans_ctx, rec, MAIL_CACHE_RECEIVED_DATE,
+			    &received_date, sizeof(received_date)))
+		return -1;
 
-	/* location = offset to beginning of headers in message */
-	index->update_field_raw(update, DATA_FIELD_LOCATION,
-				&abs_start_offset, sizeof(uoff_t));
+	/* location offset = beginning of headers in message */
+	if (!mail_cache_add(trans_ctx, rec, MAIL_CACHE_LOCATION_OFFSET,
+			    &abs_start_offset, sizeof(abs_start_offset)))
+		return -1;
 
 	/* parse the header and cache wanted fields. get the message flags
 	   from Status and X-Status fields. temporarily limit the stream length
@@ -84,12 +83,12 @@
 	i_stream_seek(input, abs_start_offset - input->start_offset);
 
 	i_stream_set_read_limit(input, eoh_offset);
-	mail_index_update_headers(update, input, 0, mbox_header_cb, &ctx);
+	//FIXME:mail_index_update_headers(update, input, 0, mbox_header_cb, &ctx);
 
 	i_stream_seek(input, input->v_limit);
 	i_stream_set_read_limit(input, 0);
 
-	ret = 1;
+	dirty = ctx.content_length_broken;
 	if (index->header->messages_count == 0 &&
 	    ctx.uid_validity != index->header->uid_validity) {
 		/* UID validity is different */
@@ -103,66 +102,53 @@
 			/* we have to write it to mbox */
 			if (index->mbox_lock_type != MAIL_LOCK_EXCLUSIVE) {
 				/* try again */
-				ret = 0;
-			} else {
-				index->header->flags |=
-					MAIL_INDEX_FLAG_DIRTY_MESSAGES;
-				rec->index_flags |= INDEX_MAIL_FLAG_DIRTY;
+				return 0;
 			}
+
+			dirty = TRUE;
 		}
 	}
 
 	if (ctx.uid >= index->header->next_uid) {
 		/* X-UID header looks ok */
-		if (ret != 0)
-			index->header->next_uid = ctx.uid;
-		dirty = ctx.content_length_broken;
+		index->header->next_uid = ctx.uid;
 	} else if (!index->mailbox_readonly) {
 		/* Write X-UID for it */
 		dirty = TRUE;
 	} else {
 		/* save MD5 */
 		md5_final(&ctx.md5, md5_digest);
-		index->update_field_raw(update, DATA_FIELD_MD5,
-					md5_digest, sizeof(md5_digest));
-		dirty = FALSE;
+
+		if (!mail_cache_add(trans_ctx, rec, MAIL_CACHE_MD5,
+				    md5_digest, sizeof(md5_digest)))
+			return -1;
 	}
 
 	if (dirty && !index->mailbox_readonly) {
 		if (index->mbox_lock_type != MAIL_LOCK_EXCLUSIVE) {
 			/* try again */
-			ret = 0;
-		} else {
-			index->header->flags |= MAIL_INDEX_FLAG_DIRTY_MESSAGES;
-			rec->index_flags |= INDEX_MAIL_FLAG_DIRTY;
+			return 0;
 		}
+
+		index->header->flags |= MAIL_INDEX_HDR_FLAG_DIRTY_MESSAGES;
+		index_flags |= MAIL_INDEX_FLAG_DIRTY;
 	}
 
-	if (ret <= 0) {
-		index->update_abort(update);
-		index->append_abort(index, rec);
-	} else {
-		if (!index->update_end(update)) {
-			index->append_abort(index, rec);
-			ret = -1;
-		} else {
-			/* save message flags */
-			rec->msg_flags = ctx.flags;
-			mail_index_mark_flag_changes(index, rec, 0,
-						     rec->msg_flags);
-			ret = 1;
+	/* save message flags */
+	rec->msg_flags = ctx.flags;
+	mail_index_mark_flag_changes(index, rec, 0, rec->msg_flags);
 
-			if (!index->append_end(index, rec))
-				ret = -1;
-		}
-	}
+	if (!mail_cache_add(trans_ctx, rec, MAIL_CACHE_INDEX_FLAGS,
+			    &index_flags, sizeof(index_flags)))
+		return -1;
 
-	mbox_header_free_context(&ctx);
-	return ret;
+	return 1;
 }
 
-int mbox_index_append(struct mail_index *index, struct istream *input)
+int mbox_index_append_stream(struct mail_index *index, struct istream *input)
 {
+	struct mail_cache_transaction_ctx *trans_ctx;
+	struct mail_index_record *rec;
 	uoff_t offset;
 	int ret;
 
@@ -174,6 +160,9 @@
 	if (!index->set_lock(index, MAIL_LOCK_EXCLUSIVE))
 		return FALSE;
 
+	if (mail_cache_transaction_begin(index->cache, TRUE, &trans_ctx) <= 0)
+		return FALSE;
+
 	do {
 		offset = input->v_offset;
 		if (input->start_offset + input->v_offset != 0) {
@@ -185,8 +174,9 @@
 						"LF not found where expected",
 						index->mailbox_path);
 
-				index->set_flags |= MAIL_INDEX_FLAG_FSCK;
-				return FALSE;
+				index->set_flags |= MAIL_INDEX_HDR_FLAG_FSCK;
+				ret = -1;
+				break;
 			}
 		}
 
@@ -195,8 +185,15 @@
 			break;
 		}
 
+		/* add message to index */
+		rec = index->append(index);
+		if (rec == NULL) {
+			ret = -1;
+			break;
+		}
+
 		t_push();
-		ret = mbox_index_append_next(index, input);
+		ret = mbox_index_append_next(index, rec, trans_ctx, input);
 		t_pop();
 
 		if (ret == 0) {
@@ -206,10 +203,18 @@
 		}
 	} while (ret > 0);
 
-	if (index->mbox_lock_type == MAIL_LOCK_EXCLUSIVE) {
+	if (ret >= 0 && index->mbox_lock_type == MAIL_LOCK_EXCLUSIVE) {
 		/* Write missing X-IMAPbase and new/changed X-UID headers */
-		return mbox_index_rewrite(index);
+		if (!mbox_index_rewrite(index))
+			ret = -1;
 	}
+
+	if (ret >= 0) {
+		if (!mail_cache_transaction_commit(trans_ctx))
+			ret = -1;
+	}
+	if (!mail_cache_transaction_end(trans_ctx))
+		ret = -1;
 
 	return ret >= 0;
 }

Index: mbox-index.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-index.c,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -d -r1.76 -r1.77
--- mbox-index.c	21 Jul 2003 14:35:39 -0000	1.76
+++ mbox-index.c	6 Aug 2003 20:15:32 -0000	1.77
@@ -6,8 +6,8 @@
 #include "mbox-index.h"
 #include "mbox-lock.h"
 #include "mail-index-util.h"
-#include "mail-index-data.h"
 #include "mail-custom-flags.h"
+#include "mail-cache.h"
 
 #include <stdlib.h>
 #include <unistd.h>
@@ -138,10 +138,6 @@
 	ctx->content_length = (uoff_t)-1;
 }
 
-void mbox_header_free_context(struct mbox_header_context *ctx __attr_unused__)
-{
-}
-
 static enum mail_flags
 mbox_get_status_flags(const unsigned char *value, size_t len)
 {
@@ -694,52 +690,36 @@
 			   struct mail_index_record *rec,
 			   uoff_t *offset, uoff_t *hdr_size, uoff_t *body_size)
 {
-	struct mail_index_data_record_header *data_hdr;
-	const uoff_t *location;
-	size_t size;
-
 	if (offset != NULL) {
-		location = index->lookup_field_raw(index, rec,
-						   DATA_FIELD_LOCATION, &size);
-		if (location == NULL) {
-			index_data_set_corrupted(index->data,
+		if (!mail_cache_copy_fixed_field(index->cache, rec,
+						 MAIL_CACHE_LOCATION_OFFSET,
+						 offset, sizeof(*offset))) {
+			mail_cache_set_corrupted(index->cache,
 				"Missing location field for record %u",
 				rec->uid);
 			return FALSE;
-		} else if (size != sizeof(uoff_t) || *location > OFF_T_MAX) {
-			index_data_set_corrupted(index->data,
-				"Invalid location field for record %u",
-				rec->uid);
-			return FALSE;
 		}
-
-		*offset = *location;
 	}
 
-	if (hdr_size != NULL || body_size != NULL) {
-		data_hdr = mail_index_data_lookup_header(index->data, rec);
-		if (data_hdr == NULL) {
-			index_set_corrupted(index,
-				"Missing data header for record %u", rec->uid);
-			return FALSE;
-		}
-
-		if ((rec->data_fields & DATA_HDR_HEADER_SIZE) == 0) {
-			index_set_corrupted(index,
+	if (hdr_size != NULL) {
+		if (!mail_cache_copy_fixed_field(index->cache, rec,
+						 MAIL_CACHE_HEADER_SIZE,
+						 hdr_size, sizeof(*hdr_size))) {
+			mail_cache_set_corrupted(index->cache,
 				"Missing header size for record %u", rec->uid);
 			return FALSE;
 		}
+	}
 
-		if ((rec->data_fields & DATA_HDR_BODY_SIZE) == 0) {
-			index_set_corrupted(index,
+	if (body_size != NULL) {
+		if (!mail_cache_copy_fixed_field(index->cache, rec,
+						 MAIL_CACHE_BODY_SIZE,
+						 body_size,
+						 sizeof(*body_size))) {
+			mail_cache_set_corrupted(index->cache,
 				"Missing body size for record %u", rec->uid);
 			return FALSE;
 		}
-
-		if (hdr_size != NULL)
-			*hdr_size = data_hdr->header_size;
-		if (body_size != NULL)
-			*body_size = data_hdr->body_size;
 	}
 
 	return TRUE;
@@ -805,8 +785,8 @@
 	if (first_seq == 1) {
 		/* Our message containing X-IMAPbase was deleted.
 		   Get it back there. */
-		index->header->flags |= MAIL_INDEX_FLAG_DIRTY_MESSAGES |
-			MAIL_INDEX_FLAG_DIRTY_CUSTOMFLAGS;
+		index->header->flags |= MAIL_INDEX_HDR_FLAG_DIRTY_MESSAGES |
+			MAIL_INDEX_HDR_FLAG_DIRTY_CUSTOMFLAGS;
 	}
 	return TRUE;
 }
@@ -816,26 +796,51 @@
 				   unsigned int seq, enum mail_flags flags,
 				   int external_change)
 {
+        enum mail_index_record_flag index_flags;
+
 	if (!mail_index_update_flags(index, rec, seq, flags, external_change))
 		return FALSE;
 
 	if (!external_change) {
-		rec->index_flags |= INDEX_MAIL_FLAG_DIRTY;
-		index->header->flags |= MAIL_INDEX_FLAG_DIRTY_MESSAGES;
+		index_flags = mail_cache_get_index_flags(index->cache, rec);
+		if ((index_flags & MAIL_INDEX_FLAG_DIRTY) == 0) {
+			if (mail_cache_lock(index->cache, FALSE) <= 0)
+				return FALSE;
+			mail_cache_unlock_later(index->cache);
+
+			index_flags |= MAIL_INDEX_FLAG_DIRTY;
+			mail_cache_update_index_flags(index->cache, rec,
+						      index_flags);
+
+			index->header->flags |=
+				MAIL_INDEX_HDR_FLAG_DIRTY_MESSAGES;
+		}
 	}
 	return TRUE;
 }
 
-static int mbox_index_append_end(struct mail_index *index,
-				 struct mail_index_record *rec)
+static struct mail_index_record *mbox_index_append(struct mail_index *index)
 {
-	if (!mail_index_append_end(index, rec))
-		return FALSE;
-
 	/* update last_uid in X-IMAPbase */
-	index->header->flags |= MAIL_INDEX_FLAG_DIRTY_MESSAGES |
-		MAIL_INDEX_FLAG_DIRTY_CUSTOMFLAGS;
-	return TRUE;
+	index->header->flags |= MAIL_INDEX_HDR_FLAG_DIRTY_MESSAGES |
+		MAIL_INDEX_HDR_FLAG_DIRTY_CUSTOMFLAGS;
+
+	return mail_index_append(index);
+}
+
+static time_t mbox_get_received_date(struct mail_index *index,
+				     struct mail_index_record *rec)
+{
+	time_t date;
+
+	if (mail_cache_copy_fixed_field(index->cache, rec,
+					MAIL_CACHE_RECEIVED_DATE,
+					&date, sizeof(date)))
+		return date;
+
+	mail_cache_set_corrupted(index->cache,
+		"Missing internal date for record %u", rec->uid);
+	return (time_t)-1;
 }
 
 struct mail_index mbox_index = {
@@ -844,28 +849,18 @@
 	mbox_index_set_lock,
 	mbox_index_try_lock,
         mail_index_set_lock_notify_callback,
-	mbox_index_rebuild,
+	mail_index_rebuild,
 	mail_index_fsck,
 	mbox_index_sync,
 	mail_index_get_header,
 	mail_index_lookup,
 	mail_index_next,
         mail_index_lookup_uid_range,
-	mail_index_lookup_field,
-	mail_index_lookup_field_raw,
-	mail_index_cache_fields_later,
 	mbox_open_mail,
-	mail_get_internal_date,
+	mbox_get_received_date,
 	mbox_index_expunge,
 	mbox_index_update_flags,
-	mail_index_append_begin,
-	mbox_index_append_end,
-	mail_index_append_abort,
-	mail_index_update_begin,
-	mail_index_update_end,
-	mail_index_update_abort,
-	mail_index_update_field,
-	mail_index_update_field_raw,
+	mbox_index_append,
 	mail_index_get_last_error,
 	mail_index_get_last_error_text,
 

Index: mbox-index.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-index.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- mbox-index.h	15 Jun 2003 03:42:28 -0000	1.30
+++ mbox-index.h	6 Aug 2003 20:15:32 -0000	1.31
@@ -35,7 +35,6 @@
 void mbox_header_init_context(struct mbox_header_context *ctx,
 			      struct mail_index *index,
 			      struct istream *input);
-void mbox_header_free_context(struct mbox_header_context *ctx);
 void mbox_header_cb(struct message_part *part,
 		    struct message_header_line *hdr, void *context);
 void mbox_keywords_parse(const unsigned char *value, size_t len,
@@ -50,20 +49,19 @@
 int mbox_verify_end_of_body(struct istream *input, uoff_t end_offset);
 int mbox_mail_get_location(struct mail_index *index,
 			   struct mail_index_record *rec,
-			   uoff_t *offset, uoff_t *hdr_size, uoff_t *body_size);
+			   uoff_t *offset, uoff_t *hdr_size, uoff_t *full_size);
 
 struct mail_index *
 mbox_index_alloc(const char *mbox_path, const char *index_dir,
 		 const char *control_dir);
-int mbox_index_rebuild(struct mail_index *index);
 int mbox_index_sync(struct mail_index *index, int minimal_sync,
 		    enum mail_lock_type lock_type, int *changes);
 int mbox_sync_full(struct mail_index *index);
 struct istream *mbox_open_mail(struct mail_index *index,
 			       struct mail_index_record *rec,
-			       time_t *internal_date, int *deleted);
+			       time_t *received_date, int *deleted);
 
-int mbox_index_append(struct mail_index *index, struct istream *input);
+int mbox_index_append_stream(struct mail_index *index, struct istream *input);
 
 time_t mbox_from_parse_date(const unsigned char *msg, size_t size);
 const char *mbox_from_create(const char *sender, time_t time);

Index: mbox-open.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-open.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- mbox-open.c	5 Jan 2003 13:09:52 -0000	1.20
+++ mbox-open.c	6 Aug 2003 20:15:32 -0000	1.21
@@ -3,7 +3,6 @@
 #include "lib.h"
 #include "istream.h"
 #include "mbox-index.h"
-#include "mail-index-data.h"
 #include "mail-index-util.h"
 
 #include <stdlib.h>
@@ -12,7 +11,7 @@
 
 struct istream *mbox_open_mail(struct mail_index *index,
 			       struct mail_index_record *rec,
-			       time_t *internal_date, int *deleted)
+			       time_t *received_date, int *deleted)
 {
 	struct istream *input;
 	uoff_t offset, hdr_size, body_size;
@@ -32,8 +31,8 @@
 	if (input == NULL)
 		return NULL;
 
-	if (internal_date != NULL)
-		*internal_date = mail_get_internal_date(index, rec);
+	if (received_date != NULL)
+		*received_date = index->get_received_date(index, rec);
 
 	i_assert(index->mbox_sync_counter == index->mbox_lock_counter);
 

Index: mbox-rewrite.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-rewrite.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- mbox-rewrite.c	15 Jun 2003 03:42:28 -0000	1.58
+++ mbox-rewrite.c	6 Aug 2003 20:15:32 -0000	1.59
@@ -11,6 +11,7 @@
 #include "mbox-lock.h"
 #include "mail-index-util.h"
 #include "mail-custom-flags.h"
+#include "mail-cache.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -38,18 +39,25 @@
 };
 
 /* Remove dirty flag from all messages */
-static void reset_dirty_flags(struct mail_index *index)
+static int reset_dirty_flags(struct mail_index *index)
 {
 	struct mail_index_record *rec;
+	enum mail_index_record_flag index_flags;
 
 	rec = index->lookup(index, 1);
 	while (rec != NULL) {
-		rec->index_flags &= ~INDEX_MAIL_FLAG_DIRTY;
+		index_flags = mail_cache_get_index_flags(index->cache, rec);
+		if ((index_flags & MAIL_INDEX_FLAG_DIRTY) != 0) {
+			if (!mail_cache_update_index_flags(index->cache, rec, index_flags))
+				return FALSE;
+		}
+
 		rec = index->next(index, rec);
 	}
 
-	index->header->flags &= ~(MAIL_INDEX_FLAG_DIRTY_MESSAGES |
-				  MAIL_INDEX_FLAG_DIRTY_CUSTOMFLAGS);
+	index->header->flags &= ~(MAIL_INDEX_HDR_FLAG_DIRTY_MESSAGES |
+				  MAIL_INDEX_HDR_FLAG_DIRTY_CUSTOMFLAGS);
+	return TRUE;
 }
 
 static int mbox_write(struct mail_index *index, struct istream *input,
@@ -553,7 +561,8 @@
 }
 
 #define INDEX_DIRTY_FLAGS \
-        (MAIL_INDEX_FLAG_DIRTY_MESSAGES | MAIL_INDEX_FLAG_DIRTY_CUSTOMFLAGS)
+	(MAIL_INDEX_HDR_FLAG_DIRTY_MESSAGES | \
+	 MAIL_INDEX_HDR_FLAG_DIRTY_CUSTOMFLAGS)
 
 int mbox_index_rewrite(struct mail_index *index)
 {
@@ -567,7 +576,7 @@
 	uoff_t offset, hdr_size, body_size, dirty_offset, wanted_offset;
 	const char *path;
 	unsigned int seq;
-	int tmp_fd, failed, dirty_found, rewrite, no_locking;
+	int tmp_fd, failed, dirty, dirty_found, rewrite, no_locking;
 
 	i_assert(!index->mailbox_readonly);
 	i_assert(index->lock_type == MAIL_LOCK_UNLOCK ||
@@ -633,7 +642,7 @@
 		return !failed;
 	}
 
-	if (index->header->flags & MAIL_INDEX_FLAG_DIRTY_CUSTOMFLAGS) {
+	if (index->header->flags & MAIL_INDEX_HDR_FLAG_DIRTY_CUSTOMFLAGS) {
 		/* need to update X-IMAPbase in first message */
 		dirty_found = TRUE;
 	} else {
@@ -649,7 +658,14 @@
 	failed = FALSE; seq = 1;
 	rec = index->lookup(index, 1);
 	while (rec != NULL) {
-		if (dirty_found || (rec->index_flags & INDEX_MAIL_FLAG_DIRTY)) {
+		if (dirty_found)
+			dirty = FALSE;
+		else {
+			dirty = (mail_cache_get_index_flags(index->cache, rec) &
+				 MAIL_INDEX_FLAG_DIRTY) != 0;
+		}
+
+		if (dirty_found || dirty) {
 			/* get offset to beginning of mail headers */
 			if (!mbox_mail_get_location(index, rec, &offset,
 						    &hdr_size, &body_size)) {
@@ -659,30 +675,27 @@
 			}
 
 			if (offset < input->v_offset) {
-				index_set_corrupted(index,
-						    "Invalid message offset");
+				mail_cache_set_corrupted(index->cache,
+					"Invalid message offset");
 				failed = TRUE;
 				break;
 			}
 
 			if (offset + hdr_size + body_size > input->v_size) {
-				index_set_corrupted(index,
-						    "Invalid message size");
+				mail_cache_set_corrupted(index->cache,
+					"Invalid message size");
 				failed = TRUE;
 				break;
 			}
-		}
 
-		if (!dirty_found &&
-		    (rec->index_flags & INDEX_MAIL_FLAG_DIRTY)) {
-			/* first dirty message */
-			dirty_found = TRUE;
-			dirty_offset = offset;
+			if (!dirty_found) {
+				/* first dirty message */
+				dirty_found = TRUE;
+				dirty_offset = offset;
 
-			i_stream_seek(input, dirty_offset);
-		}
+				i_stream_seek(input, dirty_offset);
+			}
 
-		if (dirty_found) {
 			/* write the From-line */
 			if (!mbox_write(index, input, output, offset)) {
 				failed = TRUE;
@@ -748,8 +761,10 @@
 		}
 	}
 
-	if (!failed)
-		reset_dirty_flags(index);
+	if (!failed) {
+		if (!reset_dirty_flags(index))
+			failed = TRUE;
+	}
 
 	i_stream_unref(input);
 	o_stream_unref(output);

Index: mbox-sync-full.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-sync-full.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- mbox-sync-full.c	23 Jul 2003 00:29:32 -0000	1.14
+++ mbox-sync-full.c	6 Aug 2003 20:15:32 -0000	1.15
@@ -8,11 +8,14 @@
 #include "mbox-index.h"
 #include "mbox-lock.h"
 #include "mail-index-util.h"
+#include "mail-cache.h"
 
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 
+#if 0
+
 static void skip_line(struct istream *input)
 {
 	const unsigned char *msg;
@@ -34,21 +37,25 @@
 			 struct mail_index_record *rec,
 			 unsigned int uid, unsigned char current_digest[16])
 {
-	const unsigned char *old_digest;
+	const void *old_digest;
 	size_t size;
 
-	/* MD5 sums must match */
-	old_digest = index->lookup_field_raw(index, rec, DATA_FIELD_MD5, &size);
-	if (old_digest == NULL)
+	if (uid != 0) {
+		/* X-UID header - no need to check more */
 		return uid == rec->uid;
+	}
 
-	return size >= 16 && memcmp(old_digest, current_digest, 16) == 0 &&
-		(uid == 0 || uid == rec->uid);
+	/* check if MD5 sums match */
+	if (!mail_cache_lookup_field(index->cache, rec, MAIL_CACHE_MD5,
+				     &old_digest, &size))
+		return FALSE;
+
+	return memcmp(old_digest, current_digest, 16) == 0;
 }
 
 static int mail_update_header_size(struct mail_index *index,
 				   struct mail_index_record *rec,
-				   struct mail_index_update *update,
+				   struct mail_cache_transaction_ctx *ctx,
 				   struct message_size *hdr_size)
 {
 	const void *part_data;
@@ -105,14 +112,14 @@
 	if (uid_validity == index->header->uid_validity)
 		return TRUE;
 
-	index->header->flags |= MAIL_INDEX_FLAG_DIRTY_MESSAGES |
-		MAIL_INDEX_FLAG_DIRTY_CUSTOMFLAGS;
+	index->header->flags |= MAIL_INDEX_HDR_FLAG_DIRTY_MESSAGES |
+		MAIL_INDEX_HDR_FLAG_DIRTY_CUSTOMFLAGS;
 
 	if (uid_validity == 0) {
 		/* X-IMAPbase header isn't written yet */
 	} else {
 		/* UID validity has changed - rebuild whole index */
-		index->set_flags |= MAIL_INDEX_FLAG_REBUILD;
+		index->set_flags |= MAIL_INDEX_HDR_FLAG_REBUILD;
 		return FALSE;
 	}
 
@@ -386,4 +393,10 @@
 	}
 
 	return !failed;
+}
+#endif
+
+int mbox_sync_full(struct mail_index *index)
+{
+	// FIXME
 }

Index: mbox-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mbox/mbox-sync.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- mbox-sync.c	23 Jul 2003 00:29:32 -0000	1.32
+++ mbox-sync.c	6 Aug 2003 20:15:32 -0000	1.33
@@ -141,7 +141,8 @@
 			if (!mbox_lock_and_sync_full(index, data_lock_type))
 				return FALSE;
 
-			if ((index->set_flags & MAIL_INDEX_FLAG_REBUILD) != 0) {
+			if ((index->set_flags &
+			     MAIL_INDEX_HDR_FLAG_REBUILD) != 0) {
 				/* uidvalidity probably changed, rebuild */
 				if (!index->rebuild(index))
 					return FALSE;

--- mbox-rebuild.c DELETED ---



More information about the dovecot-cvs mailing list