[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-file.c, 1.8, 1.9 mbox-file.h, 1.2, 1.3 mbox-lock.c, 1.14, 1.15 mbox-lock.h, 1.1, 1.2 mbox-mail.c, 1.25, 1.26 mbox-save.c, 1.79, 1.80 mbox-storage.c, 1.116, 1.117 mbox-storage.h, 1.36, 1.37 mbox-sync-parse.c, 1.38, 1.39 mbox-sync-private.h, 1.48, 1.49 mbox-sync-rewrite.c, 1.45, 1.46 mbox-sync-update.c, 1.32, 1.33 mbox-sync.c, 1.145, 1.146 mbox-transaction.c, 1.11, 1.12

cras at dovecot.org cras at dovecot.org
Fri Apr 8 16:13:51 EEST 2005


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

Modified Files:
	mbox-file.c mbox-file.h mbox-lock.c mbox-lock.h mbox-mail.c 
	mbox-save.c mbox-storage.c mbox-storage.h mbox-sync-parse.c 
	mbox-sync-private.h mbox-sync-rewrite.c mbox-sync-update.c 
	mbox-sync.c mbox-transaction.c 
Log Message:
Moved mbox/maildir-specific variables from struct index_mailbox to
mbox_mailbox and maildir_mailbox.



Index: mbox-file.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-file.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- mbox-file.c	29 Mar 2005 13:33:08 -0000	1.8
+++ mbox-file.c	8 Apr 2005 13:13:48 -0000	1.9
@@ -9,113 +9,113 @@
 
 #include <sys/stat.h>
 
-int mbox_file_open(struct index_mailbox *ibox)
+int mbox_file_open(struct mbox_mailbox *mbox)
 {
 	struct stat st;
 	int fd;
 
-	i_assert(ibox->mbox_fd == -1);
+	i_assert(mbox->mbox_fd == -1);
 
-	if (ibox->mbox_file_stream != NULL) {
+	if (mbox->mbox_file_stream != NULL) {
 		/* read-only mbox stream */
-		i_assert(ibox->mbox_readonly);
+		i_assert(mbox->mbox_readonly);
 		return 0;
 	}
 
-	fd = open(ibox->path, ibox->mbox_readonly ? O_RDONLY : O_RDWR);
-	if (fd == -1 && errno == EACCES && !ibox->mbox_readonly) {
-                ibox->mbox_readonly = TRUE;
-		fd = open(ibox->path, O_RDONLY);
+	fd = open(mbox->path, mbox->mbox_readonly ? O_RDONLY : O_RDWR);
+	if (fd == -1 && errno == EACCES && !mbox->mbox_readonly) {
+                mbox->mbox_readonly = TRUE;
+		fd = open(mbox->path, O_RDONLY);
 	}
 
 	if (fd == -1) {
-		mbox_set_syscall_error(ibox, "open()");
+		mbox_set_syscall_error(mbox, "open()");
 		return -1;
 	}
 
 	if (fstat(fd, &st) < 0) {
-		mbox_set_syscall_error(ibox, "fstat()");
+		mbox_set_syscall_error(mbox, "fstat()");
 		(void)close(fd);
 		return -1;
 	}
 
-	ibox->mbox_writeonly = S_ISFIFO(st.st_mode);
-	ibox->mbox_fd = fd;
-	ibox->mbox_dev = st.st_dev;
-	ibox->mbox_ino = st.st_ino;
+	mbox->mbox_writeonly = S_ISFIFO(st.st_mode);
+	mbox->mbox_fd = fd;
+	mbox->mbox_dev = st.st_dev;
+	mbox->mbox_ino = st.st_ino;
 	return 0;
 }
 
-void mbox_file_close(struct index_mailbox *ibox)
+void mbox_file_close(struct mbox_mailbox *mbox)
 {
-	mbox_file_close_stream(ibox);
+	mbox_file_close_stream(mbox);
 
-	if (ibox->mbox_fd != -1) {
-		if (close(ibox->mbox_fd) < 0)
+	if (mbox->mbox_fd != -1) {
+		if (close(mbox->mbox_fd) < 0)
 			i_error("close(mbox) failed: %m");
-		ibox->mbox_fd = -1;
+		mbox->mbox_fd = -1;
 	}
 }
 
-int mbox_file_open_stream(struct index_mailbox *ibox)
+int mbox_file_open_stream(struct mbox_mailbox *mbox)
 {
-	if (ibox->mbox_stream != NULL)
+	if (mbox->mbox_stream != NULL)
 		return 0;
 
-	if (ibox->mbox_file_stream != NULL) {
+	if (mbox->mbox_file_stream != NULL) {
 		/* read-only mbox stream */
-		i_assert(ibox->mbox_fd == -1 && ibox->mbox_readonly);
+		i_assert(mbox->mbox_fd == -1 && mbox->mbox_readonly);
 
-		ibox->mbox_stream =
+		mbox->mbox_stream =
 			i_stream_create_raw_mbox(default_pool,
-						 ibox->mbox_file_stream);
+						 mbox->mbox_file_stream);
 		return 0;
 	}
 
-	if (ibox->mbox_fd == -1) {
-		if (mbox_file_open(ibox) < 0)
+	if (mbox->mbox_fd == -1) {
+		if (mbox_file_open(mbox) < 0)
 			return -1;
 	}
 
-	if (ibox->mbox_writeonly) {
-		ibox->mbox_file_stream =
+	if (mbox->mbox_writeonly) {
+		mbox->mbox_file_stream =
 			i_stream_create_from_data(default_pool, NULL, 0);
-	} else if (ibox->mail_read_mmaped) {
-		ibox->mbox_file_stream =
-			i_stream_create_mmap(ibox->mbox_fd, default_pool,
+	} else if (mbox->ibox.mail_read_mmaped) {
+		mbox->mbox_file_stream =
+			i_stream_create_mmap(mbox->mbox_fd, default_pool,
 					     MAIL_MMAP_BLOCK_SIZE,
 					     0, 0, FALSE);
 	} else {
-		ibox->mbox_file_stream =
-			i_stream_create_file(ibox->mbox_fd, default_pool,
+		mbox->mbox_file_stream =
+			i_stream_create_file(mbox->mbox_fd, default_pool,
 					     MAIL_READ_BLOCK_SIZE, FALSE);
 	}
 
-	ibox->mbox_stream =
-		i_stream_create_raw_mbox(default_pool, ibox->mbox_file_stream);
+	mbox->mbox_stream =
+		i_stream_create_raw_mbox(default_pool, mbox->mbox_file_stream);
 	return 0;
 }
 
-void mbox_file_close_stream(struct index_mailbox *ibox)
+void mbox_file_close_stream(struct mbox_mailbox *mbox)
 {
-	if (ibox->mbox_stream != NULL) {
-		i_stream_unref(ibox->mbox_stream);
-		ibox->mbox_stream = NULL;
+	if (mbox->mbox_stream != NULL) {
+		i_stream_unref(mbox->mbox_stream);
+		mbox->mbox_stream = NULL;
 	}
 
-	if (ibox->mbox_file_stream != NULL) {
-		if (ibox->mbox_fd == -1) {
+	if (mbox->mbox_file_stream != NULL) {
+		if (mbox->mbox_fd == -1) {
 			/* read-only mbox stream */
-			i_assert(ibox->mbox_readonly);
+			i_assert(mbox->mbox_readonly);
 		} else {
-			i_stream_close(ibox->mbox_file_stream);
-			i_stream_unref(ibox->mbox_file_stream);
-			ibox->mbox_file_stream = NULL;
+			i_stream_close(mbox->mbox_file_stream);
+			i_stream_unref(mbox->mbox_file_stream);
+			mbox->mbox_file_stream = NULL;
 		}
 	}
 }
 
-int mbox_file_seek(struct index_mailbox *ibox, struct mail_index_view *view,
+int mbox_file_seek(struct mbox_mailbox *mbox, struct mail_index_view *view,
 		   uint32_t seq, int *deleted_r)
 {
 	const void *data;
@@ -124,48 +124,48 @@
 
 	*deleted_r = FALSE;
 
-	ret = mail_index_lookup_ext(view, seq, ibox->mbox_ext_idx, &data);
+	ret = mail_index_lookup_ext(view, seq, mbox->mbox_ext_idx, &data);
 	if (ret <= 0) {
 		if (ret < 0)
-			mail_storage_set_index_error(ibox);
+			mail_storage_set_index_error(&mbox->ibox);
 		else
 			*deleted_r = TRUE;
 		return -1;
 	}
 
 	if (data == NULL) {
-		mail_storage_set_critical(ibox->box.storage,
+		mail_storage_set_critical(&mbox->storage->storage,
 			"Cached message offset lost for seq %u in mbox file %s",
-			seq, ibox->path);
-		mail_index_mark_corrupted(ibox->index);
+			seq, mbox->path);
+		mail_index_mark_corrupted(mbox->ibox.index);
 		return -1;
 	}
 
 	offset = *((const uint64_t *)data);
-	if (istream_raw_mbox_seek(ibox->mbox_stream, offset) < 0) {
+	if (istream_raw_mbox_seek(mbox->mbox_stream, offset) < 0) {
 		if (offset == 0) {
-			mail_storage_set_error(ibox->box.storage,
+			mail_storage_set_error(&mbox->storage->storage,
 				"Mailbox isn't a valid mbox file");
 			return -1;
 		}
 
-		if (ibox->mbox_sync_dirty)
+		if (mbox->mbox_sync_dirty)
 			return 0;
 
-		mail_storage_set_critical(ibox->box.storage,
+		mail_storage_set_critical(&mbox->storage->storage,
 			"Cached message offset %s is invalid for mbox file %s",
-			dec2str(offset), ibox->path);
-		mail_index_mark_corrupted(ibox->index);
+			dec2str(offset), mbox->path);
+		mail_index_mark_corrupted(mbox->ibox.index);
 		return -1;
 	}
 
-	if (ibox->mbox_sync_dirty) {
+	if (mbox->mbox_sync_dirty) {
 		/* we're dirty - make sure this is the correct mail */
-		ret = mbox_sync_parse_match_mail(ibox, view, seq);
+		ret = mbox_sync_parse_match_mail(mbox, view, seq);
 		if (ret <= 0)
 			return ret;
 
-		ret = istream_raw_mbox_seek(ibox->mbox_stream, offset);
+		ret = istream_raw_mbox_seek(mbox->mbox_stream, offset);
 		i_assert(ret == 0);
 	}
 

Index: mbox-file.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-file.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- mbox-file.h	28 Aug 2004 16:39:54 -0000	1.2
+++ mbox-file.h	8 Apr 2005 13:13:48 -0000	1.3
@@ -1,13 +1,13 @@
 #ifndef __MBOX_FILE_H
 #define __MBOX_FILE_H
 
-int mbox_file_open(struct index_mailbox *ibox);
-void mbox_file_close(struct index_mailbox *ibox);
+int mbox_file_open(struct mbox_mailbox *mbox);
+void mbox_file_close(struct mbox_mailbox *mbox);
 
-int mbox_file_open_stream(struct index_mailbox *ibox);
-void mbox_file_close_stream(struct index_mailbox *ibox);
+int mbox_file_open_stream(struct mbox_mailbox *mbox);
+void mbox_file_close_stream(struct mbox_mailbox *mbox);
 
-int mbox_file_seek(struct index_mailbox *ibox, struct mail_index_view *view,
+int mbox_file_seek(struct mbox_mailbox *mbox, struct mail_index_view *view,
 		   uint32_t seq, int *deleted_r);
 
 #endif

Index: mbox-lock.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-lock.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- mbox-lock.c	29 Mar 2005 13:33:08 -0000	1.14
+++ mbox-lock.c	8 Apr 2005 13:13:48 -0000	1.15
@@ -36,7 +36,7 @@
 };
 
 struct mbox_lock_context {
-	struct index_mailbox *ibox;
+	struct mbox_mailbox *mbox;
 	int lock_status[MBOX_LOCK_COUNT];
 	int checked_file;
 
@@ -157,25 +157,25 @@
 
 static int mbox_file_open_latest(struct mbox_lock_context *ctx, int lock_type)
 {
-	struct index_mailbox *ibox = ctx->ibox;
+	struct mbox_mailbox *mbox = ctx->mbox;
 	struct stat st;
 
 	if (ctx->checked_file || lock_type == F_UNLCK)
 		return 0;
 
-	if (ibox->mbox_fd != -1) {
-		if (stat(ibox->path, &st) < 0) {
-			mbox_set_syscall_error(ibox, "stat()");
+	if (mbox->mbox_fd != -1) {
+		if (stat(mbox->path, &st) < 0) {
+			mbox_set_syscall_error(mbox, "stat()");
 			return -1;
 		}
 
-		if (st.st_ino != ibox->mbox_ino ||
-		    !CMP_DEV_T(st.st_dev, ibox->mbox_dev))
-			mbox_file_close(ibox);
+		if (st.st_ino != mbox->mbox_ino ||
+		    !CMP_DEV_T(st.st_dev, mbox->mbox_dev))
+			mbox_file_close(mbox);
 	}
 
-	if (ibox->mbox_fd == -1) {
-		if (mbox_file_open(ibox) < 0)
+	if (mbox->mbox_fd == -1) {
+		if (mbox_file_open(mbox) < 0)
 			return -1;
 	}
 
@@ -194,7 +194,7 @@
 		   dotlocking. */
 		lock_types = ctx->lock_type == F_WRLCK ||
 			(ctx->lock_type == F_UNLCK &&
-			 ctx->ibox->mbox_lock_type == F_WRLCK) ?
+			 ctx->mbox->mbox_lock_type == F_WRLCK) ?
 			write_locks : read_locks;
 
 		for (i = 0; lock_types[i] != (enum mbox_lock_type)-1; i++) {
@@ -216,7 +216,7 @@
 	}
 	ctx->dotlock_last_stale = stale;
 
-	index_storage_lock_notify(ctx->ibox, stale ?
+	index_storage_lock_notify(&ctx->mbox->ibox, stale ?
 				  MAILBOX_LOCK_NOTIFY_MAILBOX_OVERRIDE :
 				  MAILBOX_LOCK_NOTIFY_MAILBOX_ABORT,
 				  secs_left);
@@ -226,23 +226,23 @@
 static int mbox_lock_dotlock(struct mbox_lock_context *ctx, int lock_type,
 			     time_t max_wait_time __attr_unused__)
 {
-	struct index_mailbox *ibox = ctx->ibox;
+	struct mbox_mailbox *mbox = ctx->mbox;
 	struct dotlock_settings set;
 	int ret;
 
 	if (lock_type == F_UNLCK) {
-		if (!ibox->mbox_dotlocked)
+		if (!mbox->mbox_dotlocked)
 			return 1;
 
-		if (file_dotlock_delete(&ibox->mbox_dotlock) <= 0) {
-			mbox_set_syscall_error(ibox, "file_dotlock_delete()");
+		if (file_dotlock_delete(&mbox->mbox_dotlock) <= 0) {
+			mbox_set_syscall_error(mbox, "file_dotlock_delete()");
 			ret = -1;
 		}
-                ibox->mbox_dotlocked = FALSE;
+                mbox->mbox_dotlocked = FALSE;
 		return 1;
 	}
 
-	if (ibox->mbox_dotlocked)
+	if (mbox->mbox_dotlocked)
 		return 1;
 
         ctx->dotlock_last_stale = -1;
@@ -253,17 +253,17 @@
 	set.callback = dotlock_callback;
 	set.context = ctx;
 
-	ret = file_dotlock_create(&set, ibox->path, 0, &ibox->mbox_dotlock);
+	ret = file_dotlock_create(&set, mbox->path, 0, &mbox->mbox_dotlock);
 	if (ret < 0) {
-		mbox_set_syscall_error(ibox, "file_lock_dotlock()");
+		mbox_set_syscall_error(mbox, "file_lock_dotlock()");
 		return -1;
 	}
 	if (ret == 0) {
-		mail_storage_set_error(ibox->box.storage,
+		mail_storage_set_error(&mbox->storage->storage,
 				       "Timeout while waiting for lock");
 		return 0;
 	}
-	ibox->mbox_dotlocked = TRUE;
+	mbox->mbox_dotlocked = TRUE;
 
 	if (mbox_file_open_latest(ctx, lock_type) < 0)
 		return -1;
@@ -279,7 +279,7 @@
 	if (mbox_file_open_latest(ctx, lock_type) < 0)
 		return -1;
 
-	if (lock_type == F_UNLCK && ctx->ibox->mbox_fd == -1)
+	if (lock_type == F_UNLCK && ctx->mbox->mbox_fd == -1)
 		return 1;
 
 	if (lock_type == F_WRLCK)
@@ -290,9 +290,9 @@
 		lock_type = LOCK_UN;
 
         last_notify = 0;
-	while (flock(ctx->ibox->mbox_fd, lock_type | LOCK_NB) < 0) {
+	while (flock(ctx->mbox->mbox_fd, lock_type | LOCK_NB) < 0) {
 		if (errno != EWOULDBLOCK) {
-			mbox_set_syscall_error(ctx->ibox, "flock()");
+			mbox_set_syscall_error(ctx->mbox, "flock()");
 			return -1;
 		}
 
@@ -304,7 +304,7 @@
 			return 0;
 
 		if (now != last_notify) {
-			index_storage_lock_notify(ctx->ibox,
+			index_storage_lock_notify(&ctx->mbox->ibox,
 				MAILBOX_LOCK_NOTIFY_MAILBOX_ABORT,
 				max_wait_time - now);
 		}
@@ -325,7 +325,7 @@
 	if (mbox_file_open_latest(ctx, lock_type) < 0)
 		return -1;
 
-	if (lock_type == F_UNLCK && ctx->ibox->mbox_fd == -1)
+	if (lock_type == F_UNLCK && ctx->mbox->mbox_fd == -1)
 		return 1;
 
 	if (lock_type != F_UNLCK)
@@ -334,9 +334,9 @@
 		lock_type = F_ULOCK;
 
         last_notify = 0;
-	while (lockf(ctx->ibox->mbox_fd, lock_type, 0) < 0) {
+	while (lockf(ctx->mbox->mbox_fd, lock_type, 0) < 0) {
 		if (errno != EAGAIN) {
-			mbox_set_syscall_error(ctx->ibox, "lockf()");
+			mbox_set_syscall_error(ctx->mbox, "lockf()");
 			return -1;
 		}
 
@@ -348,7 +348,7 @@
 			return 0;
 
 		if (now != last_notify) {
-			index_storage_lock_notify(ctx->ibox,
+			index_storage_lock_notify(&ctx->mbox->ibox,
 				MAILBOX_LOCK_NOTIFY_MAILBOX_ABORT,
 				max_wait_time - now);
 		}
@@ -371,7 +371,7 @@
 	if (mbox_file_open_latest(ctx, lock_type) < 0)
 		return -1;
 
-	if (lock_type == F_UNLCK && ctx->ibox->mbox_fd == -1)
+	if (lock_type == F_UNLCK && ctx->mbox->mbox_fd == -1)
 		return 1;
 
 	memset(&fl, 0, sizeof(fl));
@@ -387,10 +387,10 @@
 		alarm(I_MIN(max_wait_time, 5));
 	}
 
-	while (fcntl(ctx->ibox->mbox_fd, wait_type, &fl) < 0) {
+	while (fcntl(ctx->mbox->mbox_fd, wait_type, &fl) < 0) {
 		if (errno != EINTR) {
 			if (errno != EAGAIN && errno != EACCES)
-				mbox_set_syscall_error(ctx->ibox, "fcntl()");
+				mbox_set_syscall_error(ctx->mbox, "fcntl()");
 			alarm(0);
 			return -1;
 		}
@@ -408,7 +408,7 @@
 			next_alarm = 5;
 		alarm(next_alarm);
 
-		index_storage_lock_notify(ctx->ibox,
+		index_storage_lock_notify(&ctx->mbox->ibox,
 					  MAILBOX_LOCK_NOTIFY_MAILBOX_ABORT,
 					  max_wait_time - now);
 	}
@@ -427,7 +427,7 @@
 	ctx->lock_type = lock_type;
 
 	lock_types = lock_type == F_WRLCK ||
-		(lock_type == F_UNLCK && ctx->ibox->mbox_lock_type == F_WRLCK) ?
+		(lock_type == F_UNLCK && ctx->mbox->mbox_lock_type == F_WRLCK) ?
 		write_locks : read_locks;
 	for (i = idx; lock_types[i] != (enum mbox_lock_type)-1; i++) {
 		type = lock_types[i];
@@ -444,30 +444,30 @@
 	return ret;
 }
 
-static int mbox_update_locking(struct index_mailbox *ibox, int lock_type)
+static int mbox_update_locking(struct mbox_mailbox *mbox, int lock_type)
 {
 	struct mbox_lock_context ctx;
 	time_t max_wait_time;
 	int ret, i, drop_locks;
 
-        index_storage_lock_notify_reset(ibox);
+        index_storage_lock_notify_reset(&mbox->ibox);
 
 	if (!lock_settings_initialized)
                 mbox_init_lock_settings();
 
-	if (ibox->mbox_fd == -1 && ibox->mbox_file_stream != NULL) {
+	if (mbox->mbox_fd == -1 && mbox->mbox_file_stream != NULL) {
 		/* read-only mbox stream. no need to lock. */
-		i_assert(ibox->mbox_readonly);
-		ibox->mbox_lock_type = lock_type;
+		i_assert(mbox->mbox_readonly);
+		mbox->mbox_lock_type = lock_type;
 		return TRUE;
 	}
 
 	max_wait_time = time(NULL) + lock_timeout;
 
 	memset(&ctx, 0, sizeof(ctx));
-	ctx.ibox = ibox;
+	ctx.mbox = mbox;
 
-	if (ibox->mbox_lock_type == F_WRLCK) {
+	if (mbox->mbox_lock_type == F_WRLCK) {
 		/* dropping to shared lock. first drop those that we
 		   don't remove completely. */
 		for (i = 0; i < MBOX_LOCK_COUNT; i++)
@@ -479,13 +479,13 @@
 		drop_locks = FALSE;
 	}
 
-	ibox->mbox_lock_type = lock_type;
+	mbox->mbox_lock_type = lock_type;
 	ret = mbox_lock_list(&ctx, lock_type, max_wait_time, 0);
 	if (ret <= 0) {
 		if (!drop_locks)
 			(void)mbox_unlock_files(&ctx);
 		if (ret == 0) {
-			mail_storage_set_error(ibox->box.storage,
+			mail_storage_set_error(&mbox->storage->storage,
 				"Timeout while waiting for lock");
 		}
 		return ret;
@@ -500,37 +500,37 @@
 		for (i = 0; read_locks[i] != (enum mbox_lock_type)-1; i++)
 			ctx.lock_status[read_locks[i]] = 0;
 
-		ibox->mbox_lock_type = F_WRLCK;
+		mbox->mbox_lock_type = F_WRLCK;
 		(void)mbox_lock_list(&ctx, F_UNLCK, 0, 0);
-		ibox->mbox_lock_type = F_RDLCK;
+		mbox->mbox_lock_type = F_RDLCK;
 	}
 
 	return 1;
 }
 
-int mbox_lock(struct index_mailbox *ibox, int lock_type,
+int mbox_lock(struct mbox_mailbox *mbox, int lock_type,
 	      unsigned int *lock_id_r)
 {
 	int ret;
 
 	/* allow only unlock -> shared/exclusive or exclusive -> shared */
 	i_assert(lock_type == F_RDLCK || lock_type == F_WRLCK);
-	i_assert(lock_type == F_RDLCK || ibox->mbox_lock_type != F_RDLCK);
+	i_assert(lock_type == F_RDLCK || mbox->mbox_lock_type != F_RDLCK);
 
-	if (ibox->mbox_lock_type == F_UNLCK) {
-		ret = mbox_update_locking(ibox, lock_type);
+	if (mbox->mbox_lock_type == F_UNLCK) {
+		ret = mbox_update_locking(mbox, lock_type);
 		if (ret <= 0)
 			return ret;
 
-		ibox->mbox_lock_id += 2;
+		mbox->mbox_lock_id += 2;
 	}
 
 	if (lock_type == F_RDLCK) {
-		ibox->mbox_shared_locks++;
-		*lock_id_r = ibox->mbox_lock_id;
+		mbox->mbox_shared_locks++;
+		*lock_id_r = mbox->mbox_lock_id;
 	} else {
-		ibox->mbox_excl_locks++;
-		*lock_id_r = ibox->mbox_lock_id + 1;
+		mbox->mbox_excl_locks++;
+		*lock_id_r = mbox->mbox_lock_id + 1;
 	}
 	return 1;
 }
@@ -542,46 +542,46 @@
 	if (mbox_lock_list(ctx, F_UNLCK, 0, 0) < 0)
 		ret = -1;
 
-	if (ctx->ibox->mail_read_mmaped) {
+	if (ctx->mbox->ibox.mail_read_mmaped) {
 		/* make sure we don't keep mmap() between locks */
-		mbox_file_close_stream(ctx->ibox);
+		mbox_file_close_stream(ctx->mbox);
 	}
 
-	ctx->ibox->mbox_lock_id += 2;
-	ctx->ibox->mbox_lock_type = F_UNLCK;
+	ctx->mbox->mbox_lock_id += 2;
+	ctx->mbox->mbox_lock_type = F_UNLCK;
 	return ret;
 }
 
-int mbox_unlock(struct index_mailbox *ibox, unsigned int lock_id)
+int mbox_unlock(struct mbox_mailbox *mbox, unsigned int lock_id)
 {
 	struct mbox_lock_context ctx;
 	int i;
 
-	i_assert(ibox->mbox_lock_id == (lock_id & ~1));
+	i_assert(mbox->mbox_lock_id == (lock_id & ~1));
 
 	if (lock_id & 1) {
 		/* dropping exclusive lock */
-		i_assert(ibox->mbox_excl_locks > 0);
-		if (--ibox->mbox_excl_locks > 0)
+		i_assert(mbox->mbox_excl_locks > 0);
+		if (--mbox->mbox_excl_locks > 0)
 			return 0;
-		if (ibox->mbox_shared_locks > 0) {
+		if (mbox->mbox_shared_locks > 0) {
 			/* drop to shared lock */
-			if (mbox_update_locking(ibox, F_RDLCK) < 0)
+			if (mbox_update_locking(mbox, F_RDLCK) < 0)
 				return -1;
 			return 0;
 		}
 	} else {
 		/* dropping shared lock */
-		i_assert(ibox->mbox_shared_locks > 0);
-		if (--ibox->mbox_shared_locks > 0)
+		i_assert(mbox->mbox_shared_locks > 0);
+		if (--mbox->mbox_shared_locks > 0)
 			return 0;
-		if (ibox->mbox_excl_locks > 0)
+		if (mbox->mbox_excl_locks > 0)
 			return 0;
 	}
 	/* all locks gone */
 
 	memset(&ctx, 0, sizeof(ctx));
-	ctx.ibox = ibox;
+	ctx.mbox = mbox;
 
 	for (i = 0; i < MBOX_LOCK_COUNT; i++)
 		ctx.lock_status[i] = 1;

Index: mbox-lock.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-lock.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- mbox-lock.h	6 May 2004 01:22:25 -0000	1.1
+++ mbox-lock.h	8 Apr 2005 13:13:48 -0000	1.2
@@ -3,8 +3,8 @@
 
 /* NOTE: if mbox file is not open, it's opened. if it is open but file has
    been overwritten (ie. inode has changed), it's reopened. */
-int mbox_lock(struct index_mailbox *ibox, int lock_type,
+int mbox_lock(struct mbox_mailbox *mbox, int lock_type,
 	      unsigned int *lock_id_r);
-int mbox_unlock(struct index_mailbox *ibox, unsigned int lock_id);
+int mbox_unlock(struct mbox_mailbox *mbox, unsigned int lock_id);
 
 #endif

Index: mbox-mail.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-mail.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- mbox-mail.c	29 Mar 2005 16:48:47 -0000	1.25
+++ mbox-mail.c	8 Apr 2005 13:13:48 -0000	1.26
@@ -18,7 +18,7 @@
 {
 	struct mbox_transaction_context *t =
 		(struct mbox_transaction_context *)mail->trans;
-	struct index_mailbox *ibox = mail->ibox;
+	struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox;
 	enum mbox_sync_flags sync_flags = 0;
 	int ret, deleted;
 
@@ -26,26 +26,26 @@
 		return 0;
 
 __again:
-	if (ibox->mbox_lock_type == F_UNLCK) {
+	if (mbox->mbox_lock_type == F_UNLCK) {
 		sync_flags |= MBOX_SYNC_LOCK_READING;
-		if (mbox_sync(ibox, sync_flags) < 0)
+		if (mbox_sync(mbox, sync_flags) < 0)
 			return -1;
 
 		/* refresh index file after mbox has been locked to make
 		   sure we get only up-to-date mbox offsets. */
-		if (mail_index_refresh(ibox->index) < 0) {
-			mail_storage_set_index_error(ibox);
+		if (mail_index_refresh(mbox->ibox.index) < 0) {
+			mail_storage_set_index_error(&mbox->ibox);
 			return -1;
 		}
 
-		i_assert(ibox->mbox_lock_type != F_UNLCK);
-		t->mbox_lock_id = ibox->mbox_lock_id;
+		i_assert(mbox->mbox_lock_type != F_UNLCK);
+		t->mbox_lock_id = mbox->mbox_lock_id;
 	}
 
-	if (mbox_file_open_stream(ibox) < 0)
+	if (mbox_file_open_stream(mbox) < 0)
 		return -1;
 
-	ret = mbox_file_seek(ibox, mail->trans->trans_view,
+	ret = mbox_file_seek(mbox, mail->trans->trans_view,
 			     mail->mail.mail.seq, &deleted);
 	if (ret < 0) {
 		if (deleted) {
@@ -57,12 +57,12 @@
 
 	if (ret == 0) {
 		/* we'll need to re-sync it completely */
-		if (ibox->mbox_lock_type == F_RDLCK) {
-			if (ibox->mbox_lock_id == t->mbox_lock_id)
+		if (mbox->mbox_lock_type == F_RDLCK) {
+			if (mbox->mbox_lock_id == t->mbox_lock_id)
 				t->mbox_lock_id = 0;
-			(void)mbox_unlock(mail->ibox, ibox->mbox_lock_id);
-			ibox->mbox_lock_id = 0;
-			i_assert(ibox->mbox_lock_type == F_UNLCK);
+			(void)mbox_unlock(mbox, mbox->mbox_lock_id);
+			mbox->mbox_lock_id = 0;
+			i_assert(mbox->mbox_lock_type == F_UNLCK);
 		}
 
 		sync_flags |= MBOX_SYNC_UNDIRTY;
@@ -76,6 +76,7 @@
 {
 	struct index_mail *mail = (struct index_mail *)_mail;
 	struct index_mail_data *data = &mail->data;
+	struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox;
 
 	(void)index_mail_get_received_date(_mail);
 	if (data->received_date != (time_t)-1)
@@ -84,7 +85,7 @@
 	if (mbox_mail_seek(mail) <= 0)
 		return (time_t)-1;
 	data->received_date =
-		istream_raw_mbox_get_received_time(mail->ibox->mbox_stream);
+		istream_raw_mbox_get_received_time(mbox->mbox_stream);
 	if (data->received_date == (time_t)-1) {
 		/* it's broken and conflicts with our "not found"
 		   return value. change it. */
@@ -101,12 +102,13 @@
 mbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field)
 {
 	struct index_mail *mail = (struct index_mail *)_mail;
+	struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox;
 
 	if (field == MAIL_FETCH_FROM_ENVELOPE) {
 		if (mbox_mail_seek(mail) <= 0)
 			return NULL;
 
-		return istream_raw_mbox_get_sender(mail->ibox->mbox_stream);
+		return istream_raw_mbox_get_sender(mbox->mbox_stream);
 
 	}
 
@@ -117,6 +119,7 @@
 {
 	struct index_mail *mail = (struct index_mail *)_mail;
 	struct index_mail_data *data = &mail->data;
+	struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox;
 	struct istream *stream;
 	uoff_t hdr_offset, body_offset, body_size;
 
@@ -124,7 +127,7 @@
 		return (uoff_t)-1;
 
 	/* our header size varies, so don't do any caching */
-	stream = mail->ibox->mbox_stream;
+	stream = mbox->mbox_stream;
 	hdr_offset = istream_raw_mbox_get_header_offset(stream);
 	body_offset = istream_raw_mbox_get_body_offset(stream);
 	body_size = istream_raw_mbox_get_body_size(stream, (uoff_t)-1);
@@ -140,6 +143,7 @@
 {
 	struct index_mail *mail = (struct index_mail *)_mail;
 	struct index_mail_data *data = &mail->data;
+	struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox;
 	struct istream *raw_stream;
 	uoff_t offset;
 
@@ -147,7 +151,7 @@
 		if (mbox_mail_seek(mail) <= 0)
 			return NULL;
 
-		raw_stream = mail->ibox->mbox_stream;
+		raw_stream = mbox->mbox_stream;
 		offset = istream_raw_mbox_get_header_offset(raw_stream);
 		raw_stream = i_stream_create_limit(default_pool, raw_stream,
 						   offset, (uoff_t)-1);

Index: mbox-save.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-save.c,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -d -r1.79 -r1.80
--- mbox-save.c	7 Apr 2005 22:04:53 -0000	1.79
+++ mbox-save.c	8 Apr 2005 13:13:48 -0000	1.80
@@ -27,7 +27,7 @@
 struct mbox_save_context {
 	struct mail_save_context ctx;
 
-	struct index_mailbox *ibox;
+	struct mbox_mailbox *mbox;
 	struct mail_index_transaction *trans;
 	uoff_t append_offset, mail_offset;
 
@@ -51,11 +51,11 @@
 static void write_error(struct mbox_save_context *ctx, int error)
 {
 	if (ENOSPACE(error)) {
-		mail_storage_set_error(ctx->ibox->box.storage,
+		mail_storage_set_error(&ctx->mbox->storage->storage,
 				       "Not enough disk space");
 	} else {
 		errno = error;
-		mbox_set_syscall_error(ctx->ibox, "write()");
+		mbox_set_syscall_error(ctx->mbox, "write()");
 	}
 }
 
@@ -65,24 +65,24 @@
 	char ch;
 	int fd;
 
-	if (ctx->ibox->mbox_writeonly) {
+	if (ctx->mbox->mbox_writeonly) {
 		*offset = 0;
 		return 0;
 	}
 
-	fd = ctx->ibox->mbox_fd;
+	fd = ctx->mbox->mbox_fd;
 	if (fstat(fd, &st) < 0)
-                return mbox_set_syscall_error(ctx->ibox, "fstat()");
+                return mbox_set_syscall_error(ctx->mbox, "fstat()");
 
 	*offset = (uoff_t)st.st_size;
 	if (st.st_size == 0)
 		return 0;
 
 	if (lseek(fd, st.st_size-1, SEEK_SET) < 0)
-                return mbox_set_syscall_error(ctx->ibox, "lseek()");
+                return mbox_set_syscall_error(ctx->mbox, "lseek()");
 
 	if (read(fd, &ch, 1) != 1)
-		return mbox_set_syscall_error(ctx->ibox, "read()");
+		return mbox_set_syscall_error(ctx->mbox, "read()");
 
 	if (ch != '\n') {
 		if (write_full(fd, "\n", 1) < 0) {
@@ -127,8 +127,8 @@
 
 	t_push();
 	if (from_envelope == NULL) {
-		from_envelope = t_strconcat(ctx->ibox->storage->user, "@",
-					    my_hostdomain, NULL);
+		from_envelope = t_strconcat(ctx->mbox->storage->user,
+					    "@", my_hostdomain, NULL);
 	}
 
 	/* save in local timezone, no matter what it was given with */
@@ -148,7 +148,7 @@
 	size_t len;
 	int ret = 0;
 
-	if (ctx->ibox->mbox_writeonly) {
+	if (ctx->mbox->mbox_writeonly) {
 		/* we can't seek, don't set Content-Length */
 		return 0;
 	}
@@ -163,14 +163,14 @@
 
 	if (o_stream_seek(ctx->output, ctx->extra_hdr_offset +
 			  ctx->space_end_idx - len) < 0) {
-		mbox_set_syscall_error(ctx->ibox, "o_stream_seek()");
+		mbox_set_syscall_error(ctx->mbox, "o_stream_seek()");
 		ret = -1;
 	} else if (o_stream_send(ctx->output, str, len) < 0) {
 		write_error(ctx, ctx->output->stream_errno);
 		ret = -1;
 	} else {
 		if (o_stream_seek(ctx->output, end_offset) < 0) {
-			mbox_set_syscall_error(ctx->ibox, "o_stream_seek()");
+			mbox_set_syscall_error(ctx->mbox, "o_stream_seek()");
 			ret = -1;
 		}
 	}
@@ -181,13 +181,14 @@
 
 static void mbox_save_init_sync(struct mbox_transaction_context *t)
 {
+	struct mbox_mailbox *mbox = (struct mbox_mailbox *)t->ictx.ibox;
 	struct mbox_save_context *ctx = t->save_ctx;
 	const struct mail_index_header *hdr;
 	struct mail_index_view *view;
 
 	/* open a new view to get the header. this is required if we just
 	   synced the mailbox so we can get updated next_uid. */
-	view = mail_index_view_open(t->ictx.ibox->index);
+	view = mail_index_view_open(mbox->ibox.index);
 	hdr = mail_index_get_header(view);
 
 	ctx->next_uid = hdr->next_uid;
@@ -236,7 +237,7 @@
 	const char *const *keyword_names;
 	unsigned int i, count, keyword_names_count;
 
-	keyword_names_list = mail_index_get_keywords(ctx->ibox->index);
+	keyword_names_list = mail_index_get_keywords(ctx->mbox->ibox.index);
 	keyword_names = array_get(keyword_names_list, &keyword_names_count);
 
 	str_append(ctx->headers, "X-Keywords:");
@@ -258,30 +259,30 @@
 mbox_save_init_file(struct mbox_save_context *ctx,
 		    struct mbox_transaction_context *t, int want_mail)
 {
-	struct index_mailbox *ibox = ctx->ibox;
+	struct mbox_mailbox *mbox = ctx->mbox;
 	int ret;
 
-	if (ctx->ibox->mbox_readonly || ctx->ibox->readonly) {
-		mail_storage_set_error(&ctx->ibox->storage->storage,
+	if (ctx->mbox->mbox_readonly || ctx->mbox->ibox.readonly) {
+		mail_storage_set_error(&ctx->mbox->storage->storage,
 				       "Read-only mbox");
 		return -1;
 	}
 
 	if (ctx->append_offset == (uoff_t)-1) {
 		/* first appended mail in this transaction */
-		if (ibox->mbox_lock_type != F_WRLCK) {
-			if (mbox_lock(ibox, F_WRLCK, &t->mbox_lock_id) <= 0)
+		if (mbox->mbox_lock_type != F_WRLCK) {
+			if (mbox_lock(mbox, F_WRLCK, &t->mbox_lock_id) <= 0)
 				return -1;
 		}
 
-		if (ibox->mbox_fd == -1) {
-			if (mbox_file_open(ibox) < 0)
+		if (mbox->mbox_fd == -1) {
+			if (mbox_file_open(mbox) < 0)
 				return -1;
 		}
 
 		if (!want_mail) {
 			/* assign UIDs only if mbox doesn't require syncing */
-			ret = mbox_sync_has_changed(ibox, TRUE);
+			ret = mbox_sync_has_changed(mbox, TRUE);
 			if (ret < 0)
 				return -1;
 			if (ret == 0)
@@ -291,13 +292,13 @@
 		if (mbox_seek_to_end(ctx, &ctx->append_offset) < 0)
 			return -1;
 
-		ctx->output = o_stream_create_file(ibox->mbox_fd, default_pool,
+		ctx->output = o_stream_create_file(mbox->mbox_fd, default_pool,
 						   0, FALSE);
 	}
 
 	if (!ctx->synced && want_mail) {
 		/* we'll need to assign UID for the mail immediately. */
-		if (mbox_sync(ibox, 0) < 0)
+		if (mbox_sync(mbox, 0) < 0)
 			return -1;
 		mbox_save_init_sync(t);
 	}
@@ -326,7 +327,7 @@
 {
 	struct mbox_transaction_context *t =
 		(struct mbox_transaction_context *)_t;
-	struct index_mailbox *ibox = t->ictx.ibox;
+	struct mbox_mailbox *mbox = (struct mbox_mailbox *)t->ictx.ibox;
 	struct mbox_save_context *ctx = t->save_ctx;
 	enum mail_flags save_flags;
 	uint64_t offset;
@@ -340,7 +341,7 @@
 	if (ctx == NULL) {
 		ctx = t->save_ctx = i_new(struct mbox_save_context, 1);
 		ctx->ctx.transaction = &t->ictx.mailbox_ctx;
-		ctx->ibox = ibox;
+		ctx->mbox = mbox;
 		ctx->trans = t->ictx.trans;
 		ctx->append_offset = (uoff_t)-1;
 		ctx->headers = str_new(default_pool, 512);
@@ -359,7 +360,7 @@
 	str_truncate(ctx->headers, 0);
 	if (ctx->synced) {
 		str_printfa(ctx->headers, "X-UID: %u\n", ctx->next_uid);
-		if (!ibox->keep_recent)
+		if (!mbox->ibox.keep_recent)
 			save_flags &= ~MAIL_RECENT;
 
 		// FIXME: set keywords
@@ -370,14 +371,14 @@
 		offset = ctx->output->offset == 0 ? 0 :
 			ctx->output->offset - 1;
 		mail_index_update_ext(ctx->trans, ctx->seq,
-				      ibox->mbox_ext_idx, &offset, NULL);
+				      mbox->mbox_ext_idx, &offset, NULL);
 		ctx->next_uid++;
 	}
 	mbox_save_append_flag_headers(ctx->headers, save_flags);
 	mbox_save_append_keyword_headers(ctx, keywords);
 	str_append_c(ctx->headers, '\n');
 
-	i_assert(ibox->mbox_lock_type == F_WRLCK);
+	i_assert(mbox->mbox_lock_type == F_WRLCK);
 
 	ctx->mail_offset = ctx->output->offset;
 	ctx->eoh_input_offset = (uoff_t)-1;
@@ -396,11 +397,11 @@
 						      save_header_callback,
 						      ctx);
 		ctx->body_output =
-			(ctx->ibox->storage->storage.flags &
+			(ctx->mbox->storage->storage.flags &
 			 MAIL_STORAGE_FLAG_SAVE_CRLF) != 0 ?
 			o_stream_create_crlf(default_pool, ctx->output) :
 			o_stream_create_lf(default_pool, ctx->output);
-		if (ctx->ibox->mbox_save_md5 && ctx->synced)
+		if (ctx->mbox->mbox_save_md5 && ctx->synced)
 			ctx->mbox_md5_ctx = mbox_md5_init();
 	}
 
@@ -465,7 +466,7 @@
 
 		mbox_md5_finish(ctx->mbox_md5_ctx, hdr_md5_sum);
 		mail_index_update_ext(ctx->trans, ctx->seq,
-				      ctx->ibox->md5hdr_ext_idx,
+				      ctx->mbox->ibox.md5hdr_ext_idx,
 				      hdr_md5_sum, NULL);
 	}
 
@@ -504,19 +505,19 @@
 
 	if (ctx->failed && ctx->mail_offset != (uoff_t)-1) {
 		/* saving this mail failed - truncate back to beginning of it */
-		if (ftruncate(ctx->ibox->mbox_fd, (off_t)ctx->mail_offset) < 0)
-			mbox_set_syscall_error(ctx->ibox, "ftruncate()");
+		if (ftruncate(ctx->mbox->mbox_fd, (off_t)ctx->mail_offset) < 0)
+			mbox_set_syscall_error(ctx->mbox, "ftruncate()");
 		ctx->mail_offset = (uoff_t)-1;
 	}
 
 	if (ctx->failed) {
 		errno = ctx->output->stream_errno;
 		if (ENOSPACE(errno)) {
-			mail_storage_set_error(ctx->ibox->box.storage,
+			mail_storage_set_error(&ctx->mbox->storage->storage,
 					       "Not enough disk space");
 		} else if (errno != 0) {
-			mail_storage_set_critical(ctx->ibox->box.storage,
-				"write(%s) failed: %m", ctx->ibox->path);
+			mail_storage_set_critical(&ctx->mbox->storage->storage,
+				"write(%s) failed: %m", ctx->mbox->path);
 		}
 		return -1;
 	}
@@ -559,10 +560,10 @@
 			&ctx->next_uid, sizeof(ctx->next_uid));
 	}
 
-	if (!ctx->synced && ctx->ibox->mbox_fd != -1 &&
-	    !ctx->ibox->mbox_writeonly) {
-		if (fdatasync(ctx->ibox->mbox_fd) < 0) {
-			mbox_set_syscall_error(ctx->ibox, "fdatasync()");
+	if (!ctx->synced && ctx->mbox->mbox_fd != -1 &&
+	    !ctx->mbox->mbox_writeonly) {
+		if (fdatasync(ctx->mbox->mbox_fd) < 0) {
+			mbox_set_syscall_error(ctx->mbox, "fdatasync()");
 			ret = -1;
 		}
 	}
@@ -573,18 +574,18 @@
 
 void mbox_transaction_save_rollback(struct mbox_save_context *ctx)
 {
-	struct index_mailbox *ibox = ctx->ibox;
+	struct mbox_mailbox *mbox = ctx->mbox;
 
-	if (ctx->append_offset != (uoff_t)-1 && ibox->mbox_fd != -1) {
-		i_assert(ibox->mbox_lock_type == F_WRLCK);
+	if (ctx->append_offset != (uoff_t)-1 && mbox->mbox_fd != -1) {
+		i_assert(mbox->mbox_lock_type == F_WRLCK);
 
 		/* failed, truncate file back to original size.
 		   output stream needs to be flushed before truncating
 		   so unref() won't write anything. */
 		o_stream_flush(ctx->output);
 
-		if (ftruncate(ibox->mbox_fd, (off_t)ctx->append_offset) < 0)
-			mbox_set_syscall_error(ibox, "ftruncate()");
+		if (ftruncate(mbox->mbox_fd, (off_t)ctx->append_offset) < 0)
+			mbox_set_syscall_error(mbox, "ftruncate()");
 	}
 
 	mbox_transaction_save_deinit(ctx);

Index: mbox-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-storage.c,v
retrieving revision 1.116
retrieving revision 1.117
diff -u -d -r1.116 -r1.117
--- mbox-storage.c	8 Apr 2005 12:14:43 -0000	1.116
+++ mbox-storage.c	8 Apr 2005 13:13:48 -0000	1.117
@@ -37,12 +37,12 @@
 extern struct mail_storage mbox_storage;
 extern struct mailbox mbox_mailbox;
 
-int mbox_set_syscall_error(struct index_mailbox *ibox, const char *function)
+int mbox_set_syscall_error(struct mbox_mailbox *mbox, const char *function)
 {
 	i_assert(function != NULL);
 
-	mail_storage_set_critical(ibox->box.storage,
-		"%s failed with mbox file %s: %m", function, ibox->path);
+	mail_storage_set_critical(&mbox->storage->storage,
+		"%s failed with mbox file %s: %m", function, mbox->path);
 	return -1;
 }
 
@@ -480,48 +480,47 @@
 	return FALSE;
 }
 
-static struct index_mailbox *
+static struct mbox_mailbox *
 mbox_alloc(struct index_storage *storage, struct mail_index *index,
 	   const char *name, enum mailbox_open_flags flags)
 {
-	struct index_mailbox *ibox;
+	struct mbox_mailbox *mbox;
 	pool_t pool;
 
 	pool = pool_alloconly_create("mailbox", 256);
-	ibox = p_new(pool, struct index_mailbox, 1);
-	ibox->box = mbox_mailbox;
-	ibox->box.pool = pool;
-	ibox->storage = storage;
+	mbox = p_new(pool, struct mbox_mailbox, 1);
+	mbox->ibox.box = mbox_mailbox;
+	mbox->ibox.box.pool = pool;
+	mbox->ibox.storage = storage;
+	mbox->ibox.mail_vfuncs = &mbox_mail_vfuncs;
+	mbox->ibox.is_recent = mbox_mail_is_recent;
 
-	if (index_storage_mailbox_init(ibox, index, name, flags) < 0) {
+	if (index_storage_mailbox_init(&mbox->ibox, index, name, flags) < 0) {
 		/* the memory is already freed here, no need to deinit */
 		return NULL;
 	}
 
-	ibox->mbox_fd = -1;
-	ibox->mbox_lock_type = F_UNLCK;
-	ibox->mbox_ext_idx =
+	mbox->storage = storage;
+	mbox->mbox_fd = -1;
+	mbox->mbox_lock_type = F_UNLCK;
+	mbox->mbox_ext_idx =
 		mail_index_ext_register(index, "mbox", 0,
 					sizeof(uint64_t), sizeof(uint64_t));
 
-	ibox->is_recent = mbox_mail_is_recent;
-	ibox->mail_vfuncs = &mbox_mail_vfuncs;
-        ibox->mbox_very_dirty_syncs = getenv("MBOX_VERY_DIRTY_SYNCS") != NULL;
-	ibox->mbox_do_dirty_syncs = ibox->mbox_very_dirty_syncs ||
+        mbox->mbox_very_dirty_syncs = getenv("MBOX_VERY_DIRTY_SYNCS") != NULL;
+	mbox->mbox_do_dirty_syncs = mbox->mbox_very_dirty_syncs ||
 		getenv("MBOX_DIRTY_SYNCS") != NULL;
 
-	ibox->md5hdr_ext_idx =
-		mail_index_ext_register(ibox->index, "header-md5", 0, 16, 1);
 	if ((storage->storage.flags & MAIL_STORAGE_FLAG_KEEP_HEADER_MD5) != 0)
-		ibox->mbox_save_md5 = TRUE;
-	return ibox;
+		mbox->mbox_save_md5 = TRUE;
+	return mbox;
 }
 
 static struct mailbox *
 mbox_open(struct index_storage *storage, const char *name,
 	  enum mailbox_open_flags flags)
 {
-	struct index_mailbox *ibox;
+	struct mbox_mailbox *mbox;
 	struct mail_index *index;
 	const char *path, *index_dir;
 
@@ -540,22 +539,22 @@
 	}
 
 	index = index_storage_alloc(index_dir, path, MBOX_INDEX_PREFIX);
-	ibox = mbox_alloc(storage, index, name, flags);
-	if (ibox == NULL)
+	mbox = mbox_alloc(storage, index, name, flags);
+	if (mbox == NULL)
 		return NULL;
 
-	ibox->path = p_strdup(ibox->box.pool, path);
+	mbox->path = p_strdup(mbox->ibox.box.pool, path);
 
 	if (access(path, R_OK|W_OK) < 0) {
 		if (errno < EACCES)
-			mbox_set_syscall_error(ibox, "access()");
+			mbox_set_syscall_error(mbox, "access()");
 		else {
-			ibox->readonly = TRUE;
-			ibox->mbox_readonly = TRUE;
+			mbox->ibox.readonly = TRUE;
+			mbox->mbox_readonly = TRUE;
 		}
 	}
 
-	return &ibox->box;
+	return &mbox->ibox.box;
 }
 
 static struct mailbox *
@@ -563,21 +562,21 @@
 			 struct istream *input, enum mailbox_open_flags flags)
 {
 	struct mail_index *index;
-	struct index_mailbox *ibox;
+	struct mbox_mailbox *mbox;
 
 	flags |= MAILBOX_OPEN_READONLY;
 
 	index = mail_index_alloc(NULL, NULL);
-	ibox = mbox_alloc(storage, index, name, flags);
-	if (ibox == NULL)
+	mbox = mbox_alloc(storage, index, name, flags);
+	if (mbox == NULL)
 		return NULL;
 
 	i_stream_ref(input);
-	ibox->mbox_file_stream = input;
-	ibox->mbox_readonly = TRUE;
+	mbox->mbox_file_stream = input;
+	mbox->mbox_readonly = TRUE;
 
-	ibox->path = "(read-only mbox stream)";
-	return &ibox->box;
+	mbox->path = "(read-only mbox stream)";
+	return &mbox->ibox.box;
 }
 
 static struct mailbox *
@@ -939,28 +938,28 @@
 
 static int mbox_storage_close(struct mailbox *box)
 {
-	struct index_mailbox *ibox = (struct index_mailbox *)box;
+	struct mbox_mailbox *mbox = (struct mbox_mailbox *)box;
 	const struct mail_index_header *hdr;
 	struct mail_index *free_index = NULL;
 	int ret = 0;
 
-	hdr = mail_index_get_header(ibox->view);
+	hdr = mail_index_get_header(mbox->ibox.view);
 	if ((hdr->flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) != 0 &&
-	    !ibox->readonly && !ibox->mbox_readonly) {
+	    !mbox->ibox.readonly && !mbox->mbox_readonly) {
 		/* we've done changes to mbox which haven't been written yet.
 		   do it now. */
-		if (mbox_sync(ibox, MBOX_SYNC_REWRITE) < 0)
+		if (mbox_sync(mbox, MBOX_SYNC_REWRITE) < 0)
 			ret = -1;
 	}
 
-        mbox_file_close(ibox);
-	if (ibox->mbox_file_stream != NULL) {
-		i_stream_unref(ibox->mbox_file_stream);
-		ibox->mbox_file_stream = NULL;
+        mbox_file_close(mbox);
+	if (mbox->mbox_file_stream != NULL) {
+		i_stream_unref(mbox->mbox_file_stream);
+		mbox->mbox_file_stream = NULL;
 
 		/* it's not in storage's index cache, so free it manually */
-		free_index = ibox->index;
-		ibox->index = NULL;
+		free_index = mbox->ibox.index;
+		mbox->ibox.index = NULL;
 	}
 
 	index_storage_mailbox_free(box);
@@ -973,16 +972,16 @@
 mbox_notify_changes(struct mailbox *box, unsigned int min_interval,
 		    mailbox_notify_callback_t *callback, void *context)
 {
-	struct index_mailbox *ibox = (struct index_mailbox *)box;
+	struct mbox_mailbox *mbox = (struct mbox_mailbox *)box;
 
-	ibox->min_notify_interval = min_interval;
-	ibox->notify_callback = callback;
-	ibox->notify_context = context;
+	mbox->ibox.min_notify_interval = min_interval;
+	mbox->ibox.notify_callback = callback;
+	mbox->ibox.notify_context = context;
 
 	if (callback == NULL)
-		index_mailbox_check_remove_all(ibox);
+		index_mailbox_check_remove_all(&mbox->ibox);
 	else
-		index_mailbox_check_add(ibox, ibox->path, FALSE);
+		index_mailbox_check_add(&mbox->ibox, mbox->path, FALSE);
 }
 
 struct mail_storage mbox_storage = {

Index: mbox-storage.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-storage.h,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- mbox-storage.h	8 Apr 2005 12:14:43 -0000	1.36
+++ mbox-storage.h	8 Apr 2005 13:13:48 -0000	1.37
@@ -11,6 +11,33 @@
 
 #include "index-storage.h"
 
+struct mbox_mailbox {
+	struct index_mailbox ibox;
+	struct index_storage *storage;
+
+	const char *path;
+
+	int mbox_fd;
+	struct istream *mbox_stream, *mbox_file_stream;
+	int mbox_lock_type;
+	dev_t mbox_dev;
+	ino_t mbox_ino;
+	unsigned int mbox_excl_locks, mbox_shared_locks;
+	struct dotlock *mbox_dotlock;
+	unsigned int mbox_lock_id;
+	int mbox_readonly, mbox_writeonly;
+	time_t mbox_dirty_stamp;
+	off_t mbox_dirty_size;
+
+	uint32_t mbox_ext_idx;
+
+	unsigned int mbox_sync_dirty:1;
+	unsigned int mbox_do_dirty_syncs:1;
+	unsigned int mbox_very_dirty_syncs:1;
+	unsigned int mbox_save_md5:1;
+	unsigned int mbox_dotlocked:1;
+};
+
 struct mbox_transaction_context {
 	struct index_transaction_context ictx;
 
@@ -23,7 +50,7 @@
 extern const char *mbox_hide_headers[];
 extern unsigned int mbox_hide_headers_count;
 
-int mbox_set_syscall_error(struct index_mailbox *ibox, const char *function);
+int mbox_set_syscall_error(struct mbox_mailbox *mbox, const char *function);
 
 struct mailbox_list_context *
 mbox_mailbox_list_init(struct mail_storage *storage,

Index: mbox-sync-parse.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-parse.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- mbox-sync-parse.c	7 Apr 2005 22:27:26 -0000	1.38
+++ mbox-sync-parse.c	8 Apr 2005 13:13:48 -0000	1.39
@@ -134,14 +134,14 @@
 		t_push();
 		keyword = t_strndup(hdr->full_value + keyword_start,
 				    pos - keyword_start);
-		(void)mail_index_keyword_lookup(ctx->sync_ctx->ibox->index,
+		(void)mail_index_keyword_lookup(ctx->sync_ctx->mbox->ibox.index,
 						keyword, TRUE, &idx);
 		t_pop();
 
 		count++;
 	}
 
-	if (count != array_count(ctx->sync_ctx->ibox->keyword_names)) {
+	if (count != array_count(ctx->sync_ctx->mbox->ibox.keyword_names)) {
 		/* need to update this list */
 		ctx->imapbase_rewrite = TRUE;
 		ctx->need_rewrite = TRUE;
@@ -267,7 +267,7 @@
 		str_truncate(keyword, 0);
 		str_append_n(keyword, hdr->full_value + keyword_start,
 			     pos - keyword_start);
-		if (!mail_index_keyword_lookup(ctx->sync_ctx->ibox->index,
+		if (!mail_index_keyword_lookup(ctx->sync_ctx->mbox->ibox.index,
 					       str_c(keyword), FALSE, &idx)) {
 			/* keyword wasn't found. that means the sent mail
 			   originally contained X-Keywords header. Delete it. */
@@ -501,7 +501,7 @@
 	ctx->body_offset = input->v_offset;
 }
 
-int mbox_sync_parse_match_mail(struct index_mailbox *ibox,
+int mbox_sync_parse_match_mail(struct mbox_mailbox *mbox,
 			       struct mail_index_view *view, uint32_t seq)
 {
         struct mbox_sync_mail_context ctx;
@@ -520,7 +520,7 @@
 	memset(&ctx, 0, sizeof(ctx));
         mbox_md5_ctx = mbox_md5_init();
 
-	hdr_ctx = message_parse_header_init(ibox->mbox_stream, NULL, FALSE);
+	hdr_ctx = message_parse_header_init(mbox->mbox_stream, NULL, FALSE);
 	while ((ret = message_parse_header_next(hdr_ctx, &hdr)) > 0) {
 		if (hdr->eoh)
 			break;
@@ -551,17 +551,18 @@
 	if (ctx.mail.uid != 0) {
 		/* match by X-UID header */
 		if (mail_index_lookup_uid(view, seq, &uid) < 0) {
-			mail_storage_set_index_error(ibox);
+			mail_storage_set_index_error(&mbox->ibox);
 			return -1;
 		}
 		return ctx.mail.uid == uid;
 	}
 
 	/* match by MD5 sum */
-	ibox->mbox_save_md5 = TRUE;
+	mbox->mbox_save_md5 = TRUE;
 
-	if (mail_index_lookup_ext(view, seq, ibox->md5hdr_ext_idx, &data) < 0) {
-		mail_storage_set_index_error(ibox);
+	if (mail_index_lookup_ext(view, seq, mbox->ibox.md5hdr_ext_idx,
+				  &data) < 0) {
+		mail_storage_set_index_error(&mbox->ibox);
 		return -1;
 	}
 	return data == NULL ? 0 :

Index: mbox-sync-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-private.h,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- mbox-sync-private.h	7 Apr 2005 22:27:26 -0000	1.48
+++ mbox-sync-private.h	8 Apr 2005 13:13:48 -0000	1.49
@@ -90,7 +90,7 @@
 };
 
 struct mbox_sync_context {
-	struct index_mailbox *ibox;
+	struct mbox_mailbox *mbox;
         enum mbox_sync_flags flags;
 	struct istream *input, *file_input;
 	int write_fd;
@@ -124,12 +124,12 @@
 	unsigned int delay_writes:1;
 };
 
-int mbox_sync(struct index_mailbox *ibox, enum mbox_sync_flags flags);
-int mbox_sync_has_changed(struct index_mailbox *ibox, int leave_dirty);
+int mbox_sync(struct mbox_mailbox *mbox, enum mbox_sync_flags flags);
+int mbox_sync_has_changed(struct mbox_mailbox *mbox, int leave_dirty);
 
 void mbox_sync_parse_next_mail(struct istream *input,
 			       struct mbox_sync_mail_context *ctx);
-int mbox_sync_parse_match_mail(struct index_mailbox *ibox,
+int mbox_sync_parse_match_mail(struct mbox_mailbox *mbox,
 			       struct mail_index_view *view, uint32_t seq);
 
 void mbox_sync_update_header(struct mbox_sync_mail_context *ctx);

Index: mbox-sync-rewrite.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-rewrite.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- mbox-sync-rewrite.c	7 Apr 2005 22:27:26 -0000	1.45
+++ mbox-sync-rewrite.c	8 Apr 2005 13:13:48 -0000	1.46
@@ -36,14 +36,14 @@
         if (ret == (off_t)size)
 		ret = 0;
 	else if (ret >= 0) {
-		mail_storage_set_critical(sync_ctx->ibox->box.storage,
+		mail_storage_set_critical(&sync_ctx->mbox->storage->storage,
 			"mbox_move(%"PRIuUOFF_T", %"PRIuUOFF_T", %"PRIuUOFF_T
 			") moved only %"PRIuUOFF_T" bytes in mbox file %s",
-			dest, source, size, (uoff_t)ret, sync_ctx->ibox->path);
+			dest, source, size, (uoff_t)ret, sync_ctx->mbox->path);
 		ret = -1;
 	} else if (ret < 0) {
 		errno = output->stream_errno;
-		mbox_set_syscall_error(sync_ctx->ibox,
+		mbox_set_syscall_error(sync_ctx->mbox,
 				       "o_stream_send_istream()");
 	}
 
@@ -60,14 +60,14 @@
 	while (size > sizeof(space)) {
 		if (pwrite_full(sync_ctx->write_fd, space,
 				sizeof(space), offset) < 0) {
-			mbox_set_syscall_error(sync_ctx->ibox, "pwrite_full()");
+			mbox_set_syscall_error(sync_ctx->mbox, "pwrite_full()");
 			return -1;
 		}
 		size -= sizeof(space);
 	}
 
 	if (pwrite_full(sync_ctx->write_fd, space, size, offset) < 0) {
-		mbox_set_syscall_error(sync_ctx->ibox, "pwrite_full()");
+		mbox_set_syscall_error(sync_ctx->mbox, "pwrite_full()");
 		return -1;
 	}
 	return 0;
@@ -225,7 +225,7 @@
         struct mbox_sync_context *sync_ctx = ctx->sync_ctx;
 	size_t old_hdr_size, new_hdr_size;
 
-	i_assert(sync_ctx->ibox->mbox_lock_type == F_WRLCK);
+	i_assert(sync_ctx->mbox->mbox_lock_type == F_WRLCK);
 
 	old_hdr_size = ctx->body_offset - ctx->hdr_offset;
 	new_hdr_size = str_len(ctx->header);
@@ -283,7 +283,7 @@
 			str_len(ctx->header) - ctx->header_first_change,
 			ctx->hdr_offset + ctx->header_first_change +
 			move_diff) < 0) {
-		mbox_set_syscall_error(sync_ctx->ibox, "pwrite_full()");
+		mbox_set_syscall_error(sync_ctx->mbox, "pwrite_full()");
 		return -1;
 	}
 
@@ -383,7 +383,7 @@
 	dest_offset -= str_len(mail_ctx.header);
 	if (pwrite_full(sync_ctx->write_fd, str_data(mail_ctx.header),
 			str_len(mail_ctx.header), dest_offset) < 0) {
-		mbox_set_syscall_error(sync_ctx->ibox, "pwrite_full()");
+		mbox_set_syscall_error(sync_ctx->mbox, "pwrite_full()");
 		return -1;
 	}
 
@@ -410,7 +410,7 @@
 	int ret = 0;
 
 	i_assert(extra_space < OFF_T_MAX);
-	i_assert(sync_ctx->ibox->mbox_lock_type == F_WRLCK);
+	i_assert(sync_ctx->mbox->mbox_lock_type == F_WRLCK);
 
 	mails = array_get_modifyable(&sync_ctx->mails, &count);
 	i_assert(count == last_seq - first_seq + 1);

Index: mbox-sync-update.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-update.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- mbox-sync-update.c	7 Apr 2005 22:27:26 -0000	1.32
+++ mbox-sync-update.c	8 Apr 2005 13:13:48 -0000	1.33
@@ -112,7 +112,7 @@
 	unsigned int i, idx_count, keywords_count;
 	size_t last_break;
 
-	keyword_names = array_get(sync_ctx->ibox->keyword_names,
+	keyword_names = array_get(sync_ctx->mbox->ibox.keyword_names,
 				  &keywords_count);
 	keyword_indexes = array_get(keyword_indexes_arr, &idx_count);
 
@@ -151,7 +151,7 @@
 		}
 	}
 
-	names = array_get(ctx->sync_ctx->ibox->keyword_names, &count);
+	names = array_get(ctx->sync_ctx->mbox->ibox.keyword_names, &count);
 	for (i = 0; i < count; i++) {
 		/* try avoid overly long lines but cutting them
 		   every 70 chars or so */
@@ -376,7 +376,7 @@
 			mbox_sync_update_xkeywords(ctx);
 	}
 
-	if (!ctx->sync_ctx->ibox->keep_recent)
+	if (!ctx->sync_ctx->mbox->ibox.keep_recent)
 		ctx->mail.flags &= ~MAIL_RECENT;
 
 	if ((old_flags & STATUS_FLAGS_MASK) !=
@@ -397,7 +397,7 @@
 	    (ctx->mail.flags & MAIL_RECENT) != 0) {
 		ctx->mail.flags = (ctx->mail.flags & ~STATUS_FLAGS_MASK) |
 			(mail->flags & STATUS_FLAGS_MASK);
-		if (!ctx->sync_ctx->ibox->keep_recent)
+		if (!ctx->sync_ctx->mbox->ibox.keep_recent)
                         ctx->mail.flags &= ~MAIL_RECENT;
 		mbox_sync_update_status(ctx);
 	}

Index: mbox-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync.c,v
retrieving revision 1.145
retrieving revision 1.146
diff -u -d -r1.145 -r1.146
--- mbox-sync.c	7 Apr 2005 22:27:26 -0000	1.145
+++ mbox-sync.c	8 Apr 2005 13:13:48 -0000	1.146
@@ -65,10 +65,10 @@
 int mbox_sync_seek(struct mbox_sync_context *sync_ctx, uoff_t from_offset)
 {
 	if (istream_raw_mbox_seek(sync_ctx->input, from_offset) < 0) {
-		mail_storage_set_critical(sync_ctx->ibox->box.storage,
+		mail_storage_set_critical(&sync_ctx->mbox->storage->storage,
 			"Unexpectedly lost From-line at offset %"PRIuUOFF_T
 			" from mbox file %s", from_offset,
-			sync_ctx->ibox->path);
+			sync_ctx->mbox->path);
 		return -1;
 	}
 	return 0;
@@ -127,7 +127,7 @@
 	i_assert(mail_ctx->mail.body_size < OFF_T_MAX);
 
 	if ((mail_ctx->mail.flags & MAIL_RECENT) != 0 && !mail_ctx->pseudo) {
-		if (!sync_ctx->ibox->keep_recent) {
+		if (!sync_ctx->mbox->ibox.keep_recent) {
 			/* need to add 'O' flag to Status-header */
 			mail_ctx->need_rewrite = TRUE;
 		}
@@ -171,7 +171,7 @@
 		if (uid <= sync_rec->uid2 &&
 		    sync_rec->type != MAIL_INDEX_SYNC_TYPE_APPEND &&
 		    (sync_rec->type != MAIL_INDEX_SYNC_TYPE_EXPUNGE ||
-		     !sync_ctx->ibox->mbox_readonly)) {
+		     !sync_ctx->mbox->mbox_readonly)) {
 			array_append(&sync_ctx->syncs, sync_rec, 1);
 
 			if (sync_rec->type == MAIL_INDEX_SYNC_TYPE_EXPUNGE)
@@ -180,7 +180,7 @@
 
 		ret = mail_index_sync_next(sync_ctx->index_sync_ctx, sync_rec);
 		if (ret < 0) {
-			mail_storage_set_index_error(sync_ctx->ibox);
+			mail_storage_set_index_error(&sync_ctx->mbox->ibox);
 			return -1;
 		}
 
@@ -256,7 +256,7 @@
 		ret = mail_index_lookup(sync_ctx->sync_view,
 					sync_ctx->idx_seq, &rec);
 		if (ret < 0) {
-			mail_storage_set_index_error(sync_ctx->ibox);
+			mail_storage_set_index_error(&sync_ctx->mbox->ibox);
 			return -1;
 		}
 
@@ -271,16 +271,16 @@
 
 	if (ret == 0 && uid < sync_ctx->hdr->next_uid) {
 		/* this UID was already in index and it was expunged */
-		mail_storage_set_critical(sync_ctx->ibox->box.storage,
+		mail_storage_set_critical(&sync_ctx->mbox->storage->storage,
 			"mbox sync: Expunged message reappeared in mailbox %s "
-			"(UID %u < %u)", sync_ctx->ibox->path, uid,
+			"(UID %u < %u)", sync_ctx->mbox->path, uid,
 			sync_ctx->hdr->next_uid);
 		ret = 0; rec = NULL;
 	} else if (rec != NULL && rec->uid != uid) {
 		/* new UID in the middle of the mailbox - shouldn't happen */
-		mail_storage_set_critical(sync_ctx->ibox->box.storage,
+		mail_storage_set_critical(&sync_ctx->mbox->storage->storage,
 			"mbox sync: UID inserted in the middle of mailbox %s "
-			"(%u > %u)", sync_ctx->ibox->path, rec->uid, uid);
+			"(%u > %u)", sync_ctx->mbox->path, rec->uid, uid);
 		ret = 0; rec = NULL;
 	} else {
 		ret = 1;
@@ -305,15 +305,15 @@
 		ret = mail_index_lookup(sync_ctx->sync_view,
 					sync_ctx->idx_seq, &rec);
 		if (ret < 0) {
-			mail_storage_set_index_error(sync_ctx->ibox);
+			mail_storage_set_index_error(&sync_ctx->mbox->ibox);
 			return -1;
 		}
 
 		if (mail_index_lookup_ext(sync_ctx->sync_view,
 					  sync_ctx->idx_seq,
-					  sync_ctx->ibox->md5hdr_ext_idx,
+					  sync_ctx->mbox->ibox.md5hdr_ext_idx,
 					  &data) < 0) {
-			mail_storage_set_index_error(sync_ctx->ibox);
+			mail_storage_set_index_error(&sync_ctx->mbox->ibox);
 			return -1;
 		}
 
@@ -342,9 +342,9 @@
 		/* see if from_offset needs updating */
 		if (mail_index_lookup_ext(sync_ctx->sync_view,
 					  sync_ctx->idx_seq,
-					  sync_ctx->ibox->mbox_ext_idx,
+					  sync_ctx->mbox->mbox_ext_idx,
 					  &data) < 0) {
-			mail_storage_set_index_error(sync_ctx->ibox);
+			mail_storage_set_index_error(&sync_ctx->mbox->ibox);
 			return -1;
 		}
 
@@ -355,7 +355,7 @@
 
 	offset = mail->from_offset;
 	mail_index_update_ext(sync_ctx->t, sync_ctx->idx_seq,
-			      sync_ctx->ibox->mbox_ext_idx, &offset, NULL);
+			      sync_ctx->mbox->mbox_ext_idx, &offset, NULL);
 	return 0;
 }
 
@@ -395,10 +395,10 @@
 					MODIFY_REPLACE, mbox_flags);
 		mbox_sync_update_index_keywords(mail_ctx);
 
-		if (sync_ctx->ibox->mbox_save_md5 != 0) {
+		if (sync_ctx->mbox->mbox_save_md5 != 0) {
 			mail_index_update_ext(sync_ctx->t, sync_ctx->idx_seq,
-					      sync_ctx->ibox->md5hdr_ext_idx,
-					      mail_ctx->hdr_md5_sum, NULL);
+				sync_ctx->mbox->ibox.md5hdr_ext_idx,
+				mail_ctx->hdr_md5_sum, NULL);
 		}
 	} else {
 		/* see if we need to update flags in index file. the flags in
@@ -417,7 +417,7 @@
 		if (mail_index_lookup_keywords(sync_ctx->sync_view,
 					       sync_ctx->idx_seq,
 					       &idx_mail.keywords) < 0) {
-			mail_storage_set_index_error(sync_ctx->ibox);
+			mail_storage_set_index_error(&sync_ctx->mbox->ibox);
 			t_pop();
 			return -1;
 		}
@@ -466,8 +466,10 @@
 
 	if (mail_ctx->recent &&
 	    (rec == NULL || (rec->flags & MAIL_INDEX_MAIL_FLAG_DIRTY) == 0 ||
-	    (rec->flags & MAIL_RECENT) != 0))
-		index_mailbox_set_recent(sync_ctx->ibox, sync_ctx->idx_seq);
+	     (rec->flags & MAIL_RECENT) != 0)) {
+		index_mailbox_set_recent(&sync_ctx->mbox->ibox,
+					 sync_ctx->idx_seq);
+	}
 
 	/* update from_offsets, but not if we're going to rewrite this message.
 	   rewriting would just move it anyway. */
@@ -522,7 +524,7 @@
 	   to wrong location in the mbox file. */
 	if (pread_full(sync_ctx->write_fd, buf, sizeof(buf),
 		       sync_ctx->base_uid_last_offset) <= 0) {
-		mbox_set_syscall_error(sync_ctx->ibox, "pread_full()");
+		mbox_set_syscall_error(sync_ctx->mbox, "pread_full()");
 		return -1;
 	}
 
@@ -535,9 +537,9 @@
 	}
 
 	if (uid_last != sync_ctx->base_uid_last) {
-		mail_storage_set_critical(sync_ctx->ibox->box.storage,
+		mail_storage_set_critical(&sync_ctx->mbox->storage->storage,
 			"X-IMAPbase uid-last unexpectedly lost in mbox file %s",
-			sync_ctx->ibox->path);
+			sync_ctx->mbox->path);
 		return -1;
 	}
 
@@ -545,7 +547,7 @@
 	str = t_strdup_printf("%010u", sync_ctx->next_uid - 1);
 	if (pwrite_full(sync_ctx->write_fd, str, 10,
 			sync_ctx->base_uid_last_offset) < 0) {
-		mbox_set_syscall_error(sync_ctx->ibox, "pwrite_full()");
+		mbox_set_syscall_error(sync_ctx->mbox, "pwrite_full()");
 		return -1;
 	}
 
@@ -560,7 +562,7 @@
 
 	if (pwrite_full(ctx->sync_ctx->write_fd, str_data(str), str_len(str),
 			ctx->mail.from_offset) < 0) {
-		mbox_set_syscall_error(ctx->sync_ctx->ibox, "pwrite_full()");
+		mbox_set_syscall_error(ctx->sync_ctx->mbox, "pwrite_full()");
 		return -1;
 	}
 
@@ -575,7 +577,7 @@
 	uint32_t ext_idx;
 	uint64_t offset;
 
-	ext_idx = sync_ctx->ibox->mbox_ext_idx;
+	ext_idx = sync_ctx->mbox->mbox_ext_idx;
 
 	mails = array_get(&sync_ctx->mails, &count);
 	for (i = 0; i < count; i++) {
@@ -766,14 +768,14 @@
 static int
 mbox_sync_seek_to_seq(struct mbox_sync_context *sync_ctx, uint32_t seq)
 {
-	struct index_mailbox *ibox = sync_ctx->ibox;
+	struct mbox_mailbox *mbox = sync_ctx->mbox;
 	uoff_t old_offset;
 	uint32_t uid;
 	int ret, deleted;
 
 	if (seq == 0) {
-		if (istream_raw_mbox_seek(ibox->mbox_stream, 0) < 0) {
-			mail_storage_set_error(ibox->box.storage,
+		if (istream_raw_mbox_seek(mbox->mbox_stream, 0) < 0) {
+			mail_storage_set_error(&mbox->storage->storage,
 				"Mailbox isn't a valid mbox file");
 			return -1;
 		}
@@ -781,17 +783,18 @@
 	} else {
 		old_offset = istream_raw_mbox_get_start_offset(sync_ctx->input);
 
-		ret = mbox_file_seek(ibox, sync_ctx->sync_view, seq, &deleted);
+		ret = mbox_file_seek(mbox, sync_ctx->sync_view, seq, &deleted);
 		if (ret < 0)
 			return -1;
 
 		if (ret == 0) {
-			if (istream_raw_mbox_seek(ibox->mbox_stream,
+			if (istream_raw_mbox_seek(mbox->mbox_stream,
 						  old_offset) < 0) {
-				mail_storage_set_critical(ibox->box.storage,
+				mail_storage_set_critical(
+					&mbox->storage->storage,
 					"Error seeking back to original "
 					"offset %s in mbox file %s",
-					dec2str(old_offset), ibox->path);
+					dec2str(old_offset), mbox->path);
 				return -1;
 			}
 			return 0;
@@ -801,7 +804,7 @@
 	if (seq <= 1)
 		uid = 0;
 	else if (mail_index_lookup_uid(sync_ctx->sync_view, seq-1, &uid) < 0) {
-		mail_storage_set_index_error(ibox);
+		mail_storage_set_index_error(&mbox->ibox);
 		return -1;
 	}
 
@@ -830,24 +833,25 @@
 
 	if (mail_index_lookup_uid_range(sync_view, uid, (uint32_t)-1,
 					&seq1, &seq2) < 0) {
-		mail_storage_set_index_error(sync_ctx->ibox);
+		mail_storage_set_index_error(&sync_ctx->mbox->ibox);
 		return -1;
 	}
 
 	if (seq1 == 0) {
 		/* doesn't exist anymore, seek to end of file */
-		st = i_stream_stat(sync_ctx->ibox->mbox_file_stream);
+		st = i_stream_stat(sync_ctx->mbox->mbox_file_stream);
 		if (st == NULL) {
-			mbox_set_syscall_error(sync_ctx->ibox,
+			mbox_set_syscall_error(sync_ctx->mbox,
 					       "i_stream_stat()");
 			return -1;
 		}
 
-		if (istream_raw_mbox_seek(sync_ctx->ibox->mbox_stream,
+		if (istream_raw_mbox_seek(sync_ctx->mbox->mbox_stream,
 					  st->st_size) < 0) {
-			mail_storage_set_critical(sync_ctx->ibox->box.storage,
+			mail_storage_set_critical(
+				&sync_ctx->mbox->storage->storage,
 				"Error seeking to end of mbox file %s",
-				sync_ctx->ibox->path);
+				sync_ctx->mbox->path);
 			return -1;
 		}
 		sync_ctx->idx_seq =
@@ -881,7 +885,7 @@
 	} else {
 		/* if there's no sync records left, we can stop. except if
 		   this is a dirty sync, check if there are new messages. */
-		if (!sync_ctx->ibox->mbox_sync_dirty)
+		if (!sync_ctx->mbox->mbox_sync_dirty)
 			return 0;
 
 		messages_count =
@@ -930,13 +934,14 @@
                     sync_ctx->hdr->uid_validity != 0 &&
 		    sync_ctx->base_uid_validity !=
 		    sync_ctx->hdr->uid_validity) {
-			mail_storage_set_critical(sync_ctx->ibox->box.storage,
+			mail_storage_set_critical(
+				&sync_ctx->mbox->storage->storage,
 				"UIDVALIDITY changed (%u -> %u) "
 				"in mbox file %s",
 				sync_ctx->hdr->uid_validity,
 				sync_ctx->base_uid_validity,
-				sync_ctx->ibox->path);
-                        mail_index_mark_corrupted(sync_ctx->ibox->index);
+				sync_ctx->mbox->path);
+                        mail_index_mark_corrupted(sync_ctx->mbox->ibox.index);
 			return -1;
 		}
 
@@ -970,7 +975,7 @@
 			/* If we can't use/store X-UID header, use MD5 sum.
 			   Also check for existing MD5 sums when we're actually
 			   able to write X-UIDs. */
-			sync_ctx->ibox->mbox_save_md5 = TRUE;
+			sync_ctx->mbox->mbox_save_md5 = TRUE;
 
 			if (mbox_sync_find_index_md5(sync_ctx,
 						     mail_ctx->hdr_md5_sum,
@@ -1064,7 +1069,7 @@
 	}
 
 	if (!skipped_mails)
-		sync_ctx->ibox->mbox_sync_dirty = FALSE;
+		sync_ctx->mbox->mbox_sync_dirty = FALSE;
 
 	return 1;
 }
@@ -1098,7 +1103,7 @@
 	if (pwrite_full(sync_ctx->write_fd,
 			str_data(str), str_len(str), 0) < 0) {
 		if (!ENOSPACE(errno)) {
-			mbox_set_syscall_error(sync_ctx->ibox,
+			mbox_set_syscall_error(sync_ctx->mbox,
 					       "pwrite_full()");
 			return -1;
 		}
@@ -1123,7 +1128,7 @@
 
 	st = i_stream_stat(sync_ctx->file_input);
 	if (st == NULL) {
-		mbox_set_syscall_error(sync_ctx->ibox, "i_stream_stat()");
+		mbox_set_syscall_error(sync_ctx->mbox, "i_stream_stat()");
 		return -1;
 	}
 
@@ -1151,7 +1156,7 @@
 
 		if (file_set_size(sync_ctx->write_fd,
 				  file_size + -sync_ctx->space_diff) < 0) {
-			mbox_set_syscall_error(sync_ctx->ibox,
+			mbox_set_syscall_error(sync_ctx->mbox,
 					       "file_set_size()");
 			return -1;
 		}
@@ -1175,7 +1180,7 @@
 		/* copy trailer, then truncate the file */
 		st = i_stream_stat(sync_ctx->file_input);
 		if (st == NULL) {
-			mbox_set_syscall_error(sync_ctx->ibox,
+			mbox_set_syscall_error(sync_ctx->mbox,
 					       "i_stream_stat()");
 			return -1;
 		}
@@ -1197,7 +1202,7 @@
 			return -1;
 		if (ftruncate(sync_ctx->write_fd,
 			      offset + trailer_size) < 0) {
-			mbox_set_syscall_error(sync_ctx->ibox, "ftruncate()");
+			mbox_set_syscall_error(sync_ctx->mbox, "ftruncate()");
 			return -1;
 		}
 
@@ -1218,7 +1223,7 @@
 
 	st = i_stream_stat(sync_ctx->file_input);
 	if (st == NULL) {
-		mbox_set_syscall_error(sync_ctx->ibox, "i_stream_stat()");
+		mbox_set_syscall_error(sync_ctx->mbox, "i_stream_stat()");
 		return -1;
 	}
 
@@ -1239,7 +1244,7 @@
 	}
 
 	if ((uint32_t)st->st_mtime != sync_ctx->hdr->sync_stamp &&
-	    !sync_ctx->ibox->mbox_sync_dirty) {
+	    !sync_ctx->mbox->mbox_sync_dirty) {
 		uint32_t sync_stamp = st->st_mtime;
 
 		mail_index_update_header(sync_ctx->t,
@@ -1248,7 +1253,7 @@
 	}
 
 	if ((uint64_t)st->st_size != sync_ctx->hdr->sync_size &&
-	    !sync_ctx->ibox->mbox_sync_dirty) {
+	    !sync_ctx->mbox->mbox_sync_dirty) {
 		uint64_t sync_size = st->st_size;
 
 		mail_index_update_header(sync_ctx->t,
@@ -1256,8 +1261,8 @@
 			&sync_size, sizeof(sync_size));
 	}
 
-	sync_ctx->ibox->mbox_dirty_stamp = st->st_mtime;
-	sync_ctx->ibox->mbox_dirty_size = st->st_size;
+	sync_ctx->mbox->mbox_dirty_stamp = st->st_mtime;
+	sync_ctx->mbox->mbox_dirty_size = st->st_size;
 
 	return 0;
 }
@@ -1295,7 +1300,7 @@
 
 	st = i_stream_stat(sync_ctx->file_input);
 	if (st == NULL) {
-		mbox_set_syscall_error(sync_ctx->ibox,
+		mbox_set_syscall_error(sync_ctx->mbox,
 				       "i_stream_stat()");
 		return -1;
 	}
@@ -1304,7 +1309,7 @@
 	    (uint64_t)st->st_size == sync_ctx->hdr->sync_size) {
 		/* file is fully synced */
 		partial = TRUE;
-		sync_ctx->ibox->mbox_sync_dirty = FALSE;
+		sync_ctx->mbox->mbox_sync_dirty = FALSE;
 	} else if ((flags & MBOX_SYNC_UNDIRTY) != 0 ||
 		   (uint64_t)st->st_size == sync_ctx->hdr->sync_size) {
 		/* we want to do full syncing. always do this if
@@ -1312,13 +1317,13 @@
 		   likely means that someone had modified some header
 		   and we probably want to know about it */
 		partial = FALSE;
-		sync_ctx->ibox->mbox_sync_dirty = TRUE;
+		sync_ctx->mbox->mbox_sync_dirty = TRUE;
 	} else {
 		/* see if we can delay syncing the whole file.
 		   normally we only notice expunges and appends
 		   in partial syncing. */
 		partial = TRUE;
-		sync_ctx->ibox->mbox_sync_dirty = TRUE;
+		sync_ctx->mbox->mbox_sync_dirty = TRUE;
 	}
 
 	mbox_sync_restart(sync_ctx);
@@ -1328,7 +1333,7 @@
 			return -1;
 
 		/* partial syncing didn't work, do it again */
-		i_assert(sync_ctx->ibox->mbox_sync_dirty);
+		i_assert(sync_ctx->mbox->mbox_sync_dirty);
 		mbox_sync_restart(sync_ctx);
 
 		mail_index_transaction_rollback(sync_ctx->t);
@@ -1357,44 +1362,44 @@
 	return 0;
 }
 
-int mbox_sync_has_changed(struct index_mailbox *ibox, int leave_dirty)
+int mbox_sync_has_changed(struct mbox_mailbox *mbox, int leave_dirty)
 {
 	const struct mail_index_header *hdr;
 	const struct stat *st;
 	struct stat statbuf;
 
-	if (ibox->mbox_file_stream != NULL && ibox->mbox_fd == -1) {
+	if (mbox->mbox_file_stream != NULL && mbox->mbox_fd == -1) {
 		/* read-only stream */
-		st = i_stream_stat(ibox->mbox_file_stream);
+		st = i_stream_stat(mbox->mbox_file_stream);
 		if (st == NULL) {
-			mbox_set_syscall_error(ibox, "i_stream_stat()");
+			mbox_set_syscall_error(mbox, "i_stream_stat()");
 			return -1;
 		}
 	} else {
-		if (stat(ibox->path, &statbuf) < 0) {
-			mbox_set_syscall_error(ibox, "stat()");
+		if (stat(mbox->path, &statbuf) < 0) {
+			mbox_set_syscall_error(mbox, "stat()");
 			return -1;
 		}
 		st = &statbuf;
 	}
 
-	hdr = mail_index_get_header(ibox->view);
+	hdr = mail_index_get_header(mbox->ibox.view);
 
 	if ((uint32_t)st->st_mtime == hdr->sync_stamp &&
 	    (uint64_t)st->st_size == hdr->sync_size) {
 		/* fully synced */
-		ibox->mbox_sync_dirty = FALSE;
+		mbox->mbox_sync_dirty = FALSE;
 		return 0;
 	}
 
-	if (!ibox->mbox_sync_dirty || !leave_dirty)
+	if (!mbox->mbox_sync_dirty || !leave_dirty)
 		return 1;
 
-	return st->st_mtime != ibox->mbox_dirty_stamp ||
-		st->st_size != ibox->mbox_dirty_size;
+	return st->st_mtime != mbox->mbox_dirty_stamp ||
+		st->st_size != mbox->mbox_dirty_size;
 }
 
-int mbox_sync(struct index_mailbox *ibox, enum mbox_sync_flags flags)
+int mbox_sync(struct mbox_mailbox *mbox, enum mbox_sync_flags flags)
 {
 	struct mail_index_sync_ctx *index_sync_ctx;
 	struct mail_index_view *sync_view;
@@ -1404,13 +1409,13 @@
 	unsigned int lock_id = 0;
 	int ret, changed;
 
-	ibox->sync_last_check = ioloop_time;
+	mbox->ibox.sync_last_check = ioloop_time;
 
-	if (!ibox->mbox_do_dirty_syncs)
+	if (!mbox->mbox_do_dirty_syncs)
 		flags |= MBOX_SYNC_UNDIRTY;
 
 	if ((flags & MBOX_SYNC_LOCK_READING) != 0) {
-		if (mbox_lock(ibox, F_RDLCK, &lock_id) <= 0)
+		if (mbox_lock(mbox, F_RDLCK, &lock_id) <= 0)
 			return -1;
 	}
 
@@ -1418,9 +1423,9 @@
 		changed = 1;
 	else {
 		int leave_dirty = (flags & MBOX_SYNC_UNDIRTY) == 0;
-		if ((changed = mbox_sync_has_changed(ibox, leave_dirty)) < 0) {
+		if ((changed = mbox_sync_has_changed(mbox, leave_dirty)) < 0) {
 			if ((flags & MBOX_SYNC_LOCK_READING) != 0)
-				(void)mbox_unlock(ibox, lock_id);
+				(void)mbox_unlock(mbox, lock_id);
 			return -1;
 		}
 	}
@@ -1432,12 +1437,12 @@
 			return 0;
 
 		/* have to sync to make sure offsets have stayed the same */
-		(void)mbox_unlock(ibox, lock_id);
+		(void)mbox_unlock(mbox, lock_id);
 		lock_id = 0;
 	}
 
 	/* reopen input stream to make sure it has nothing buffered */
-        mbox_file_close_stream(ibox);
+        mbox_file_close_stream(mbox);
 
 __again:
 	if (changed) {
@@ -1445,39 +1450,40 @@
 		   lock it for writing immediately. the mbox must be locked
 		   before index syncing is started to avoid deadlocks, so we
 		   don't have much choice either (well, easy ones anyway). */
-		int lock_type = ibox->mbox_readonly ? F_RDLCK : F_WRLCK;
-		if (mbox_lock(ibox, lock_type, &lock_id) <= 0)
+		int lock_type = mbox->mbox_readonly ? F_RDLCK : F_WRLCK;
+		if (mbox_lock(mbox, lock_type, &lock_id) <= 0)
 			return -1;
 	}
 
 	if ((flags & MBOX_SYNC_LAST_COMMIT) != 0) {
-		seq = ibox->commit_log_file_seq;
-		offset = ibox->commit_log_file_offset;
+		seq = mbox->ibox.commit_log_file_seq;
+		offset = mbox->ibox.commit_log_file_offset;
 	} else {
 		seq = (uint32_t)-1;
 		offset = (uoff_t)-1;
 	}
 
-	ret = mail_index_sync_begin(ibox->index, &index_sync_ctx, &sync_view,
-				    seq, offset, !ibox->keep_recent,
+	ret = mail_index_sync_begin(mbox->ibox.index, &index_sync_ctx,
+				    &sync_view, seq, offset,
+				    !mbox->ibox.keep_recent,
 				    (flags & MBOX_SYNC_REWRITE) != 0);
 	if (ret <= 0) {
 		if (ret < 0)
-			mail_storage_set_index_error(ibox);
+			mail_storage_set_index_error(&mbox->ibox);
 		if (lock_id != 0)
-			(void)mbox_unlock(ibox, lock_id);
+			(void)mbox_unlock(mbox, lock_id);
 		return ret;
 	}
 
 	if (!changed && !mail_index_sync_have_more(index_sync_ctx)) {
 		/* nothing to do */
 		if (lock_id != 0)
-			(void)mbox_unlock(ibox, lock_id);
+			(void)mbox_unlock(mbox, lock_id);
 
 		/* index may need to do internal syncing though, so commit
 		   instead of rollbacking. */
 		if (mail_index_sync_commit(index_sync_ctx) < 0) {
-			mail_storage_set_index_error(ibox);
+			mail_storage_set_index_error(&mbox->ibox);
 			return -1;
 		}
 		return 0;
@@ -1491,14 +1497,14 @@
 		goto __again;
 	}
 
-	if (mbox_file_open_stream(ibox) < 0) {
+	if (mbox_file_open_stream(mbox) < 0) {
 		mail_index_sync_rollback(index_sync_ctx);
-		(void)mbox_unlock(ibox, lock_id);
+		(void)mbox_unlock(mbox, lock_id);
 		return -1;
 	}
 
 	memset(&sync_ctx, 0, sizeof(sync_ctx));
-	sync_ctx.ibox = ibox;
+	sync_ctx.mbox = mbox;
 
 	sync_ctx.hdr = mail_index_get_header(sync_view);
 	sync_ctx.from_line = str_new(default_pool, 256);
@@ -1510,20 +1516,20 @@
 	sync_ctx.mail_keyword_pool = pool_alloconly_create("keywords", 4096);
 
 	/* make sure we've read the latest keywords in index */
-	(void)mail_index_get_keywords(ibox->index);
+	(void)mail_index_get_keywords(mbox->ibox.index);
 
 	ARRAY_CREATE(&sync_ctx.mails, default_pool,
 		     struct mbox_sync_mail, 64);
 	ARRAY_CREATE(&sync_ctx.syncs, default_pool,
 		     struct mail_index_sync_rec, 32);
 
-	sync_ctx.file_input = sync_ctx.ibox->mbox_file_stream;
-	sync_ctx.input = sync_ctx.ibox->mbox_stream;
-	sync_ctx.write_fd = sync_ctx.ibox->mbox_readonly ? -1 :
-		sync_ctx.ibox->mbox_fd;
+	sync_ctx.file_input = sync_ctx.mbox->mbox_file_stream;
+	sync_ctx.input = sync_ctx.mbox->mbox_stream;
+	sync_ctx.write_fd = sync_ctx.mbox->mbox_readonly ? -1 :
+		sync_ctx.mbox->mbox_fd;
 	sync_ctx.flags = flags;
-	sync_ctx.delay_writes = sync_ctx.ibox->mbox_readonly ||
-		sync_ctx.ibox->readonly ||
+	sync_ctx.delay_writes = sync_ctx.mbox->mbox_readonly ||
+		sync_ctx.mbox->ibox.readonly ||
 		((flags & MBOX_SYNC_REWRITE) == 0 &&
 		 getenv("MBOX_LAZY_WRITES") != NULL);
 
@@ -1532,18 +1538,18 @@
 	if (ret < 0)
 		mail_index_transaction_rollback(sync_ctx.t);
 	else if (mail_index_transaction_commit(sync_ctx.t, &seq, &offset) < 0) {
-		mail_storage_set_index_error(ibox);
+		mail_storage_set_index_error(&mbox->ibox);
 		ret = -1;
 	} else {
-		ibox->commit_log_file_seq = 0;
-		ibox->commit_log_file_offset = 0;
+		mbox->ibox.commit_log_file_seq = 0;
+		mbox->ibox.commit_log_file_offset = 0;
 	}
 	sync_ctx.t = NULL;
 
 	if (ret < 0)
 		mail_index_sync_rollback(index_sync_ctx);
 	else if (mail_index_sync_commit(index_sync_ctx) < 0) {
-		mail_storage_set_index_error(ibox);
+		mail_storage_set_index_error(&mbox->ibox);
 		ret = -1;
 	}
 
@@ -1553,22 +1559,22 @@
                 ret = mbox_rewrite_base_uid_last(&sync_ctx);
 	}
 
-	if (ret == 0 && ibox->mbox_lock_type == F_WRLCK &&
-	    !ibox->mbox_writeonly) {
-		if (fsync(ibox->mbox_fd) < 0) {
-			mbox_set_syscall_error(ibox, "fsync()");
+	if (ret == 0 && mbox->mbox_lock_type == F_WRLCK &&
+	    !mbox->mbox_writeonly) {
+		if (fsync(mbox->mbox_fd) < 0) {
+			mbox_set_syscall_error(mbox, "fsync()");
 			ret = -1;
 		}
 	}
 
-	if (lock_id != 0 && ibox->mbox_lock_type != F_RDLCK) {
+	if (lock_id != 0 && mbox->mbox_lock_type != F_RDLCK) {
 		/* drop to read lock */
 		unsigned int read_lock_id = 0;
 
-		if (mbox_lock(ibox, F_RDLCK, &read_lock_id) <= 0)
+		if (mbox_lock(mbox, F_RDLCK, &read_lock_id) <= 0)
 			ret = -1;
 		else {
-			if (mbox_unlock(ibox, lock_id) < 0)
+			if (mbox_unlock(mbox, lock_id) < 0)
 				ret = -1;
 			lock_id = read_lock_id;
 		}
@@ -1579,7 +1585,7 @@
 		   notice changes made by others .. and this has to be done
 		   even if lock_reading is set.. except if
 		   mbox_sync_dirty = TRUE */
-		if (mbox_unlock(ibox, lock_id) < 0)
+		if (mbox_unlock(mbox, lock_id) < 0)
 			ret = -1;
 	}
 
@@ -1594,18 +1600,19 @@
 struct mailbox_sync_context *
 mbox_storage_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
 {
-	struct index_mailbox *ibox = (struct index_mailbox *)box;
+	struct mbox_mailbox *mbox = (struct mbox_mailbox *)box;
 	enum mbox_sync_flags mbox_sync_flags = 0;
 	int ret = 0;
 
 	if ((flags & MAILBOX_SYNC_FLAG_FAST) == 0 ||
-	    ibox->sync_last_check + MAILBOX_FULL_SYNC_INTERVAL <= ioloop_time) {
+	    mbox->ibox.sync_last_check + MAILBOX_FULL_SYNC_INTERVAL <=
+	    ioloop_time) {
 		if ((flags & MAILBOX_SYNC_FLAG_FULL_READ) != 0 &&
-		    !ibox->mbox_very_dirty_syncs)
+		    !mbox->mbox_very_dirty_syncs)
 			mbox_sync_flags |= MBOX_SYNC_UNDIRTY;
 		if ((flags & MAILBOX_SYNC_FLAG_FULL_WRITE) != 0)
 			mbox_sync_flags |= MBOX_SYNC_REWRITE;
-		ret = mbox_sync(ibox, mbox_sync_flags);
+		ret = mbox_sync(mbox, mbox_sync_flags);
 	}
 
 	return index_mailbox_sync_init(box, flags, ret < 0);

Index: mbox-transaction.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-transaction.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- mbox-transaction.c	15 Mar 2005 19:01:53 -0000	1.11
+++ mbox-transaction.c	8 Apr 2005 13:13:48 -0000	1.12
@@ -9,11 +9,11 @@
 mbox_transaction_begin(struct mailbox *box,
 		       enum mailbox_transaction_flags flags)
 {
-	struct index_mailbox *ibox = (struct index_mailbox *)box;
+	struct mbox_mailbox *mbox = (struct mbox_mailbox *)box;
 	struct mbox_transaction_context *t;
 
 	t = i_new(struct mbox_transaction_context, 1);
-	index_transaction_init(&t->ictx, ibox, flags);
+	index_transaction_init(&t->ictx, &mbox->ibox, flags);
 	return &t->ictx.mailbox_ctx;
 }
 
@@ -22,7 +22,7 @@
 {
 	struct mbox_transaction_context *t =
 		(struct mbox_transaction_context *)_t;
-	struct index_mailbox *ibox = t->ictx.ibox;
+	struct mbox_mailbox *mbox = (struct mbox_mailbox *)t->ictx.ibox;
 	unsigned int lock_id = t->mbox_lock_id;
 	int mbox_modified, ret = 0;
 
@@ -38,27 +38,27 @@
 	}
 	t = NULL;
 
-	if (lock_id != 0 && ibox->mbox_lock_type != F_WRLCK) {
+	if (lock_id != 0 && mbox->mbox_lock_type != F_WRLCK) {
 		/* unlock before writing any changes */
-		(void)mbox_unlock(ibox, lock_id);
+		(void)mbox_unlock(mbox, lock_id);
 		lock_id = 0;
 	}
 
 	if (ret == 0) {
 		enum mbox_sync_flags mbox_sync_flags = MBOX_SYNC_LAST_COMMIT;
 		if ((flags & MAILBOX_SYNC_FLAG_FULL_READ) != 0 &&
-		    !ibox->mbox_very_dirty_syncs)
+		    !mbox->mbox_very_dirty_syncs)
 			mbox_sync_flags |= MBOX_SYNC_UNDIRTY;
 		if ((flags & MAILBOX_SYNC_FLAG_FULL_WRITE) != 0)
 			mbox_sync_flags |= MBOX_SYNC_REWRITE;
 		if (mbox_modified)
 			mbox_sync_flags |= MBOX_SYNC_HEADER;
-		if (mbox_sync(ibox, mbox_sync_flags) < 0)
+		if (mbox_sync(mbox, mbox_sync_flags) < 0)
 			ret = -1;
 	}
 
 	if (lock_id != 0) {
-		if (mbox_unlock(ibox, lock_id) < 0)
+		if (mbox_unlock(mbox, lock_id) < 0)
 			ret = -1;
 	}
 	return ret;
@@ -68,12 +68,12 @@
 {
 	struct mbox_transaction_context *t =
 		(struct mbox_transaction_context *)_t;
-	struct index_mailbox *ibox = t->ictx.ibox;
+	struct mbox_mailbox *mbox = (struct mbox_mailbox *)t->ictx.ibox;
 
 	if (t->save_ctx != NULL)
 		mbox_transaction_save_rollback(t->save_ctx);
 
 	if (t->mbox_lock_id != 0)
-		(void)mbox_unlock(ibox, t->mbox_lock_id);
+		(void)mbox_unlock(mbox, t->mbox_lock_id);
 	index_transaction_rollback(_t);
 }



More information about the dovecot-cvs mailing list