changeset 3279:b698ae839a18 HEAD

Moved mbox/maildir-specific variables from struct index_mailbox to mbox_mailbox and maildir_mailbox.
author Timo Sirainen <tss@iki.fi>
date Fri, 08 Apr 2005 16:13:45 +0300
parents df372eecc5d0
children 2c72492dfd91
files src/lib-storage/index/index-storage.c src/lib-storage/index/index-storage.h src/lib-storage/index/maildir/maildir-copy.c src/lib-storage/index/maildir/maildir-mail.c src/lib-storage/index/maildir/maildir-save.c src/lib-storage/index/maildir/maildir-storage.c src/lib-storage/index/maildir/maildir-storage.h src/lib-storage/index/maildir/maildir-sync.c src/lib-storage/index/maildir/maildir-transaction.c src/lib-storage/index/maildir/maildir-uidlist.c src/lib-storage/index/maildir/maildir-uidlist.h src/lib-storage/index/maildir/maildir-util.c src/lib-storage/index/mbox/mbox-file.c src/lib-storage/index/mbox/mbox-file.h src/lib-storage/index/mbox/mbox-lock.c src/lib-storage/index/mbox/mbox-lock.h src/lib-storage/index/mbox/mbox-mail.c src/lib-storage/index/mbox/mbox-save.c src/lib-storage/index/mbox/mbox-storage.c src/lib-storage/index/mbox/mbox-storage.h src/lib-storage/index/mbox/mbox-sync-parse.c src/lib-storage/index/mbox/mbox-sync-private.h src/lib-storage/index/mbox/mbox-sync-rewrite.c src/lib-storage/index/mbox/mbox-sync-update.c src/lib-storage/index/mbox/mbox-sync.c src/lib-storage/index/mbox/mbox-transaction.c
diffstat 26 files changed, 718 insertions(+), 669 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/index-storage.c	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/index-storage.c	Fri Apr 08 16:13:45 2005 +0300
@@ -337,6 +337,9 @@
 		return -1;
 	}
 
+	ibox->md5hdr_ext_idx =
+		mail_index_ext_register(index, "header-md5", 0, 16, 1);
+
 	ibox->cache = mail_index_get_cache(index);
 	index_cache_register_defaults(ibox);
 	ibox->view = mail_index_view_open(index);
--- a/src/lib-storage/index/index-storage.h	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/index-storage.h	Fri Apr 08 16:13:45 2005 +0300
@@ -39,7 +39,6 @@
 struct index_mailbox {
 	struct mailbox box;
 	struct index_storage *storage;
-	const char *path, *control_dir;
 
 	struct mail_index *index;
 	struct mail_index_view *view;
@@ -48,6 +47,8 @@
 
 	int (*is_recent)(struct index_mailbox *ibox, uint32_t uid);
 
+	uint32_t md5hdr_ext_idx;
+
 	struct timeout *notify_to;
 	struct index_notify_file *notify_files;
         struct index_notify_io *notify_ios;
@@ -69,29 +70,6 @@
 	uint32_t synced_recent_count;
 	time_t sync_last_check;
 
-	/* mbox: */
-	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, md5hdr_ext_idx;
-
-	/* maildir sync: */
-	struct maildir_uidlist *uidlist;
-	time_t last_new_mtime, last_cur_mtime, last_new_sync_time;
-	time_t dirty_cur_time;
-
-        mode_t mail_create_mode;
-	unsigned int private_flags_mask;
-
 	unsigned int readonly:1;
 	unsigned int keep_recent:1;
 	unsigned int recent_flags_synced:1;
@@ -99,12 +77,6 @@
 	unsigned int sent_readonly_flags_warning:1;
 	unsigned int notify_pending:1;
 	unsigned int mail_read_mmaped:1;
-	unsigned int syncing_commit:1;
-	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 index_transaction_context {
--- a/src/lib-storage/index/maildir/maildir-copy.c	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/maildir/maildir-copy.c	Fri Apr 08 16:13:45 2005 +0300
@@ -10,7 +10,7 @@
 #include <unistd.h>
 
 struct maildir_copy_context {
-	struct index_mailbox *ibox;
+	struct maildir_mailbox *mbox;
 	int hardlink;
 
 	pool_t pool;
@@ -27,7 +27,7 @@
 	const char *fname;
 };
 
-static int do_hardlink(struct index_mailbox *ibox, const char *path,
+static int do_hardlink(struct maildir_mailbox *mbox, const char *path,
 		       void *context)
 {
 	struct hardlink_ctx *ctx = context;
@@ -37,14 +37,14 @@
 			return 0;
 
 		if (ENOSPACE(errno)) {
-			mail_storage_set_error(ibox->box.storage,
+			mail_storage_set_error(&mbox->storage->storage,
 					       "Not enough disk space");
 			return -1;
 		}
 		if (errno == EACCES || errno == EXDEV)
 			return 1;
 
-		mail_storage_set_critical(ibox->box.storage,
+		mail_storage_set_critical(&mbox->storage->storage,
 					  "link(%s, %s) failed: %m",
 					  path, ctx->dest_path);
 		return -1;
@@ -57,7 +57,8 @@
 static int maildir_copy_hardlink(struct mail *mail,
 				 struct maildir_copy_context *ctx)
 {
-	struct index_mail *imail = (struct index_mail *) mail;
+	struct index_mail *imail = (struct index_mail *)mail;
+	struct maildir_mailbox *mbox = (struct maildir_mailbox *)imail->ibox;
 	struct hardlink_ctx do_ctx;
 	struct rollback *rb;
 	enum mail_flags flags;
@@ -71,9 +72,9 @@
 
 	memset(&do_ctx, 0, sizeof(do_ctx));
 	do_ctx.dest_path =
-		t_strconcat(ctx->ibox->path, "/new/", dest_fname, NULL);
+		t_strconcat(ctx->mbox->path, "/new/", dest_fname, NULL);
 
-	if (maildir_file_do(imail->ibox, imail->mail.mail.uid,
+	if (maildir_file_do(mbox, imail->mail.mail.uid,
 			    do_hardlink, &do_ctx) < 0)
 		return -1;
 
@@ -89,7 +90,7 @@
 }
 
 static struct maildir_copy_context *
-maildir_copy_init(struct index_mailbox *ibox)
+maildir_copy_init(struct maildir_mailbox *mbox)
 {
 	struct maildir_copy_context *ctx;
 	pool_t pool;
@@ -99,7 +100,7 @@
 	ctx = p_new(pool, struct maildir_copy_context, 1);
 	ctx->pool = pool;
 	ctx->hardlink = getenv("MAILDIR_COPY_WITH_HARDLINKS") != NULL;
-	ctx->ibox = ibox;
+	ctx->mbox = mbox;
 	return ctx;
 }
 
@@ -115,7 +116,7 @@
 
 	for (rb = ctx->rollbacks; rb != NULL; rb = rb->next) {
 		t_push();
-		(void)unlink(t_strconcat(ctx->ibox->path,
+		(void)unlink(t_strconcat(ctx->mbox->path,
 					 "/new/", rb->fname, NULL));
 		t_pop();
 	}
@@ -128,14 +129,16 @@
 {
 	struct maildir_transaction_context *t =
 		(struct maildir_transaction_context *)_t;
+	struct maildir_mailbox *mbox = (struct maildir_mailbox *)t->ictx.ibox;
 	struct maildir_copy_context *ctx;
 	int ret;
 
 	if (t->copy_ctx == NULL)
-		t->copy_ctx = maildir_copy_init(t->ictx.ibox);
+		t->copy_ctx = maildir_copy_init(mbox);
 	ctx = t->copy_ctx;
 
-	if (ctx->hardlink && mail->box->storage == ctx->ibox->box.storage) {
+	if (ctx->hardlink &&
+	    mail->box->storage == &ctx->mbox->storage->storage) {
 		// FIXME: handle dest_mail
 		t_push();
 		ret = maildir_copy_hardlink(mail, ctx);
--- a/src/lib-storage/index/maildir/maildir-mail.c	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/maildir/maildir-mail.c	Fri Apr 08 16:13:45 2005 +0300
@@ -10,7 +10,8 @@
 #include <unistd.h>
 #include <sys/stat.h>
 
-static int do_open(struct index_mailbox *ibox, const char *path, void *context)
+static int
+do_open(struct maildir_mailbox *mbox, const char *path, void *context)
 {
 	int *fd = context;
 
@@ -20,12 +21,13 @@
 	if (errno == ENOENT)
 		return 0;
 
-	mail_storage_set_critical(ibox->box.storage,
+	mail_storage_set_critical(&mbox->storage->storage,
 				  "open(%s) failed: %m", path);
 	return -1;
 }
 
-static int do_stat(struct index_mailbox *ibox, const char *path, void *context)
+static int
+do_stat(struct maildir_mailbox *mbox, const char *path, void *context)
 {
 	struct stat *st = context;
 
@@ -34,20 +36,20 @@
 	if (errno == ENOENT)
 		return 0;
 
-	mail_storage_set_critical(ibox->box.storage,
+	mail_storage_set_critical(&mbox->storage->storage,
 				  "stat(%s) failed: %m", path);
 	return -1;
 }
 
 static struct istream *
-maildir_open_mail(struct index_mailbox *ibox, uint32_t uid, int *deleted)
+maildir_open_mail(struct maildir_mailbox *mbox, uint32_t uid, int *deleted)
 {
 	int fd;
 
 	*deleted = FALSE;
 
 	fd = -1;
-	if (maildir_file_do(ibox, uid, do_open, &fd) < 0)
+	if (maildir_file_do(mbox, uid, do_open, &fd) < 0)
 		return NULL;
 
 	if (fd == -1) {
@@ -55,7 +57,7 @@
 		return NULL;
 	}
 
-	if (ibox->mail_read_mmaped) {
+	if (mbox->ibox.mail_read_mmaped) {
 		return i_stream_create_mmap(fd, default_pool,
 					    MAIL_MMAP_BLOCK_SIZE, 0, 0, TRUE);
 	} else {
@@ -66,7 +68,8 @@
 
 static time_t maildir_mail_get_received_date(struct mail *_mail)
 {
-	struct index_mail *mail = (struct index_mail *) _mail;
+	struct index_mail *mail = (struct index_mail *)_mail;
+	struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->ibox;
 	struct index_mail_data *data = &mail->data;
 	struct stat st;
 	int fd;
@@ -85,12 +88,12 @@
 		i_assert(fd != -1);
 
 		if (fstat(fd, &st) < 0) {
-			mail_storage_set_critical(mail->ibox->box.storage,
+			mail_storage_set_critical(&mbox->storage->storage,
 						  "fstat(maildir) failed: %m");
 			return (time_t)-1;
 		}
 	} else {
-		if (maildir_file_do(mail->ibox, mail->mail.mail.uid,
+		if (maildir_file_do(mbox, mail->mail.mail.uid,
 				    do_stat, &st) <= 0)
 			return (time_t)-1;
 	}
@@ -105,6 +108,7 @@
 static uoff_t maildir_mail_get_virtual_size(struct mail *_mail)
 {
 	struct index_mail *mail = (struct index_mail *)_mail;
+	struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->ibox;
 	struct index_mail_data *data = &mail->data;
 	const char *fname, *p;
 	uoff_t virtual_size;
@@ -119,7 +123,7 @@
 			return data->virtual_size;
 	}
 
-	fname = maildir_uidlist_lookup(mail->ibox->uidlist,
+	fname = maildir_uidlist_lookup(mbox->uidlist,
 				       mail->mail.mail.uid, &flags);
 	if (fname == NULL)
 		return (uoff_t)-1;
@@ -149,11 +153,12 @@
 maildir_mail_get_special(struct mail *_mail, enum mail_fetch_field field)
 {
 	struct index_mail *mail = (struct index_mail *)_mail;
+	struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->ibox;
 	enum maildir_uidlist_rec_flag flags;
 	const char *fname, *end;
 
 	if (field == MAIL_FETCH_UIDL_FILE_NAME) {
-	    	fname = maildir_uidlist_lookup(mail->ibox->uidlist,
+	    	fname = maildir_uidlist_lookup(mbox->uidlist,
 					       mail->mail.mail.uid, &flags);
 		end = strchr(fname, ':');
 		return end == NULL ? fname : t_strdup_until(fname, end);
@@ -165,6 +170,7 @@
 static uoff_t maildir_mail_get_physical_size(struct mail *_mail)
 {
 	struct index_mail *mail = (struct index_mail *)_mail;
+	struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->ibox;
 	struct index_mail_data *data = &mail->data;
 	struct stat st;
 	const char *fname, *p;
@@ -175,7 +181,7 @@
 	if (size != (uoff_t)-1)
 		return size;
 
-	fname = maildir_uidlist_lookup(mail->ibox->uidlist,
+	fname = maildir_uidlist_lookup(mbox->uidlist,
 				       mail->mail.mail.uid, &flags);
 	if (fname == NULL)
 		return (uoff_t)-1;
@@ -195,7 +201,7 @@
 	}
 
 	if (size == (uoff_t)-1) {
-		if (maildir_file_do(mail->ibox, mail->mail.mail.uid,
+		if (maildir_file_do(mbox, mail->mail.mail.uid,
 				    do_stat, &st) <= 0)
 			return (uoff_t)-1;
 		size = st.st_size;
@@ -212,12 +218,13 @@
 					       struct message_size *hdr_size,
 					       struct message_size *body_size)
 {
-	struct index_mail *mail = (struct index_mail *) _mail;
+	struct index_mail *mail = (struct index_mail *)_mail;
+	struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->ibox;
 	struct index_mail_data *data = &mail->data;
 	int deleted;
 
 	if (data->stream == NULL) {
-		data->stream = maildir_open_mail(mail->ibox,
+		data->stream = maildir_open_mail(mbox,
 						 mail->mail.mail.uid, &deleted);
 		if (data->stream == NULL) {
 			_mail->expunged = deleted;
--- a/src/lib-storage/index/maildir/maildir-save.c	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/maildir/maildir-save.c	Fri Apr 08 16:13:45 2005 +0300
@@ -24,7 +24,7 @@
 	struct mail_save_context ctx;
 	pool_t pool;
 
-	struct index_mailbox *ibox;
+	struct maildir_mailbox *mbox;
 	struct mail_index_transaction *trans;
 	struct maildir_uidlist_sync_ctx *sync_ctx;
 
@@ -62,16 +62,16 @@
 	else {
 		ret = -1;
 		if (ENOSPACE(errno)) {
-			mail_storage_set_error(ctx->ibox->box.storage,
+			mail_storage_set_error(&ctx->mbox->storage->storage,
 					       "Not enough disk space");
 		} else {
-			mail_storage_set_critical(ctx->ibox->box.storage,
+			mail_storage_set_critical(&ctx->mbox->storage->storage,
 				"link(%s, %s) failed: %m", tmp_path, new_path);
 		}
 	}
 
 	if (unlink(tmp_path) < 0 && errno != ENOENT) {
-		mail_storage_set_critical(ctx->ibox->box.storage,
+		mail_storage_set_critical(&ctx->mbox->storage->storage,
 			"unlink(%s) failed: %m", tmp_path);
 	}
 	t_pop();
@@ -81,7 +81,7 @@
 static struct maildir_save_context *
 maildir_save_transaction_init(struct maildir_transaction_context *t)
 {
-        struct index_mailbox *ibox = t->ictx.ibox;
+        struct maildir_mailbox *mbox = (struct maildir_mailbox *)t->ictx.ibox;
 	struct maildir_save_context *ctx;
 	pool_t pool;
 
@@ -89,12 +89,12 @@
 	ctx = p_new(pool, struct maildir_save_context, 1);
 	ctx->ctx.transaction = &t->ictx.mailbox_ctx;
 	ctx->pool = pool;
-	ctx->ibox = ibox;
+	ctx->mbox = mbox;
 	ctx->trans = t->ictx.trans;
 
-	ctx->tmpdir = p_strconcat(pool, ibox->path, "/tmp", NULL);
-	ctx->newdir = p_strconcat(pool, ibox->path, "/new", NULL);
-	ctx->curdir = p_strconcat(pool, ibox->path, "/cur", NULL);
+	ctx->tmpdir = p_strconcat(pool, mbox->path, "/tmp", NULL);
+	ctx->newdir = p_strconcat(pool, mbox->path, "/new", NULL);
+	ctx->curdir = p_strconcat(pool, mbox->path, "/cur", NULL);
 	return ctx;
 }
 
@@ -108,7 +108,7 @@
 	struct maildir_transaction_context *t =
 		(struct maildir_transaction_context *)_t;
 	struct maildir_save_context *ctx;
-	struct index_mailbox *ibox = t->ictx.ibox;
+	struct maildir_mailbox *mbox = (struct maildir_mailbox *)t->ictx.ibox;
 	struct maildir_filename *mf;
 	struct ostream *output;
 	const char *fname, *dest_fname, *path;
@@ -122,7 +122,7 @@
 	ctx = t->save_ctx;
 
 	/* create a new file in tmp/ directory */
-	ctx->fd = maildir_create_tmp(ibox, ctx->tmpdir, ibox->mail_create_mode,
+	ctx->fd = maildir_create_tmp(mbox, ctx->tmpdir, mbox->mail_create_mode,
 				     &path);
 	if (ctx->fd == -1) {
 		ctx->failed = TRUE;
@@ -138,14 +138,14 @@
 	ctx->input = input;
 
 	output = o_stream_create_file(ctx->fd, system_pool, 0, FALSE);
-	ctx->output = (ctx->ibox->storage->storage.flags &
+	ctx->output = (ctx->mbox->storage->storage.flags &
 		       MAIL_STORAGE_FLAG_SAVE_CRLF) != 0 ?
 		o_stream_create_crlf(default_pool, output) :
 		o_stream_create_lf(default_pool, output);
 	o_stream_unref(output);
 
 	flags &= ~MAIL_RECENT;
-	if (ibox->keep_recent)
+	if (mbox->ibox.keep_recent)
 		flags |= MAIL_RECENT;
 
 	/* now, we want to be able to rollback the whole append session,
@@ -210,7 +210,7 @@
 
 		if (utime(path, &buf) < 0) {
 			ctx->failed = TRUE;
-			mail_storage_set_critical(ctx->ibox->box.storage,
+			mail_storage_set_critical(&ctx->mbox->storage->storage,
 						  "utime(%s) failed: %m", path);
 		}
 	}
@@ -222,12 +222,12 @@
 	/* FIXME: when saving multiple messages, we could get better
 	   performance if we left the fd open and fsync()ed it later */
 	if (fsync(ctx->fd) < 0) {
-		mail_storage_set_critical(ctx->ibox->box.storage,
+		mail_storage_set_critical(&ctx->mbox->storage->storage,
 					  "fsync(%s) failed: %m", path);
 		ctx->failed = TRUE;
 	}
 	if (close(ctx->fd) < 0) {
-		mail_storage_set_critical(ctx->ibox->box.storage,
+		mail_storage_set_critical(&ctx->mbox->storage->storage,
 					  "close(%s) failed: %m", path);
 		ctx->failed = TRUE;
 	}
@@ -236,17 +236,17 @@
 	if (ctx->failed) {
 		/* delete the tmp file */
 		if (unlink(path) < 0 && errno != ENOENT) {
-			mail_storage_set_critical(ctx->ibox->box.storage,
+			mail_storage_set_critical(&ctx->mbox->storage->storage,
 				"unlink(%s) failed: %m", path);
 		}
 
 		errno = output_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);
 		}
 
 		ctx->files = ctx->files->next;
@@ -308,13 +308,13 @@
 
 	i_assert(ctx->output == NULL);
 
-	sync_ctx = maildir_sync_index_begin(ctx->ibox);
+	sync_ctx = maildir_sync_index_begin(ctx->mbox);
 	if (sync_ctx == NULL) {
 		maildir_save_commit_abort(ctx, ctx->files);
 		return -1;
 	}
 
-	ret = maildir_uidlist_lock(ctx->ibox->uidlist);
+	ret = maildir_uidlist_lock(ctx->mbox->uidlist);
 	if (ret <= 0) {
 		/* error or timeout - our transaction is broken */
 		maildir_sync_index_abort(sync_ctx);
@@ -327,14 +327,14 @@
 		return -1;
 	}
 
-	first_uid = maildir_uidlist_get_next_uid(ctx->ibox->uidlist);
+	first_uid = maildir_uidlist_get_next_uid(ctx->mbox->uidlist);
 	mail_index_append_assign_uids(ctx->trans, first_uid, &last_uid);
 
 	flags = MAILDIR_UIDLIST_REC_FLAG_NEW_DIR |
 		MAILDIR_UIDLIST_REC_FLAG_RECENT;
 
 	/* move them into new/ */
-	ctx->sync_ctx = maildir_uidlist_sync_init(ctx->ibox->uidlist, TRUE);
+	ctx->sync_ctx = maildir_uidlist_sync_init(ctx->mbox->uidlist, TRUE);
 	for (mf = ctx->files; mf != NULL; mf = mf->next) {
 		fname = mf->dest != NULL ? mf->dest : mf->basename;
 		if (maildir_file_move(ctx, mf->basename, mf->dest) < 0 ||
--- a/src/lib-storage/index/maildir/maildir-storage.c	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/maildir/maildir-storage.c	Fri Apr 08 16:13:45 2005 +0300
@@ -391,14 +391,16 @@
 
 static int maildir_is_recent(struct index_mailbox *ibox, uint32_t uid)
 {
-	return maildir_uidlist_is_recent(ibox->uidlist, uid);
+	struct maildir_mailbox *mbox = (struct maildir_mailbox *)ibox;
+
+	return maildir_uidlist_is_recent(mbox->uidlist, uid);
 }
 
 static struct mailbox *
 maildir_open(struct index_storage *storage, const char *name,
 	     enum mailbox_open_flags flags)
 {
-	struct index_mailbox *ibox;
+	struct maildir_mailbox *mbox;
 	struct mail_index *index;
 	const char *path, *index_dir, *control_dir;
 	struct stat st;
@@ -418,32 +420,33 @@
 		mail_index_set_permissions(index, st.st_mode & 0666, st.st_gid);
 
 	pool = pool_alloconly_create("mailbox", 256);
-	ibox = p_new(pool, struct index_mailbox, 1);
-	ibox->box = maildir_mailbox;
-	ibox->box.pool = pool;
-	ibox->storage = storage;
+	mbox = p_new(pool, struct maildir_mailbox, 1);
+	mbox->ibox.box = maildir_mailbox;
+	mbox->ibox.box.pool = pool;
+	mbox->ibox.storage = storage;
+	mbox->ibox.mail_vfuncs = &maildir_mail_vfuncs;
+	mbox->ibox.is_recent = maildir_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 was already freed */
 		return NULL;
 	}
 
-	ibox->path = p_strdup(pool, path);
-	ibox->control_dir = p_strdup(pool, control_dir);
+	mbox->storage = storage;
+	mbox->path = p_strdup(pool, path);
+	mbox->control_dir = p_strdup(pool, control_dir);
 
-	ibox->mail_vfuncs = &maildir_mail_vfuncs;
-	ibox->uidlist = maildir_uidlist_init(ibox);
-	ibox->is_recent = maildir_is_recent;
+	mbox->uidlist = maildir_uidlist_init(mbox);
 
 	if (!shared)
-		ibox->mail_create_mode = 0600;
+		mbox->mail_create_mode = 0600;
 	else {
-		ibox->mail_create_mode = st.st_mode & 0666;
-		ibox->private_flags_mask = MAIL_SEEN;
+		mbox->mail_create_mode = st.st_mode & 0666;
+		mbox->private_flags_mask = MAIL_SEEN;
 	}
 
 
-	return &ibox->box;
+	return &mbox->ibox.box;
 }
 
 static struct mailbox *
@@ -811,7 +814,7 @@
 
 static int maildir_storage_close(struct mailbox *box)
 {
-	struct index_mailbox *ibox = (struct index_mailbox *)box;
+	struct maildir_mailbox *mbox = (struct maildir_mailbox *)box;
 	int ret = 0;
 
 	/*FIXME:if (!maildir_try_flush_dirty_flags(ibox->index, TRUE)) {
@@ -819,7 +822,7 @@
 		ret = -1;
 	}*/
 
-	maildir_uidlist_deinit(ibox->uidlist);
+	maildir_uidlist_deinit(mbox->uidlist);
         index_storage_mailbox_free(box);
 	return ret;
 }
@@ -828,21 +831,21 @@
 maildir_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 maildir_mailbox *mbox = (struct maildir_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);
 		return;
 	}
 
-	index_mailbox_check_add(ibox,
-		t_strconcat(ibox->storage->dir, "/new", NULL), TRUE);
-	index_mailbox_check_add(ibox,
-		t_strconcat(ibox->storage->dir, "/cur", NULL), TRUE);
+	index_mailbox_check_add(&mbox->ibox,
+		t_strconcat(mbox->storage->dir, "/new", NULL), TRUE);
+	index_mailbox_check_add(&mbox->ibox,
+		t_strconcat(mbox->storage->dir, "/cur", NULL), TRUE);
 }
 
 struct mail_storage maildir_storage = {
--- a/src/lib-storage/index/maildir/maildir-storage.h	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/maildir/maildir-storage.h	Fri Apr 08 16:13:45 2005 +0300
@@ -14,6 +14,23 @@
 struct maildir_save_context;
 struct maildir_copy_context;
 
+struct maildir_mailbox {
+	struct index_mailbox ibox;
+	struct index_storage *storage;
+
+	const char *path, *control_dir;
+
+	/* maildir sync: */
+	struct maildir_uidlist *uidlist;
+	time_t last_new_mtime, last_cur_mtime, last_new_sync_time;
+	time_t dirty_cur_time;
+
+        mode_t mail_create_mode;
+	unsigned int private_flags_mask;
+
+	unsigned int syncing_commit:1;
+};
+
 struct maildir_transaction_context {
 	struct index_transaction_context ictx;
 	struct maildir_save_context *save_ctx;
@@ -23,13 +40,13 @@
 extern struct mail_vfuncs maildir_mail_vfuncs;
 
 /* Return -1 = error, 0 = file not found, 1 = ok */
-typedef int maildir_file_do_func(struct index_mailbox *ibox,
+typedef int maildir_file_do_func(struct maildir_mailbox *mbox,
 				 const char *path, void *context);
 
-int maildir_file_do(struct index_mailbox *ibox, uint32_t seq,
+int maildir_file_do(struct maildir_mailbox *mbox, uint32_t seq,
 		    maildir_file_do_func *func, void *context);
 const char *maildir_generate_tmp_filename(const struct timeval *tv);
-int maildir_create_tmp(struct index_mailbox *ibox, const char *dir,
+int maildir_create_tmp(struct maildir_mailbox *mbox, const char *dir,
 		       mode_t mode, const char **fname_r);
 
 struct mailbox_list_context *
@@ -42,10 +59,10 @@
 
 struct mailbox_sync_context *
 maildir_storage_sync_init(struct mailbox *box, enum mailbox_sync_flags flags);
-int maildir_storage_sync_force(struct index_mailbox *ibox);
+int maildir_storage_sync_force(struct maildir_mailbox *mbox);
 
 struct maildir_index_sync_context *
-maildir_sync_index_begin(struct index_mailbox *ibox);
+maildir_sync_index_begin(struct maildir_mailbox *mbox);
 void maildir_sync_index_abort(struct maildir_index_sync_context *sync_ctx);
 int maildir_sync_index_finish(struct maildir_index_sync_context *sync_ctx,
 			      int partial);
@@ -78,7 +95,7 @@
 
 const char *maildir_get_path(struct index_storage *storage, const char *name);
 
-int maildir_sync_last_commit(struct index_mailbox *ibox);
+int maildir_sync_last_commit(struct maildir_mailbox *mbox);
 
 int maildir_filename_get_flags(const char *fname, pool_t pool,
 			       enum mail_flags *flags_r,
--- a/src/lib-storage/index/maildir/maildir-sync.c	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/maildir/maildir-sync.c	Fri Apr 08 16:13:45 2005 +0300
@@ -189,7 +189,7 @@
 #define MAILDIR_FILENAME_FLAG_FOUND 128
 
 struct maildir_sync_context {
-        struct index_mailbox *ibox;
+        struct maildir_mailbox *mbox;
 	const char *new_dir, *cur_dir;
 	int partial;
 
@@ -198,7 +198,7 @@
 };
 
 struct maildir_index_sync_context {
-        struct index_mailbox *ibox;
+        struct maildir_mailbox *mbox;
 	struct mail_index_view *view;
 	struct mail_index_sync_ctx *sync_ctx;
 	struct mail_index_transaction *trans;
@@ -208,22 +208,22 @@
 	int dirty_state;
 };
 
-static int maildir_expunge(struct index_mailbox *ibox, const char *path,
+static int maildir_expunge(struct maildir_mailbox *mbox, const char *path,
 			   void *context __attr_unused__)
 {
 	if (unlink(path) == 0) {
-		ibox->dirty_cur_time = ioloop_time;
+		mbox->dirty_cur_time = ioloop_time;
 		return 1;
 	}
 	if (errno == ENOENT)
 		return 0;
 
-	mail_storage_set_critical(ibox->box.storage,
+	mail_storage_set_critical(&mbox->storage->storage,
 				  "unlink(%s) failed: %m", path);
 	return -1;
 }
 
-static int maildir_sync_flags(struct index_mailbox *ibox, const char *path,
+static int maildir_sync_flags(struct maildir_mailbox *mbox, const char *path,
 			      void *context)
 {
         struct maildir_index_sync_context *ctx = context;
@@ -244,7 +244,7 @@
 	if (rename(path, newpath) == 0) {
 		if ((flags8 & MAIL_INDEX_MAIL_FLAG_DIRTY) != 0)
 			ctx->dirty_state = -1;
-		ibox->dirty_cur_time = ioloop_time;
+		mbox->dirty_cur_time = ioloop_time;
 		return 1;
 	}
 	if (errno == ENOENT)
@@ -257,12 +257,12 @@
 		return 1;
 	}
 
-	mail_storage_set_critical(ibox->box.storage,
+	mail_storage_set_critical(&mbox->storage->storage,
 				  "rename(%s, %s) failed: %m", path, newpath);
 	return -1;
 }
 
-static int maildir_sync_record(struct index_mailbox *ibox,
+static int maildir_sync_record(struct maildir_mailbox *mbox,
                                struct maildir_index_sync_context *ctx)
 {
 	struct mail_index_sync_rec *sync_rec = &ctx->sync_rec;
@@ -286,7 +286,7 @@
 		for (seq = seq1; seq <= seq2; seq++) {
 			if (mail_index_lookup_uid(view, seq, &uid) < 0)
 				return -1;
-			if (maildir_file_do(ibox, uid, maildir_expunge,
+			if (maildir_file_do(mbox, uid, maildir_expunge,
 					    NULL) < 0)
 				return -1;
 		}
@@ -303,7 +303,7 @@
 		for (ctx->seq = seq1; ctx->seq <= seq2; ctx->seq++) {
 			if (mail_index_lookup_uid(view, ctx->seq, &uid) < 0)
 				return -1;
-			if (maildir_file_do(ibox, uid,
+			if (maildir_file_do(mbox, uid,
 					    maildir_sync_flags, ctx) < 0)
 				return -1;
 			if (ctx->dirty_state < 0) {
@@ -324,29 +324,30 @@
 	return 0;
 }
 
-int maildir_sync_last_commit(struct index_mailbox *ibox)
+int maildir_sync_last_commit(struct maildir_mailbox *mbox)
 {
 	struct maildir_index_sync_context ctx;
 	uint32_t seq;
 	uoff_t offset;
 	int ret;
 
-	if (ibox->commit_log_file_seq == 0)
+	if (mbox->ibox.commit_log_file_seq == 0)
 		return 0;
 
 	memset(&ctx, 0, sizeof(ctx));
-	ctx.ibox = ibox;
+	ctx.mbox = mbox;
 
-        ibox->syncing_commit = TRUE;
-	ret = mail_index_sync_begin(ibox->index, &ctx.sync_ctx, &ctx.view,
-				    ibox->commit_log_file_seq,
-				    ibox->commit_log_file_offset, FALSE, FALSE);
+        mbox->syncing_commit = TRUE;
+	ret = mail_index_sync_begin(mbox->ibox.index, &ctx.sync_ctx, &ctx.view,
+				    mbox->ibox.commit_log_file_seq,
+				    mbox->ibox.commit_log_file_offset,
+				    FALSE, FALSE);
 	if (ret > 0) {
 		ctx.trans = mail_index_transaction_begin(ctx.view, FALSE, TRUE);
 
 		while ((ret = mail_index_sync_next(ctx.sync_ctx,
 						   &ctx.sync_rec)) > 0) {
-			if (maildir_sync_record(ibox, &ctx) < 0) {
+			if (maildir_sync_record(mbox, &ctx) < 0) {
 				ret = -1;
 				break;
 			}
@@ -356,26 +357,26 @@
 		if (mail_index_sync_commit(ctx.sync_ctx) < 0)
 			ret = -1;
 	}
-        ibox->syncing_commit = FALSE;
+        mbox->syncing_commit = FALSE;
 
 	if (ret == 0) {
-		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;
 	} else {
-		mail_storage_set_index_error(ibox);
+		mail_storage_set_index_error(&mbox->ibox);
 	}
 	return ret;
 }
 
 static struct maildir_sync_context *
-maildir_sync_context_new(struct index_mailbox *ibox)
+maildir_sync_context_new(struct maildir_mailbox *mbox)
 {
         struct maildir_sync_context *ctx;
 
 	ctx = t_new(struct maildir_sync_context, 1);
-	ctx->ibox = ibox;
-	ctx->new_dir = t_strconcat(ibox->path, "/new", NULL);
-	ctx->cur_dir = t_strconcat(ibox->path, "/cur", NULL);
+	ctx->mbox = mbox;
+	ctx->new_dir = t_strconcat(mbox->path, "/new", NULL);
+	ctx->cur_dir = t_strconcat(mbox->path, "/cur", NULL);
 	return ctx;
 }
 
@@ -387,7 +388,7 @@
 		maildir_sync_index_abort(ctx->index_sync_ctx);
 }
 
-static int maildir_fix_duplicate(struct index_mailbox *ibox, const char *dir,
+static int maildir_fix_duplicate(struct maildir_mailbox *mbox, const char *dir,
 				 const char *old_fname)
 {
 	const char *new_fname, *old_path, *new_path;
@@ -397,13 +398,13 @@
 
 	old_path = t_strconcat(dir, "/", old_fname, NULL);
 	new_fname = maildir_generate_tmp_filename(&ioloop_timeval);
-	new_path = t_strconcat(ibox->path, "/new/", new_fname, NULL);
+	new_path = t_strconcat(mbox->path, "/new/", new_fname, NULL);
 
 	if (rename(old_path, new_path) == 0) {
 		i_warning("Fixed duplicate in %s: %s -> %s",
-			  ibox->path, old_fname, new_fname);
+			  mbox->path, old_fname, new_fname);
 	} else if (errno != ENOENT) {
-		mail_storage_set_critical(ibox->box.storage,
+		mail_storage_set_critical(&mbox->storage->storage,
 			"rename(%s, %s) failed: %m", old_path, new_path);
 		ret = -1;
 	}
@@ -414,7 +415,7 @@
 
 static int maildir_scan_dir(struct maildir_sync_context *ctx, int new_dir)
 {
-	struct mail_storage *storage = ctx->ibox->box.storage;
+	struct mail_storage *storage = &ctx->mbox->storage->storage;
 	const char *dir;
 	DIR *dirp;
 	string_t *src, *dest;
@@ -434,8 +435,8 @@
 	src = t_str_new(1024);
 	dest = t_str_new(1024);
 
-	move_new = new_dir && !mailbox_is_readonly(&ctx->ibox->box) &&
-		!ctx->ibox->keep_recent;
+	move_new = new_dir && !mailbox_is_readonly(&ctx->mbox->ibox.box) &&
+		!ctx->mbox->ibox.keep_recent;
 	while ((dp = readdir(dirp)) != NULL) {
 		if (dp->d_name[0] == '.')
 			continue;
@@ -446,9 +447,9 @@
 			/* new file and we couldn't lock uidlist, check this
 			   later in next sync. */
 			if (new_dir)
-				ctx->ibox->last_new_mtime = 0;
+				ctx->mbox->last_new_mtime = 0;
 			else
-				ctx->ibox->dirty_cur_time = ioloop_time;
+				ctx->mbox->dirty_cur_time = ioloop_time;
 			continue;
 		}
 		if (ret < 0)
@@ -464,7 +465,7 @@
 				str_append(dest, ":2,");
 			if (rename(str_c(src), str_c(dest)) == 0) {
 				/* we moved it - it's \Recent for us */
-                                ctx->ibox->dirty_cur_time = ioloop_time;
+                                ctx->mbox->dirty_cur_time = ioloop_time;
 				flags |= MAILDIR_UIDLIST_REC_FLAG_MOVED |
 					MAILDIR_UIDLIST_REC_FLAG_RECENT;
 			} else if (ENOTFOUND(errno)) {
@@ -494,7 +495,7 @@
 				break;
 
 			/* possibly duplicate - try fixing it */
-			if (maildir_fix_duplicate(ctx->ibox,
+			if (maildir_fix_duplicate(ctx->mbox,
 						  dir, dp->d_name) < 0) {
 				ret = -1;
 				break;
@@ -514,21 +515,21 @@
 static int maildir_sync_quick_check(struct maildir_sync_context *ctx,
 				    int *new_changed_r, int *cur_changed_r)
 {
-	struct index_mailbox *ibox = ctx->ibox;
+	struct maildir_mailbox *mbox = ctx->mbox;
 	struct stat st;
 	time_t new_mtime, cur_mtime;
 
 	*new_changed_r = *cur_changed_r = FALSE;
 
 	if (stat(ctx->new_dir, &st) < 0) {
-		mail_storage_set_critical(ibox->box.storage,
+		mail_storage_set_critical(&mbox->storage->storage,
 					  "stat(%s) failed: %m", ctx->new_dir);
 		return -1;
 	}
 	new_mtime = st.st_mtime;
 
 	if (stat(ctx->cur_dir, &st) < 0) {
-		mail_storage_set_critical(ibox->box.storage,
+		mail_storage_set_critical(&mbox->storage->storage,
 					  "stat(%s) failed: %m", ctx->cur_dir);
 		return -1;
 	}
@@ -536,33 +537,34 @@
 
 	/* cur stamp is kept in index, we don't have to sync if
 	   someone else has done it and updated the index. */
-	ibox->last_cur_mtime = mail_index_get_header(ibox->view)->sync_stamp;
-	if (ibox->dirty_cur_time == 0 && cur_mtime != ibox->last_cur_mtime) {
+	mbox->last_cur_mtime =
+		mail_index_get_header(mbox->ibox.view)->sync_stamp;
+	if (mbox->dirty_cur_time == 0 && cur_mtime != mbox->last_cur_mtime) {
 		/* check if the index has been updated.. */
-		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;
 		}
 
-		ibox->last_cur_mtime =
-			mail_index_get_header(ibox->view)->sync_stamp;
+		mbox->last_cur_mtime =
+			mail_index_get_header(mbox->ibox.view)->sync_stamp;
 	}
 
-	if (new_mtime != ibox->last_new_mtime ||
-	    new_mtime >= ibox->last_new_sync_time - MAILDIR_SYNC_SECS) {
+	if (new_mtime != mbox->last_new_mtime ||
+	    new_mtime >= mbox->last_new_sync_time - MAILDIR_SYNC_SECS) {
 		*new_changed_r = TRUE;
-		ibox->last_new_mtime = new_mtime;
-		ibox->last_new_sync_time = ioloop_time;
+		mbox->last_new_mtime = new_mtime;
+		mbox->last_new_sync_time = ioloop_time;
 	}
 
-	if (cur_mtime != ibox->last_cur_mtime ||
-	    (ibox->dirty_cur_time != 0 &&
-	     ioloop_time - ibox->dirty_cur_time > MAILDIR_SYNC_SECS)) {
+	if (cur_mtime != mbox->last_cur_mtime ||
+	    (mbox->dirty_cur_time != 0 &&
+	     ioloop_time - mbox->dirty_cur_time > MAILDIR_SYNC_SECS)) {
 		/* cur/ changed, or delayed cur/ check */
 		*cur_changed_r = TRUE;
-		ibox->last_cur_mtime = cur_mtime;
+		mbox->last_cur_mtime = cur_mtime;
 
-		ibox->dirty_cur_time =
+		mbox->dirty_cur_time =
 			cur_mtime >= ioloop_time - MAILDIR_SYNC_SECS ?
 			cur_mtime : 0;
 	}
@@ -571,17 +573,17 @@
 }
 
 struct maildir_index_sync_context *
-maildir_sync_index_begin(struct index_mailbox *ibox)
+maildir_sync_index_begin(struct maildir_mailbox *mbox)
 {
 	struct maildir_index_sync_context *sync_ctx;
 
 	sync_ctx = i_new(struct maildir_index_sync_context, 1);
-	sync_ctx->ibox = ibox;
+	sync_ctx->mbox = mbox;
 
-	if (mail_index_sync_begin(ibox->index, &sync_ctx->sync_ctx,
+	if (mail_index_sync_begin(mbox->ibox.index, &sync_ctx->sync_ctx,
 				  &sync_ctx->view, (uint32_t)-1, (uoff_t)-1,
 				  FALSE, FALSE) <= 0) {
-		mail_storage_set_index_error(ibox);
+		mail_storage_set_index_error(&mbox->ibox);
 		return NULL;
 	}
 	return sync_ctx;
@@ -596,7 +598,7 @@
 int maildir_sync_index_finish(struct maildir_index_sync_context *sync_ctx,
 			      int partial)
 {
-	struct index_mailbox *ibox = sync_ctx->ibox;
+	struct maildir_mailbox *mbox = sync_ctx->mbox;
 	struct mail_index_view *view = sync_ctx->view;
 	struct maildir_uidlist_iter_ctx *iter;
 	struct mail_index_transaction *trans;
@@ -612,15 +614,15 @@
 	int ret;
 
 	hdr = mail_index_get_header(view);
-	uid_validity = maildir_uidlist_get_uid_validity(ibox->uidlist);
+	uid_validity = maildir_uidlist_get_uid_validity(mbox->uidlist);
 	if (uid_validity != hdr->uid_validity &&
 	    uid_validity != 0 && hdr->uid_validity != 0) {
 		/* uidvalidity changed and mailbox isn't being initialized,
 		   index must be rebuilt */
-		mail_storage_set_critical(ibox->box.storage,
+		mail_storage_set_critical(&mbox->storage->storage,
 			"Maildir %s sync: UIDVALIDITY changed (%u -> %u)",
-			ibox->path, hdr->uid_validity, uid_validity);
-		mail_index_mark_corrupted(ibox->index);
+			mbox->path, hdr->uid_validity, uid_validity);
+		mail_index_mark_corrupted(mbox->ibox.index);
                 maildir_sync_index_abort(sync_ctx);
 		return -1;
 	}
@@ -631,7 +633,7 @@
 	keyword_pool = pool_alloconly_create("maildir keywords", 128);
 
 	seq = 0;
-	iter = maildir_uidlist_iter_init(ibox->uidlist);
+	iter = maildir_uidlist_iter_init(mbox->uidlist);
 	while (maildir_uidlist_iter_next(iter, &uid, &uflags, &filename)) {
 		p_clear(keyword_pool);
 		maildir_filename_get_flags(filename, keyword_pool,
@@ -666,18 +668,19 @@
 				if ((uflags &
 				     MAILDIR_UIDLIST_REC_FLAG_RACING) != 0) {
 					mail_storage_set_critical(
-						ibox->box.storage,
+						&mbox->storage->storage,
 						"Maildir %s sync: "
 						"UID < next_uid "
 						"(%u < %u, file = %s)",
-						ibox->path, uid, hdr->next_uid,
+						mbox->path, uid, hdr->next_uid,
 						filename);
-					mail_index_mark_corrupted(ibox->index);
+					mail_index_mark_corrupted(
+						mbox->ibox.index);
 					ret = -1;
 					break;
 				}
-				ibox->dirty_cur_time = ioloop_time;
-				maildir_uidlist_add_flags(ibox->uidlist,
+				mbox->dirty_cur_time = ioloop_time;
+				maildir_uidlist_add_flags(mbox->uidlist,
 					filename,
 					MAILDIR_UIDLIST_REC_FLAG_RACING);
 
@@ -716,18 +719,19 @@
 				continue;
 			}
 			if ((uflags & MAILDIR_UIDLIST_REC_FLAG_RACING) != 0) {
-				mail_storage_set_critical(ibox->box.storage,
+				mail_storage_set_critical(
+					&mbox->storage->storage,
 					"Maildir %s sync: "
 					"UID inserted in the middle of mailbox "
 					"(%u > %u, file = %s)",
-					ibox->path, rec->uid, uid, filename);
-				mail_index_mark_corrupted(ibox->index);
+					mbox->path, rec->uid, uid, filename);
+				mail_index_mark_corrupted(mbox->ibox.index);
 				ret = -1;
 				break;
 			}
 
-			ibox->dirty_cur_time = ioloop_time;
-			maildir_uidlist_add_flags(ibox->uidlist, filename,
+			mbox->dirty_cur_time = ioloop_time;
+			maildir_uidlist_add_flags(mbox->uidlist, filename,
 				MAILDIR_UIDLIST_REC_FLAG_RACING);
 
 			seq--;
@@ -735,8 +739,8 @@
 		}
 
 		if ((rec->flags & MAIL_RECENT) != 0) {
-			index_mailbox_set_recent(ibox, seq);
-			if (ibox->keep_recent) {
+			index_mailbox_set_recent(&mbox->ibox, seq);
+			if (mbox->ibox.keep_recent) {
 				flags |= MAIL_RECENT;
 			} else {
 				mail_index_update_flags(trans, seq,
@@ -781,19 +785,19 @@
 	}
 
 	/* now, sync the index */
-        ibox->syncing_commit = TRUE;
+        mbox->syncing_commit = TRUE;
 	while ((ret = mail_index_sync_next(sync_ctx->sync_ctx,
 					   &sync_ctx->sync_rec)) > 0) {
-		if (maildir_sync_record(ibox, sync_ctx) < 0) {
+		if (maildir_sync_record(mbox, sync_ctx) < 0) {
 			ret = -1;
 			break;
 		}
 	}
-        ibox->syncing_commit = FALSE;
+        mbox->syncing_commit = FALSE;
 
-	if (ibox->dirty_cur_time == 0 &&
-	    ibox->last_cur_mtime != (time_t)hdr->sync_stamp) {
-		uint32_t sync_stamp = ibox->last_cur_mtime;
+	if (mbox->dirty_cur_time == 0 &&
+	    mbox->last_cur_mtime != (time_t)hdr->sync_stamp) {
+		uint32_t sync_stamp = mbox->last_cur_mtime;
 
 		mail_index_update_header(trans,
 			offsetof(struct mail_index_header, sync_stamp),
@@ -802,16 +806,16 @@
 
 	if (hdr->uid_validity == 0) {
 		/* get the initial uidvalidity */
-		if (maildir_uidlist_update(ibox->uidlist) < 0)
+		if (maildir_uidlist_update(mbox->uidlist) < 0)
 			ret = -1;
-		uid_validity = maildir_uidlist_get_uid_validity(ibox->uidlist);
+		uid_validity = maildir_uidlist_get_uid_validity(mbox->uidlist);
 		if (uid_validity == 0) {
 			uid_validity = ioloop_time;
-			maildir_uidlist_set_uid_validity(ibox->uidlist,
+			maildir_uidlist_set_uid_validity(mbox->uidlist,
 							 uid_validity);
 		}
 	} else if (uid_validity == 0) {
-		maildir_uidlist_set_uid_validity(ibox->uidlist,
+		maildir_uidlist_set_uid_validity(mbox->uidlist,
 						 hdr->uid_validity);
 	}
 
@@ -821,7 +825,7 @@
 			&uid_validity, sizeof(uid_validity));
 	}
 
-	next_uid = maildir_uidlist_get_next_uid(ibox->uidlist);
+	next_uid = maildir_uidlist_get_next_uid(mbox->uidlist);
 	if (next_uid != 0 && hdr->next_uid != next_uid) {
 		mail_index_update_header(trans,
 			offsetof(struct mail_index_header, next_uid),
@@ -838,18 +842,18 @@
 		if (mail_index_transaction_commit(trans, &seq, &offset) < 0)
 			ret = -1;
 		else if (seq != 0) {
-			ibox->commit_log_file_seq = seq;
-			ibox->commit_log_file_offset = offset;
+			mbox->ibox.commit_log_file_seq = seq;
+			mbox->ibox.commit_log_file_offset = offset;
 		}
 		if (mail_index_sync_commit(sync_ctx->sync_ctx) < 0)
 			ret = -1;
 	}
 
 	if (ret == 0) {
-		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;
 	} else {
-		mail_storage_set_index_error(ibox);
+		mail_storage_set_index_error(&mbox->ibox);
 	}
 
 	i_free(sync_ctx);
@@ -915,13 +919,13 @@
 	   problem rarely happens except under high amount of modifications.
 	*/
 
-	if (!ctx->ibox->syncing_commit) {
-		ctx->index_sync_ctx = maildir_sync_index_begin(ctx->ibox);
+	if (!ctx->mbox->syncing_commit) {
+		ctx->index_sync_ctx = maildir_sync_index_begin(ctx->mbox);
 		if (ctx->index_sync_ctx == NULL)
 			return -1;
 	}
 
-	if ((ret = maildir_uidlist_lock(ctx->ibox->uidlist)) <= 0) {
+	if ((ret = maildir_uidlist_lock(ctx->mbox->uidlist)) <= 0) {
 		/* failure / timeout. if forced is TRUE, we could still go
 		   forward and check only for renamed files, but is it worth
 		   the trouble? .. */
@@ -930,7 +934,7 @@
 
 	ctx->partial = !cur_changed;
 	ctx->uidlist_sync_ctx =
-		maildir_uidlist_sync_init(ctx->ibox->uidlist, ctx->partial);
+		maildir_uidlist_sync_init(ctx->mbox->uidlist, ctx->partial);
 
 	if (maildir_scan_dir(ctx, TRUE) < 0)
 		return -1;
@@ -941,7 +945,7 @@
 
 	/* finish uidlist syncing, but keep it still locked */
 	maildir_uidlist_sync_finish(ctx->uidlist_sync_ctx);
-	if (!ctx->ibox->syncing_commit) {
+	if (!ctx->mbox->syncing_commit) {
 		if (maildir_sync_index_finish(ctx->index_sync_ctx,
 					      ctx->partial) < 0) {
 			ctx->index_sync_ctx = NULL;
@@ -956,12 +960,12 @@
 	return ret;
 }
 
-int maildir_storage_sync_force(struct index_mailbox *ibox)
+int maildir_storage_sync_force(struct maildir_mailbox *mbox)
 {
         struct maildir_sync_context *ctx;
 	int ret;
 
-	ctx = maildir_sync_context_new(ibox);
+	ctx = maildir_sync_context_new(mbox);
 	ret = maildir_sync_context(ctx, TRUE);
 	maildir_sync_deinit(ctx);
 	return ret;
@@ -970,15 +974,16 @@
 struct mailbox_sync_context *
 maildir_storage_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
 {
-	struct index_mailbox *ibox = (struct index_mailbox *)box;
+	struct maildir_mailbox *mbox = (struct maildir_mailbox *)box;
 	struct maildir_sync_context *ctx;
 	int ret = 0;
 
 	if ((flags & MAILBOX_SYNC_FLAG_FAST) == 0 ||
-	    ibox->sync_last_check + MAILBOX_FULL_SYNC_INTERVAL <= ioloop_time) {
-		ibox->sync_last_check = ioloop_time;
+	    mbox->ibox.sync_last_check + MAILBOX_FULL_SYNC_INTERVAL <=
+	    ioloop_time) {
+		mbox->ibox.sync_last_check = ioloop_time;
 
-		ctx = maildir_sync_context_new(ibox);
+		ctx = maildir_sync_context_new(mbox);
 		ret = maildir_sync_context(ctx, FALSE);
 		maildir_sync_deinit(ctx);
 	}
--- a/src/lib-storage/index/maildir/maildir-transaction.c	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/maildir/maildir-transaction.c	Fri Apr 08 16:13:45 2005 +0300
@@ -7,11 +7,11 @@
 maildir_transaction_begin(struct mailbox *box,
 			  enum mailbox_transaction_flags flags)
 {
-	struct index_mailbox *ibox = (struct index_mailbox *)box;
+	struct maildir_mailbox *mbox = (struct maildir_mailbox *)box;
 	struct maildir_transaction_context *t;
 
 	t = i_new(struct maildir_transaction_context, 1);
-	index_transaction_init(&t->ictx, ibox, flags);
+	index_transaction_init(&t->ictx, &mbox->ibox, flags);
 	return &t->ictx.mailbox_ctx;
 }
 
@@ -20,7 +20,7 @@
 {
 	struct maildir_transaction_context *t =
 		(struct maildir_transaction_context *)_t;
-	struct index_mailbox *ibox = t->ictx.ibox;
+	struct maildir_mailbox *mbox = (struct maildir_mailbox *)t->ictx.ibox;
 	struct maildir_save_context *save_ctx;
 	int ret = 0;
 
@@ -48,7 +48,7 @@
 		maildir_transaction_save_commit_post(save_ctx);
 	}
 
-	return ret < 0 ? -1 : maildir_sync_last_commit(ibox);
+	return ret < 0 ? -1 : maildir_sync_last_commit(mbox);
 }
 
 void maildir_transaction_rollback(struct mailbox_transaction_context *_t)
--- a/src/lib-storage/index/maildir/maildir-uidlist.c	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/maildir/maildir-uidlist.c	Fri Apr 08 16:13:45 2005 +0300
@@ -29,7 +29,7 @@
 };
 
 struct maildir_uidlist {
-	struct index_mailbox *ibox;
+	struct maildir_mailbox *mbox;
 	char *fname;
 	int lock_fd;
 
@@ -78,9 +78,9 @@
 	if (UIDLIST_IS_LOCKED(uidlist))
 		return 1;
 
-	path = t_strconcat(uidlist->ibox->control_dir,
+	path = t_strconcat(uidlist->mbox->control_dir,
 			   "/" MAILDIR_UIDLIST_NAME, NULL);
-        old_mask = umask(0777 & ~uidlist->ibox->mail_create_mode);
+        old_mask = umask(0777 & ~uidlist->mbox->mail_create_mode);
 	fd = file_dotlock_open(&uidlist->dotlock_settings, path,
 			       nonblock ? DOTLOCK_CREATE_FLAG_NONBLOCK : 0,
 			       &uidlist->dotlock);
@@ -88,7 +88,7 @@
 	if (fd == -1) {
 		if (errno == EAGAIN)
 			return 0;
-		mail_storage_set_critical(uidlist->ibox->box.storage,
+		mail_storage_set_critical(&uidlist->mbox->storage->storage,
 			"file_dotlock_open(%s) failed: %m", path);
 		return -1;
 	}
@@ -120,14 +120,14 @@
 	uidlist->lock_fd = -1;
 }
 
-struct maildir_uidlist *maildir_uidlist_init(struct index_mailbox *ibox)
+struct maildir_uidlist *maildir_uidlist_init(struct maildir_mailbox *mbox)
 {
 	struct maildir_uidlist *uidlist;
 
 	uidlist = i_new(struct maildir_uidlist, 1);
-	uidlist->ibox = ibox;
+	uidlist->mbox = mbox;
 	uidlist->fname =
-		i_strconcat(ibox->control_dir, "/" MAILDIR_UIDLIST_NAME, NULL);
+		i_strconcat(mbox->control_dir, "/" MAILDIR_UIDLIST_NAME, NULL);
 	uidlist->lock_fd = -1;
 	uidlist->record_buf = buffer_create_dynamic(default_pool, 512);
 	uidlist->files = hash_create(default_pool, default_pool, 4096,
@@ -139,7 +139,7 @@
 	uidlist->dotlock_settings.immediate_stale_timeout =
 		UIDLIST_LOCK_STALE_TIMEOUT;
 	uidlist->dotlock_settings.temp_prefix =
-		uidlist->ibox->storage->temp_prefix;
+		uidlist->mbox->storage->temp_prefix;
 
 	return uidlist;
 }
@@ -179,12 +179,12 @@
 
 	if (uid == 0 || *line != ' ') {
 		/* invalid file */
-                mail_storage_set_critical(uidlist->ibox->box.storage,
+                mail_storage_set_critical(&uidlist->mbox->storage->storage,
 			"Invalid data in file %s", uidlist->fname);
 		return 0;
 	}
 	if (uid <= uidlist->prev_read_uid) {
-                mail_storage_set_critical(uidlist->ibox->box.storage,
+                mail_storage_set_critical(&uidlist->mbox->storage->storage,
 			"UIDs not ordered in file %s (%u > %u)",
 			uidlist->fname, uid, uidlist->prev_read_uid);
 		return 0;
@@ -198,7 +198,7 @@
         uidlist->last_seen_uid = uid;
 
 	if (uid >= uidlist->next_uid) {
-                mail_storage_set_critical(uidlist->ibox->box.storage,
+                mail_storage_set_critical(&uidlist->mbox->storage->storage,
 			"UID larger than next_uid in file %s (%u >= %u)",
 			uidlist->fname, uid, uidlist->next_uid);
 		return 0;
@@ -213,7 +213,7 @@
 	}
 
 	if (hash_lookup_full(uidlist->files, line, NULL, NULL)) {
-                mail_storage_set_critical(uidlist->ibox->box.storage,
+                mail_storage_set_critical(&uidlist->mbox->storage->storage,
 			"Duplicate file in uidlist file %s: %s",
 			uidlist->fname, line);
 		return 0;
@@ -230,7 +230,7 @@
 
 int maildir_uidlist_update(struct maildir_uidlist *uidlist)
 {
-	struct mail_storage *storage = uidlist->ibox->box.storage;
+	struct mail_storage *storage = &uidlist->mbox->storage->storage;
 	const char *line;
 	unsigned int uid_validity, next_uid;
 	struct istream *input;
@@ -403,7 +403,7 @@
 		/* we haven't synced yet, trust index */
 		const struct mail_index_header *hdr;
 
-		hdr = mail_index_get_header(uidlist->ibox->view);
+		hdr = mail_index_get_header(uidlist->mbox->ibox.view);
 		return hdr->recent_messages_count;
 	}
 
@@ -443,7 +443,7 @@
 static int maildir_uidlist_rewrite_fd(struct maildir_uidlist *uidlist,
 				      const char *temp_path)
 {
-	struct mail_storage *storage = uidlist->ibox->box.storage;
+	struct mail_storage *storage = &uidlist->mbox->storage->storage;
 	struct maildir_uidlist_iter_ctx *iter;
 	struct utimbuf ut;
 	string_t *str;
@@ -461,7 +461,7 @@
 	str_printfa(str, "%u %u %u\n", uidlist->version,
 		    uidlist->uid_validity, uidlist->next_uid);
 
-	iter = maildir_uidlist_iter_init(uidlist->ibox->uidlist);
+	iter = maildir_uidlist_iter_init(uidlist->mbox->uidlist);
 	while (maildir_uidlist_iter_next(iter, &uid, &flags, &filename)) {
 		/* avoid overflowing str buffer so we don't eat more memory
 		   than we need. */
@@ -513,22 +513,22 @@
 
 static int maildir_uidlist_rewrite(struct maildir_uidlist *uidlist)
 {
-	struct index_mailbox *ibox = uidlist->ibox;
+	struct maildir_mailbox *mbox = uidlist->mbox;
 	const char *temp_path, *db_path;
 	int ret;
 
 	i_assert(UIDLIST_IS_LOCKED(uidlist));
 
-	temp_path = t_strconcat(ibox->control_dir,
+	temp_path = t_strconcat(mbox->control_dir,
 				"/" MAILDIR_UIDLIST_NAME ".lock", NULL);
 	ret = maildir_uidlist_rewrite_fd(uidlist, temp_path);
 
 	if (ret == 0) {
-		db_path = t_strconcat(ibox->control_dir,
+		db_path = t_strconcat(mbox->control_dir,
 				      "/" MAILDIR_UIDLIST_NAME, NULL);
 
 		if (file_dotlock_replace(&uidlist->dotlock, 0) <= 0) {
-			mail_storage_set_critical(ibox->box.storage,
+			mail_storage_set_critical(&mbox->storage->storage,
 				"file_dotlock_replace(%s) failed: %m", db_path);
 			(void)unlink(temp_path);
 			ret = -1;
--- a/src/lib-storage/index/maildir/maildir-uidlist.h	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/maildir/maildir-uidlist.h	Fri Apr 08 16:13:45 2005 +0300
@@ -15,7 +15,7 @@
 int maildir_uidlist_try_lock(struct maildir_uidlist *uidlist);
 void maildir_uidlist_unlock(struct maildir_uidlist *uidlist);
 
-struct maildir_uidlist *maildir_uidlist_init(struct index_mailbox *ibox);
+struct maildir_uidlist *maildir_uidlist_init(struct maildir_mailbox *mbox);
 void maildir_uidlist_deinit(struct maildir_uidlist *uidlist);
 
 /* Returns -1 if error, 0 if file is broken or lost, 1 if ok. */
--- a/src/lib-storage/index/maildir/maildir-util.c	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/maildir/maildir-util.c	Fri Apr 08 16:13:45 2005 +0300
@@ -11,53 +11,53 @@
 #include <fcntl.h>
 #include <sys/stat.h>
 
-static int maildir_file_do_try(struct index_mailbox *ibox, uint32_t uid,
+static int maildir_file_do_try(struct maildir_mailbox *mbox, uint32_t uid,
 			       maildir_file_do_func *func, void *context)
 {
 	const char *fname, *path;
         enum maildir_uidlist_rec_flag flags;
 	int ret;
 
-	fname = maildir_uidlist_lookup(ibox->uidlist, uid, &flags);
+	fname = maildir_uidlist_lookup(mbox->uidlist, uid, &flags);
 	if (fname == NULL)
 		return -2; /* expunged */
 
 	t_push();
 	if ((flags & MAILDIR_UIDLIST_REC_FLAG_NEW_DIR) != 0) {
 		/* probably in new/ dir */
-		path = t_strconcat(ibox->path, "/new/", fname, NULL);
-		ret = func(ibox, path, context);
+		path = t_strconcat(mbox->path, "/new/", fname, NULL);
+		ret = func(mbox, path, context);
 		if (ret != 0) {
 			t_pop();
 			return ret;
 		}
 	}
 
-	path = t_strconcat(ibox->path, "/cur/", fname, NULL);
-	ret = func(ibox, path, context);
+	path = t_strconcat(mbox->path, "/cur/", fname, NULL);
+	ret = func(mbox, path, context);
 	t_pop();
 	return ret;
 }
 
-int maildir_file_do(struct index_mailbox *ibox, uint32_t uid,
+int maildir_file_do(struct maildir_mailbox *mbox, uint32_t uid,
 		    maildir_file_do_func *func, void *context)
 {
 	int i, ret;
 
-	ret = maildir_file_do_try(ibox, uid, func, context);
+	ret = maildir_file_do_try(mbox, uid, func, context);
 	for (i = 0; i < 10 && ret == 0; i++) {
 		/* file is either renamed or deleted. sync the maildir and
 		   see which one. if file appears to be renamed constantly,
 		   don't try to open it more than 10 times. */
-		if (maildir_storage_sync_force(ibox) < 0)
+		if (maildir_storage_sync_force(mbox) < 0)
 			return -1;
 
-		ret = maildir_file_do_try(ibox, uid, func, context);
+		ret = maildir_file_do_try(mbox, uid, func, context);
 	}
 
 	if (i == 10) {
-		mail_storage_set_critical(ibox->box.storage,
-			"maildir_file_do(%s) racing", ibox->path);
+		mail_storage_set_critical(&mbox->storage->storage,
+			"maildir_file_do(%s) racing", mbox->path);
 	}
 
 	return ret == -2 ? 0 : ret;
@@ -209,7 +209,7 @@
 	}
 }
 
-int maildir_create_tmp(struct index_mailbox *ibox, const char *dir,
+int maildir_create_tmp(struct maildir_mailbox *mbox, const char *dir,
 		       mode_t mode, const char **fname_r)
 {
 	const char *path, *tmp_fname;
@@ -244,10 +244,10 @@
 	*fname_r = t_strdup(path);
 	if (fd == -1) {
 		if (ENOSPACE(errno)) {
-			mail_storage_set_error(ibox->box.storage,
+			mail_storage_set_error(&mbox->storage->storage,
 					       "Not enough disk space");
 		} else {
-			mail_storage_set_critical(ibox->box.storage,
+			mail_storage_set_critical(&mbox->storage->storage,
 						  "open(%s) failed: %m", path);
 		}
 	}
--- a/src/lib-storage/index/mbox/mbox-file.c	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/mbox/mbox-file.c	Fri Apr 08 16:13:45 2005 +0300
@@ -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);
 	}
 
--- a/src/lib-storage/index/mbox/mbox-file.h	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/mbox/mbox-file.h	Fri Apr 08 16:13:45 2005 +0300
@@ -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
--- a/src/lib-storage/index/mbox/mbox-lock.c	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/mbox/mbox-lock.c	Fri Apr 08 16:13:45 2005 +0300
@@ -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;
--- a/src/lib-storage/index/mbox/mbox-lock.h	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/mbox/mbox-lock.h	Fri Apr 08 16:13:45 2005 +0300
@@ -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
--- a/src/lib-storage/index/mbox/mbox-mail.c	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/mbox/mbox-mail.c	Fri Apr 08 16:13:45 2005 +0300
@@ -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);
--- a/src/lib-storage/index/mbox/mbox-save.c	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/mbox/mbox-save.c	Fri Apr 08 16:13:45 2005 +0300
@@ -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);
--- a/src/lib-storage/index/mbox/mbox-storage.c	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/mbox/mbox-storage.c	Fri Apr 08 16:13:45 2005 +0300
@@ -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 = {
--- a/src/lib-storage/index/mbox/mbox-storage.h	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/mbox/mbox-storage.h	Fri Apr 08 16:13:45 2005 +0300
@@ -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,
--- a/src/lib-storage/index/mbox/mbox-sync-parse.c	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync-parse.c	Fri Apr 08 16:13:45 2005 +0300
@@ -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 :
--- a/src/lib-storage/index/mbox/mbox-sync-private.h	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync-private.h	Fri Apr 08 16:13:45 2005 +0300
@@ -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);
--- a/src/lib-storage/index/mbox/mbox-sync-rewrite.c	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync-rewrite.c	Fri Apr 08 16:13:45 2005 +0300
@@ -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);
--- a/src/lib-storage/index/mbox/mbox-sync-update.c	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync-update.c	Fri Apr 08 16:13:45 2005 +0300
@@ -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);
 	}
--- a/src/lib-storage/index/mbox/mbox-sync.c	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync.c	Fri Apr 08 16:13:45 2005 +0300
@@ -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);
--- a/src/lib-storage/index/mbox/mbox-transaction.c	Fri Apr 08 15:14:41 2005 +0300
+++ b/src/lib-storage/index/mbox/mbox-transaction.c	Fri Apr 08 16:13:45 2005 +0300
@@ -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);
 }