changeset 3280:2c72492dfd91 HEAD

Created mbox_storage and maildir_storage.
author Timo Sirainen <tss@iki.fi>
date Fri, 08 Apr 2005 17:32:49 +0300
parents b698ae839a18
children bbb22ca660e0
files src/lib-storage/index/index-storage.h src/lib-storage/index/maildir/maildir-copy.c src/lib-storage/index/maildir/maildir-list.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-uidlist.c src/lib-storage/index/maildir/maildir-util.c src/lib-storage/index/mbox/mbox-file.c src/lib-storage/index/mbox/mbox-lock.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-rewrite.c src/lib-storage/index/mbox/mbox-sync.c
diffstat 17 files changed, 160 insertions(+), 128 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/index-storage.h	Fri Apr 08 16:13:45 2005 +0300
+++ b/src/lib-storage/index/index-storage.h	Fri Apr 08 17:32:49 2005 +0300
@@ -26,7 +26,6 @@
 
 	const char *dir; /* root directory */
 	const char *index_dir;
-	const char *control_dir;
 	const char *inbox_path; /* INBOX location */
         const char *temp_prefix; /* prefix for temporary files */
 
--- a/src/lib-storage/index/maildir/maildir-copy.c	Fri Apr 08 16:13:45 2005 +0300
+++ b/src/lib-storage/index/maildir/maildir-copy.c	Fri Apr 08 17:32:49 2005 +0300
@@ -37,14 +37,14 @@
 			return 0;
 
 		if (ENOSPACE(errno)) {
-			mail_storage_set_error(&mbox->storage->storage,
+			mail_storage_set_error(STORAGE(mbox->storage),
 					       "Not enough disk space");
 			return -1;
 		}
 		if (errno == EACCES || errno == EXDEV)
 			return 1;
 
-		mail_storage_set_critical(&mbox->storage->storage,
+		mail_storage_set_critical(STORAGE(mbox->storage),
 					  "link(%s, %s) failed: %m",
 					  path, ctx->dest_path);
 		return -1;
@@ -138,7 +138,7 @@
 	ctx = t->copy_ctx;
 
 	if (ctx->hardlink &&
-	    mail->box->storage == &ctx->mbox->storage->storage) {
+	    mail->box->storage == STORAGE(ctx->mbox->storage)) {
 		// FIXME: handle dest_mail
 		t_push();
 		ret = maildir_copy_hardlink(mail, ctx);
--- a/src/lib-storage/index/maildir/maildir-list.c	Fri Apr 08 16:13:45 2005 +0300
+++ b/src/lib-storage/index/maildir/maildir-list.c	Fri Apr 08 17:32:49 2005 +0300
@@ -198,15 +198,15 @@
 static int maildir_fill_subscribed(struct maildir_list_context *ctx,
 				   struct imap_match_glob *glob)
 {
-	struct index_storage *istorage =
-		(struct index_storage *)ctx->mailbox_ctx.storage;
+	struct maildir_storage *storage =
+		(struct maildir_storage *)ctx->mailbox_ctx.storage;
 	struct subsfile_list_context *subsfile_ctx;
 	const char *path, *name, *p;
 	struct mailbox_node *node;
 	int created;
 
-	path = t_strconcat(istorage->control_dir != NULL ?
-			   istorage->control_dir : istorage->dir,
+	path = t_strconcat(storage->control_dir != NULL ?
+			   storage->control_dir : INDEX_STORAGE(storage)->dir,
 			   "/" SUBSCRIPTION_FILE_NAME, NULL);
 	subsfile_ctx = subsfile_list_init(ctx->mailbox_ctx.storage, path);
 	if (subsfile_ctx == NULL)
--- a/src/lib-storage/index/maildir/maildir-mail.c	Fri Apr 08 16:13:45 2005 +0300
+++ b/src/lib-storage/index/maildir/maildir-mail.c	Fri Apr 08 17:32:49 2005 +0300
@@ -21,7 +21,7 @@
 	if (errno == ENOENT)
 		return 0;
 
-	mail_storage_set_critical(&mbox->storage->storage,
+	mail_storage_set_critical(STORAGE(mbox->storage),
 				  "open(%s) failed: %m", path);
 	return -1;
 }
@@ -36,7 +36,7 @@
 	if (errno == ENOENT)
 		return 0;
 
-	mail_storage_set_critical(&mbox->storage->storage,
+	mail_storage_set_critical(STORAGE(mbox->storage),
 				  "stat(%s) failed: %m", path);
 	return -1;
 }
@@ -88,7 +88,7 @@
 		i_assert(fd != -1);
 
 		if (fstat(fd, &st) < 0) {
-			mail_storage_set_critical(&mbox->storage->storage,
+			mail_storage_set_critical(STORAGE(mbox->storage),
 						  "fstat(maildir) failed: %m");
 			return (time_t)-1;
 		}
--- a/src/lib-storage/index/maildir/maildir-save.c	Fri Apr 08 16:13:45 2005 +0300
+++ b/src/lib-storage/index/maildir/maildir-save.c	Fri Apr 08 17:32:49 2005 +0300
@@ -62,16 +62,16 @@
 	else {
 		ret = -1;
 		if (ENOSPACE(errno)) {
-			mail_storage_set_error(&ctx->mbox->storage->storage,
+			mail_storage_set_error(STORAGE(ctx->mbox->storage),
 					       "Not enough disk space");
 		} else {
-			mail_storage_set_critical(&ctx->mbox->storage->storage,
+			mail_storage_set_critical(STORAGE(ctx->mbox->storage),
 				"link(%s, %s) failed: %m", tmp_path, new_path);
 		}
 	}
 
 	if (unlink(tmp_path) < 0 && errno != ENOENT) {
-		mail_storage_set_critical(&ctx->mbox->storage->storage,
+		mail_storage_set_critical(STORAGE(ctx->mbox->storage),
 			"unlink(%s) failed: %m", tmp_path);
 	}
 	t_pop();
@@ -138,7 +138,7 @@
 	ctx->input = input;
 
 	output = o_stream_create_file(ctx->fd, system_pool, 0, FALSE);
-	ctx->output = (ctx->mbox->storage->storage.flags &
+	ctx->output = (STORAGE(ctx->mbox->storage)->flags &
 		       MAIL_STORAGE_FLAG_SAVE_CRLF) != 0 ?
 		o_stream_create_crlf(default_pool, output) :
 		o_stream_create_lf(default_pool, output);
@@ -210,7 +210,7 @@
 
 		if (utime(path, &buf) < 0) {
 			ctx->failed = TRUE;
-			mail_storage_set_critical(&ctx->mbox->storage->storage,
+			mail_storage_set_critical(STORAGE(ctx->mbox->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->mbox->storage->storage,
+		mail_storage_set_critical(STORAGE(ctx->mbox->storage),
 					  "fsync(%s) failed: %m", path);
 		ctx->failed = TRUE;
 	}
 	if (close(ctx->fd) < 0) {
-		mail_storage_set_critical(&ctx->mbox->storage->storage,
+		mail_storage_set_critical(STORAGE(ctx->mbox->storage),
 					  "close(%s) failed: %m", path);
 		ctx->failed = TRUE;
 	}
@@ -236,16 +236,16 @@
 	if (ctx->failed) {
 		/* delete the tmp file */
 		if (unlink(path) < 0 && errno != ENOENT) {
-			mail_storage_set_critical(&ctx->mbox->storage->storage,
+			mail_storage_set_critical(STORAGE(ctx->mbox->storage),
 				"unlink(%s) failed: %m", path);
 		}
 
 		errno = output_errno;
 		if (ENOSPACE(errno)) {
-			mail_storage_set_error(&ctx->mbox->storage->storage,
+			mail_storage_set_error(STORAGE(ctx->mbox->storage),
 					       "Not enough disk space");
 		} else if (errno != 0) {
-			mail_storage_set_critical(&ctx->mbox->storage->storage,
+			mail_storage_set_critical(STORAGE(ctx->mbox->storage),
 				"write(%s) failed: %m", ctx->mbox->path);
 		}
 
--- a/src/lib-storage/index/maildir/maildir-storage.c	Fri Apr 08 16:13:45 2005 +0300
+++ b/src/lib-storage/index/maildir/maildir-storage.c	Fri Apr 08 17:32:49 2005 +0300
@@ -28,7 +28,7 @@
 
 static const char *maildirs[] = { "cur", "new", "tmp", NULL  };
 
-static int verify_inbox(struct index_storage *storage);
+static int verify_inbox(struct maildir_storage *storage);
 
 static struct mail_storage *
 maildir_create(const char *data, const char *user,
@@ -36,7 +36,8 @@
 	       enum mail_storage_lock_method lock_method)
 {
 	int debug = (flags & MAIL_STORAGE_FLAG_DEBUG) != 0;
-	struct index_storage *storage;
+	struct maildir_storage *storage;
+	struct index_storage *istorage;
 	const char *root_dir, *inbox_dir, *index_dir, *control_dir;
 	const char *home, *path, *p;
 	size_t len;
@@ -118,24 +119,26 @@
 	}
 
 	pool = pool_alloconly_create("storage", 256);
-	storage = p_new(pool, struct index_storage, 1);
-	storage->storage = maildir_storage;
-	storage->storage.pool = pool;
+	storage = p_new(pool, struct maildir_storage, 1);
+	storage->control_dir = p_strdup(pool, home_expand(control_dir));
+
+	istorage = INDEX_STORAGE(storage);
+	istorage->storage = maildir_storage;
+	istorage->storage.pool = pool;
 
 	/* the default ".temp.xxx" prefix would be treated as directory */
-	storage->temp_prefix =
+	istorage->temp_prefix =
 		p_strconcat(pool, "temp.", my_hostname, ".", my_pid, ".", NULL);
 
-	storage->dir = p_strdup(pool, home_expand(root_dir));
-	storage->inbox_path = p_strdup(pool, home_expand(inbox_dir));
-	storage->index_dir = p_strdup(pool, home_expand(index_dir));
-	storage->control_dir = p_strdup(pool, home_expand(control_dir));
-	storage->user = p_strdup(pool, user);
-	storage->callbacks = p_new(pool, struct mail_storage_callbacks, 1);
-	index_storage_init(storage, flags, lock_method);
+	istorage->dir = p_strdup(pool, home_expand(root_dir));
+	istorage->inbox_path = p_strdup(pool, home_expand(inbox_dir));
+	istorage->index_dir = p_strdup(pool, home_expand(index_dir));
+	istorage->user = p_strdup(pool, user);
+	istorage->callbacks = p_new(pool, struct mail_storage_callbacks, 1);
+	index_storage_init(istorage, flags, lock_method);
 
 	(void)verify_inbox(storage);
-	return &storage->storage;
+	return STORAGE(storage);
 }
 
 static void maildir_free(struct mail_storage *_storage)
@@ -260,13 +263,13 @@
 	return t_strconcat(storage->index_dir, "/"MAILDIR_FS_SEP_S, name, NULL);
 }
 
-static const char *maildir_get_control_path(struct index_storage *storage,
+static const char *maildir_get_control_path(struct maildir_storage *storage,
 					    const char *name)
 {
 	if (storage->control_dir == NULL)
-		return maildir_get_path(storage, name);
+		return maildir_get_path(INDEX_STORAGE(storage), name);
 
-	if ((storage->storage.flags & MAIL_STORAGE_FLAG_FULL_FS_ACCESS) != 0 &&
+	if ((STORAGE(storage)->flags & MAIL_STORAGE_FLAG_FULL_FS_ACCESS) != 0 &&
 	    (*name == '/' || *name == '~'))
 		return maildir_get_absolute_path(name, FALSE);
 
@@ -353,7 +356,7 @@
 	return 0;
 }
 
-static int create_control_dir(struct index_storage *storage, const char *name)
+static int create_control_dir(struct maildir_storage *storage, const char *name)
 {
 	const char *dir;
 
@@ -363,7 +366,7 @@
 	dir = t_strconcat(storage->control_dir, "/"MAILDIR_FS_SEP_S,
 			  name, NULL);
 	if (mkdir_parents(dir, CREATE_MODE) < 0 && errno != EEXIST) {
-		mail_storage_set_critical(&storage->storage,
+		mail_storage_set_critical(STORAGE(storage),
 					  "mkdir(%s) failed: %m", dir);
 		return -1;
 	}
@@ -371,18 +374,19 @@
 	return 0;
 }
 
-static int verify_inbox(struct index_storage *storage)
+static int verify_inbox(struct maildir_storage *storage)
 {
+	struct index_storage *istorage = INDEX_STORAGE(storage);
 	const char *path;
 
-	path = storage->inbox_path != NULL ?
-		storage->inbox_path : storage->dir;
+	path = istorage->inbox_path != NULL ?
+		istorage->inbox_path : istorage->dir;
 
-	if (create_maildir(storage, path, TRUE) < 0)
+	if (create_maildir(istorage, path, TRUE) < 0)
 		return -1;
 
 	/* make sure the index directories exist */
-	if (create_index_dir(storage, "INBOX") < 0)
+	if (create_index_dir(istorage, "INBOX") < 0)
 		return -1;
 	if (create_control_dir(storage, "INBOX") < 0)
 		return -1;
@@ -397,9 +401,10 @@
 }
 
 static struct mailbox *
-maildir_open(struct index_storage *storage, const char *name,
+maildir_open(struct maildir_storage *storage, const char *name,
 	     enum mailbox_open_flags flags)
 {
+	struct index_storage *istorage = INDEX_STORAGE(storage);
 	struct maildir_mailbox *mbox;
 	struct mail_index *index;
 	const char *path, *index_dir, *control_dir;
@@ -407,8 +412,8 @@
 	int shared;
 	pool_t pool;
 
-	path = maildir_get_path(storage, name);
-	index_dir = maildir_get_index_path(storage, name);
+	path = maildir_get_path(istorage, name);
+	index_dir = maildir_get_index_path(istorage, name);
 	control_dir = maildir_get_control_path(storage, name);
 
 	index = index_storage_alloc(index_dir, path, MAILDIR_INDEX_PREFIX);
@@ -423,7 +428,7 @@
 	mbox = p_new(pool, struct maildir_mailbox, 1);
 	mbox->ibox.box = maildir_mailbox;
 	mbox->ibox.box.pool = pool;
-	mbox->ibox.storage = storage;
+	mbox->ibox.storage = istorage;
 	mbox->ibox.mail_vfuncs = &maildir_mail_vfuncs;
 	mbox->ibox.is_recent = maildir_is_recent;
 
@@ -453,7 +458,8 @@
 maildir_mailbox_open(struct mail_storage *_storage, const char *name,
 		     struct istream *input, enum mailbox_open_flags flags)
 {
-	struct index_storage *storage = (struct index_storage *)_storage;
+	struct maildir_storage *storage = (struct maildir_storage *)_storage;
+	struct index_storage *istorage = INDEX_STORAGE(storage);
 	const char *path;
 	struct stat st;
 
@@ -476,11 +482,11 @@
 		return NULL;
 	}
 
-	path = maildir_get_path(storage, name);
+	path = maildir_get_path(istorage, name);
 	if (stat(path, &st) == 0) {
 		/* exists - make sure the required directories are also there */
-		if (create_maildir(storage, path, TRUE) < 0 ||
-		    create_index_dir(storage, name) < 0 ||
+		if (create_maildir(istorage, path, TRUE) < 0 ||
+		    create_index_dir(istorage, name) < 0 ||
 		    create_control_dir(storage, name) < 0)
 			return NULL;
 
@@ -765,14 +771,15 @@
 static int maildir_set_subscribed(struct mail_storage *_storage,
 				  const char *name, int set)
 {
-	struct index_storage *storage = (struct index_storage *)_storage;
+	struct maildir_storage *storage = (struct maildir_storage *)_storage;
 	const char *path;
 
 	path = t_strconcat(storage->control_dir != NULL ?
-			   storage->control_dir : storage->dir,
+			   storage->control_dir : INDEX_STORAGE(storage)->dir,
 			   "/" SUBSCRIPTION_FILE_NAME, NULL);
 
-	return subsfile_set_subscribed(_storage, path, storage->temp_prefix,
+	return subsfile_set_subscribed(_storage, path,
+				       INDEX_STORAGE(storage)->temp_prefix,
 				       name, set);
 }
 
@@ -832,6 +839,7 @@
 		       mailbox_notify_callback_t *callback, void *context)
 {
 	struct maildir_mailbox *mbox = (struct maildir_mailbox *)box;
+        struct index_storage *istorage = INDEX_STORAGE(mbox->storage);
 
 	mbox->ibox.min_notify_interval = min_interval;
 	mbox->ibox.notify_callback = callback;
@@ -843,9 +851,9 @@
 	}
 
 	index_mailbox_check_add(&mbox->ibox,
-		t_strconcat(mbox->storage->dir, "/new", NULL), TRUE);
+		t_strconcat(istorage->dir, "/new", NULL), TRUE);
 	index_mailbox_check_add(&mbox->ibox,
-		t_strconcat(mbox->storage->dir, "/cur", NULL), TRUE);
+		t_strconcat(istorage->dir, "/cur", NULL), TRUE);
 }
 
 struct mail_storage maildir_storage = {
--- a/src/lib-storage/index/maildir/maildir-storage.h	Fri Apr 08 16:13:45 2005 +0300
+++ b/src/lib-storage/index/maildir/maildir-storage.h	Fri Apr 08 17:32:49 2005 +0300
@@ -10,13 +10,24 @@
 
 #include "index-storage.h"
 
+#define STORAGE(maildir_storage) \
+	(&(maildir_storage)->storage.storage)
+#define INDEX_STORAGE(maildir_storage) \
+	(&(maildir_storage)->storage)
+
 struct timeval;
 struct maildir_save_context;
 struct maildir_copy_context;
 
+struct maildir_storage {
+	struct index_storage storage;
+
+	const char *control_dir;
+};
+
 struct maildir_mailbox {
 	struct index_mailbox ibox;
-	struct index_storage *storage;
+	struct maildir_storage *storage;
 
 	const char *path, *control_dir;
 
--- a/src/lib-storage/index/maildir/maildir-sync.c	Fri Apr 08 16:13:45 2005 +0300
+++ b/src/lib-storage/index/maildir/maildir-sync.c	Fri Apr 08 17:32:49 2005 +0300
@@ -218,7 +218,7 @@
 	if (errno == ENOENT)
 		return 0;
 
-	mail_storage_set_critical(&mbox->storage->storage,
+	mail_storage_set_critical(STORAGE(mbox->storage),
 				  "unlink(%s) failed: %m", path);
 	return -1;
 }
@@ -257,7 +257,7 @@
 		return 1;
 	}
 
-	mail_storage_set_critical(&mbox->storage->storage,
+	mail_storage_set_critical(STORAGE(mbox->storage),
 				  "rename(%s, %s) failed: %m", path, newpath);
 	return -1;
 }
@@ -404,7 +404,7 @@
 		i_warning("Fixed duplicate in %s: %s -> %s",
 			  mbox->path, old_fname, new_fname);
 	} else if (errno != ENOENT) {
-		mail_storage_set_critical(&mbox->storage->storage,
+		mail_storage_set_critical(STORAGE(mbox->storage),
 			"rename(%s, %s) failed: %m", old_path, new_path);
 		ret = -1;
 	}
@@ -415,7 +415,7 @@
 
 static int maildir_scan_dir(struct maildir_sync_context *ctx, int new_dir)
 {
-	struct mail_storage *storage = &ctx->mbox->storage->storage;
+	struct mail_storage *storage = STORAGE(ctx->mbox->storage);
 	const char *dir;
 	DIR *dirp;
 	string_t *src, *dest;
@@ -522,14 +522,14 @@
 	*new_changed_r = *cur_changed_r = FALSE;
 
 	if (stat(ctx->new_dir, &st) < 0) {
-		mail_storage_set_critical(&mbox->storage->storage,
+		mail_storage_set_critical(STORAGE(mbox->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(&mbox->storage->storage,
+		mail_storage_set_critical(STORAGE(mbox->storage),
 					  "stat(%s) failed: %m", ctx->cur_dir);
 		return -1;
 	}
@@ -619,7 +619,7 @@
 	    uid_validity != 0 && hdr->uid_validity != 0) {
 		/* uidvalidity changed and mailbox isn't being initialized,
 		   index must be rebuilt */
-		mail_storage_set_critical(&mbox->storage->storage,
+		mail_storage_set_critical(STORAGE(mbox->storage),
 			"Maildir %s sync: UIDVALIDITY changed (%u -> %u)",
 			mbox->path, hdr->uid_validity, uid_validity);
 		mail_index_mark_corrupted(mbox->ibox.index);
@@ -668,7 +668,7 @@
 				if ((uflags &
 				     MAILDIR_UIDLIST_REC_FLAG_RACING) != 0) {
 					mail_storage_set_critical(
-						&mbox->storage->storage,
+						STORAGE(mbox->storage),
 						"Maildir %s sync: "
 						"UID < next_uid "
 						"(%u < %u, file = %s)",
@@ -720,7 +720,7 @@
 			}
 			if ((uflags & MAILDIR_UIDLIST_REC_FLAG_RACING) != 0) {
 				mail_storage_set_critical(
-					&mbox->storage->storage,
+					STORAGE(mbox->storage),
 					"Maildir %s sync: "
 					"UID inserted in the middle of mailbox "
 					"(%u > %u, file = %s)",
--- a/src/lib-storage/index/maildir/maildir-uidlist.c	Fri Apr 08 16:13:45 2005 +0300
+++ b/src/lib-storage/index/maildir/maildir-uidlist.c	Fri Apr 08 17:32:49 2005 +0300
@@ -88,7 +88,7 @@
 	if (fd == -1) {
 		if (errno == EAGAIN)
 			return 0;
-		mail_storage_set_critical(&uidlist->mbox->storage->storage,
+		mail_storage_set_critical(STORAGE(uidlist->mbox->storage),
 			"file_dotlock_open(%s) failed: %m", path);
 		return -1;
 	}
@@ -139,7 +139,7 @@
 	uidlist->dotlock_settings.immediate_stale_timeout =
 		UIDLIST_LOCK_STALE_TIMEOUT;
 	uidlist->dotlock_settings.temp_prefix =
-		uidlist->mbox->storage->temp_prefix;
+		INDEX_STORAGE(mbox->storage)->temp_prefix;
 
 	return uidlist;
 }
@@ -179,12 +179,12 @@
 
 	if (uid == 0 || *line != ' ') {
 		/* invalid file */
-                mail_storage_set_critical(&uidlist->mbox->storage->storage,
+                mail_storage_set_critical(STORAGE(uidlist->mbox->storage),
 			"Invalid data in file %s", uidlist->fname);
 		return 0;
 	}
 	if (uid <= uidlist->prev_read_uid) {
-                mail_storage_set_critical(&uidlist->mbox->storage->storage,
+                mail_storage_set_critical(STORAGE(uidlist->mbox->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->mbox->storage->storage,
+                mail_storage_set_critical(STORAGE(uidlist->mbox->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->mbox->storage->storage,
+                mail_storage_set_critical(STORAGE(uidlist->mbox->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->mbox->storage->storage;
+	struct mail_storage *storage = STORAGE(uidlist->mbox->storage);
 	const char *line;
 	unsigned int uid_validity, next_uid;
 	struct istream *input;
@@ -443,7 +443,7 @@
 static int maildir_uidlist_rewrite_fd(struct maildir_uidlist *uidlist,
 				      const char *temp_path)
 {
-	struct mail_storage *storage = &uidlist->mbox->storage->storage;
+	struct mail_storage *storage = STORAGE(uidlist->mbox->storage);
 	struct maildir_uidlist_iter_ctx *iter;
 	struct utimbuf ut;
 	string_t *str;
@@ -528,7 +528,7 @@
 				      "/" MAILDIR_UIDLIST_NAME, NULL);
 
 		if (file_dotlock_replace(&uidlist->dotlock, 0) <= 0) {
-			mail_storage_set_critical(&mbox->storage->storage,
+			mail_storage_set_critical(STORAGE(mbox->storage),
 				"file_dotlock_replace(%s) failed: %m", db_path);
 			(void)unlink(temp_path);
 			ret = -1;
--- a/src/lib-storage/index/maildir/maildir-util.c	Fri Apr 08 16:13:45 2005 +0300
+++ b/src/lib-storage/index/maildir/maildir-util.c	Fri Apr 08 17:32:49 2005 +0300
@@ -56,7 +56,7 @@
 	}
 
 	if (i == 10) {
-		mail_storage_set_critical(&mbox->storage->storage,
+		mail_storage_set_critical(STORAGE(mbox->storage),
 			"maildir_file_do(%s) racing", mbox->path);
 	}
 
@@ -244,10 +244,10 @@
 	*fname_r = t_strdup(path);
 	if (fd == -1) {
 		if (ENOSPACE(errno)) {
-			mail_storage_set_error(&mbox->storage->storage,
+			mail_storage_set_error(STORAGE(mbox->storage),
 					       "Not enough disk space");
 		} else {
-			mail_storage_set_critical(&mbox->storage->storage,
+			mail_storage_set_critical(STORAGE(mbox->storage),
 						  "open(%s) failed: %m", path);
 		}
 	}
--- a/src/lib-storage/index/mbox/mbox-file.c	Fri Apr 08 16:13:45 2005 +0300
+++ b/src/lib-storage/index/mbox/mbox-file.c	Fri Apr 08 17:32:49 2005 +0300
@@ -134,7 +134,7 @@
 	}
 
 	if (data == NULL) {
-		mail_storage_set_critical(&mbox->storage->storage,
+		mail_storage_set_critical(STORAGE(mbox->storage),
 			"Cached message offset lost for seq %u in mbox file %s",
 			seq, mbox->path);
 		mail_index_mark_corrupted(mbox->ibox.index);
@@ -144,7 +144,7 @@
 	offset = *((const uint64_t *)data);
 	if (istream_raw_mbox_seek(mbox->mbox_stream, offset) < 0) {
 		if (offset == 0) {
-			mail_storage_set_error(&mbox->storage->storage,
+			mail_storage_set_error(STORAGE(mbox->storage),
 				"Mailbox isn't a valid mbox file");
 			return -1;
 		}
@@ -152,7 +152,7 @@
 		if (mbox->mbox_sync_dirty)
 			return 0;
 
-		mail_storage_set_critical(&mbox->storage->storage,
+		mail_storage_set_critical(STORAGE(mbox->storage),
 			"Cached message offset %s is invalid for mbox file %s",
 			dec2str(offset), mbox->path);
 		mail_index_mark_corrupted(mbox->ibox.index);
--- a/src/lib-storage/index/mbox/mbox-lock.c	Fri Apr 08 16:13:45 2005 +0300
+++ b/src/lib-storage/index/mbox/mbox-lock.c	Fri Apr 08 17:32:49 2005 +0300
@@ -259,7 +259,7 @@
 		return -1;
 	}
 	if (ret == 0) {
-		mail_storage_set_error(&mbox->storage->storage,
+		mail_storage_set_error(STORAGE(mbox->storage),
 				       "Timeout while waiting for lock");
 		return 0;
 	}
@@ -485,7 +485,7 @@
 		if (!drop_locks)
 			(void)mbox_unlock_files(&ctx);
 		if (ret == 0) {
-			mail_storage_set_error(&mbox->storage->storage,
+			mail_storage_set_error(STORAGE(mbox->storage),
 				"Timeout while waiting for lock");
 		}
 		return ret;
--- a/src/lib-storage/index/mbox/mbox-save.c	Fri Apr 08 16:13:45 2005 +0300
+++ b/src/lib-storage/index/mbox/mbox-save.c	Fri Apr 08 17:32:49 2005 +0300
@@ -51,7 +51,7 @@
 static void write_error(struct mbox_save_context *ctx, int error)
 {
 	if (ENOSPACE(error)) {
-		mail_storage_set_error(&ctx->mbox->storage->storage,
+		mail_storage_set_error(STORAGE(ctx->mbox->storage),
 				       "Not enough disk space");
 	} else {
 		errno = error;
@@ -127,8 +127,9 @@
 
 	t_push();
 	if (from_envelope == NULL) {
-		from_envelope = t_strconcat(ctx->mbox->storage->user,
-					    "@", my_hostdomain, NULL);
+		from_envelope =
+			t_strconcat(INDEX_STORAGE(ctx->mbox->storage)->user,
+				    "@", my_hostdomain, NULL);
 	}
 
 	/* save in local timezone, no matter what it was given with */
@@ -263,7 +264,7 @@
 	int ret;
 
 	if (ctx->mbox->mbox_readonly || ctx->mbox->ibox.readonly) {
-		mail_storage_set_error(&ctx->mbox->storage->storage,
+		mail_storage_set_error(STORAGE(ctx->mbox->storage),
 				       "Read-only mbox");
 		return -1;
 	}
@@ -397,7 +398,7 @@
 						      save_header_callback,
 						      ctx);
 		ctx->body_output =
-			(ctx->mbox->storage->storage.flags &
+			(STORAGE(mbox->storage)->flags &
 			 MAIL_STORAGE_FLAG_SAVE_CRLF) != 0 ?
 			o_stream_create_crlf(default_pool, ctx->output) :
 			o_stream_create_lf(default_pool, ctx->output);
@@ -513,10 +514,10 @@
 	if (ctx->failed) {
 		errno = ctx->output->stream_errno;
 		if (ENOSPACE(errno)) {
-			mail_storage_set_error(&ctx->mbox->storage->storage,
+			mail_storage_set_error(STORAGE(ctx->mbox->storage),
 					       "Not enough disk space");
 		} else if (errno != 0) {
-			mail_storage_set_critical(&ctx->mbox->storage->storage,
+			mail_storage_set_critical(STORAGE(ctx->mbox->storage),
 				"write(%s) failed: %m", ctx->mbox->path);
 		}
 		return -1;
--- a/src/lib-storage/index/mbox/mbox-storage.c	Fri Apr 08 16:13:45 2005 +0300
+++ b/src/lib-storage/index/mbox/mbox-storage.c	Fri Apr 08 17:32:49 2005 +0300
@@ -41,7 +41,7 @@
 {
 	i_assert(function != NULL);
 
-	mail_storage_set_critical(&mbox->storage->storage,
+	mail_storage_set_critical(STORAGE(mbox->storage),
 		"%s failed with mbox file %s: %m", function, mbox->path);
 	return -1;
 }
@@ -247,7 +247,8 @@
 	    enum mail_storage_lock_method lock_method)
 {
 	int debug = (flags & MAIL_STORAGE_FLAG_DEBUG) != 0;
-	struct index_storage *storage;
+	struct mbox_storage *storage;
+	struct index_storage *istorage;
 	const char *root_dir, *inbox_file, *index_dir, *p;
 	struct stat st;
 	int autodetect;
@@ -330,17 +331,18 @@
 	}
 
 	pool = pool_alloconly_create("storage", 256);
-	storage = p_new(pool, struct index_storage, 1);
-	storage->storage = mbox_storage;
-	storage->storage.pool = pool;
+	storage = p_new(pool, struct mbox_storage, 1);
+	istorage = INDEX_STORAGE(storage);
+	istorage->storage = mbox_storage;
+	istorage->storage.pool = pool;
 
-	storage->dir = p_strdup(pool, home_expand(root_dir));
-	storage->inbox_path = p_strdup(pool, home_expand(inbox_file));
-	storage->index_dir = p_strdup(pool, home_expand(index_dir));
-	storage->user = p_strdup(pool, user);
-	storage->callbacks = p_new(pool, struct mail_storage_callbacks, 1);
-	index_storage_init(storage, flags, lock_method);
-	return &storage->storage;
+	istorage->dir = p_strdup(pool, home_expand(root_dir));
+	istorage->inbox_path = p_strdup(pool, home_expand(inbox_file));
+	istorage->index_dir = p_strdup(pool, home_expand(index_dir));
+	istorage->user = p_strdup(pool, user);
+	istorage->callbacks = p_new(pool, struct mail_storage_callbacks, 1);
+	index_storage_init(istorage, flags, lock_method);
+	return &storage->storage.storage;
 }
 
 static void mbox_free(struct mail_storage *_storage)
@@ -481,7 +483,7 @@
 }
 
 static struct mbox_mailbox *
-mbox_alloc(struct index_storage *storage, struct mail_index *index,
+mbox_alloc(struct mbox_storage *storage, struct mail_index *index,
 	   const char *name, enum mailbox_open_flags flags)
 {
 	struct mbox_mailbox *mbox;
@@ -491,7 +493,7 @@
 	mbox = p_new(pool, struct mbox_mailbox, 1);
 	mbox->ibox.box = mbox_mailbox;
 	mbox->ibox.box.pool = pool;
-	mbox->ibox.storage = storage;
+	mbox->ibox.storage = INDEX_STORAGE(storage);
 	mbox->ibox.mail_vfuncs = &mbox_mail_vfuncs;
 	mbox->ibox.is_recent = mbox_mail_is_recent;
 
@@ -511,15 +513,16 @@
 	mbox->mbox_do_dirty_syncs = mbox->mbox_very_dirty_syncs ||
 		getenv("MBOX_DIRTY_SYNCS") != NULL;
 
-	if ((storage->storage.flags & MAIL_STORAGE_FLAG_KEEP_HEADER_MD5) != 0)
+	if ((STORAGE(storage)->flags & MAIL_STORAGE_FLAG_KEEP_HEADER_MD5) != 0)
 		mbox->mbox_save_md5 = TRUE;
 	return mbox;
 }
 
 static struct mailbox *
-mbox_open(struct index_storage *storage, const char *name,
+mbox_open(struct mbox_storage *storage, const char *name,
 	  enum mailbox_open_flags flags)
 {
+	struct index_storage *istorage = INDEX_STORAGE(storage);
 	struct mbox_mailbox *mbox;
 	struct mail_index *index;
 	const char *path, *index_dir;
@@ -528,14 +531,14 @@
 		/* name = "INBOX"
 		   path = "<inbox_file>/INBOX"
 		   index_dir = "/mail/.imap/INBOX" */
-		path = storage->inbox_path;
-		index_dir = mbox_get_index_dir(storage, "INBOX");
+		path = istorage->inbox_path;
+		index_dir = mbox_get_index_dir(istorage, "INBOX");
 	} else {
 		/* name = "foo/bar"
 		   path = "/mail/foo/bar"
 		   index_dir = "/mail/foo/.imap/bar" */
-		path = mbox_get_path(storage, name);
-		index_dir = mbox_get_index_dir(storage, name);
+		path = mbox_get_path(istorage, name);
+		index_dir = mbox_get_index_dir(istorage, name);
 	}
 
 	index = index_storage_alloc(index_dir, path, MBOX_INDEX_PREFIX);
@@ -558,7 +561,7 @@
 }
 
 static struct mailbox *
-mbox_mailbox_open_stream(struct index_storage *storage, const char *name,
+mbox_mailbox_open_stream(struct mbox_storage *storage, const char *name,
 			 struct istream *input, enum mailbox_open_flags flags)
 {
 	struct mail_index *index;
@@ -583,7 +586,8 @@
 mbox_mailbox_open(struct mail_storage *_storage, const char *name,
 		  struct istream *input, enum mailbox_open_flags flags)
 {
-	struct index_storage *storage = (struct index_storage *)_storage;
+	struct mbox_storage *storage = (struct mbox_storage *)_storage;
+	struct index_storage *istorage = INDEX_STORAGE(storage);
 	const char *path;
 	struct stat st;
 
@@ -594,7 +598,7 @@
 
 	if (strcmp(name, "INBOX") == 0) {
 		/* make sure INBOX exists */
-		if (verify_inbox(storage) < 0)
+		if (verify_inbox(istorage) < 0)
 			return NULL;
 		return mbox_open(storage, "INBOX", flags);
 	}
@@ -604,7 +608,7 @@
 		return NULL;
 	}
 
-	path = mbox_get_path(storage, name);
+	path = mbox_get_path(istorage, name);
 	if (stat(path, &st) == 0) {
 		if (S_ISDIR(st.st_mode)) {
 			mail_storage_set_error(_storage,
@@ -613,7 +617,7 @@
 		}
 
 		/* exists - make sure the required directories are also there */
-		if (create_mbox_index_dirs(storage, name) < 0)
+		if (create_mbox_index_dirs(istorage, name) < 0)
 			return NULL;
 
 		return mbox_open(storage, name, flags);
@@ -622,7 +626,7 @@
 	if (ENOTFOUND(errno)) {
 		mail_storage_set_error(_storage, "Mailbox doesn't exist: %s",
 				       name);
-	} else if (!mbox_handle_errors(storage)) {
+	} else if (!mbox_handle_errors(istorage)) {
 		mail_storage_set_critical(_storage, "stat(%s) failed: %m",
 					  path);
 	}
--- a/src/lib-storage/index/mbox/mbox-storage.h	Fri Apr 08 16:13:45 2005 +0300
+++ b/src/lib-storage/index/mbox/mbox-storage.h	Fri Apr 08 17:32:49 2005 +0300
@@ -11,9 +11,18 @@
 
 #include "index-storage.h"
 
+#define STORAGE(mbox_storage) \
+	(&(mbox_storage)->storage.storage)
+#define INDEX_STORAGE(mbox_storage) \
+	(&(mbox_storage)->storage)
+
+struct mbox_storage {
+	struct index_storage storage;
+};
+
 struct mbox_mailbox {
 	struct index_mailbox ibox;
-	struct index_storage *storage;
+	struct mbox_storage *storage;
 
 	const char *path;
 
--- a/src/lib-storage/index/mbox/mbox-sync-rewrite.c	Fri Apr 08 16:13:45 2005 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync-rewrite.c	Fri Apr 08 17:32:49 2005 +0300
@@ -36,7 +36,7 @@
         if (ret == (off_t)size)
 		ret = 0;
 	else if (ret >= 0) {
-		mail_storage_set_critical(&sync_ctx->mbox->storage->storage,
+		mail_storage_set_critical(STORAGE(sync_ctx->mbox->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->mbox->path);
--- a/src/lib-storage/index/mbox/mbox-sync.c	Fri Apr 08 16:13:45 2005 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync.c	Fri Apr 08 17:32:49 2005 +0300
@@ -65,7 +65,7 @@
 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->mbox->storage->storage,
+		mail_storage_set_critical(STORAGE(sync_ctx->mbox->storage),
 			"Unexpectedly lost From-line at offset %"PRIuUOFF_T
 			" from mbox file %s", from_offset,
 			sync_ctx->mbox->path);
@@ -271,14 +271,14 @@
 
 	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->mbox->storage->storage,
+		mail_storage_set_critical(STORAGE(sync_ctx->mbox->storage),
 			"mbox sync: Expunged message reappeared in mailbox %s "
 			"(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->mbox->storage->storage,
+		mail_storage_set_critical(STORAGE(sync_ctx->mbox->storage),
 			"mbox sync: UID inserted in the middle of mailbox %s "
 			"(%u > %u)", sync_ctx->mbox->path, rec->uid, uid);
 		ret = 0; rec = NULL;
@@ -537,7 +537,7 @@
 	}
 
 	if (uid_last != sync_ctx->base_uid_last) {
-		mail_storage_set_critical(&sync_ctx->mbox->storage->storage,
+		mail_storage_set_critical(STORAGE(sync_ctx->mbox->storage),
 			"X-IMAPbase uid-last unexpectedly lost in mbox file %s",
 			sync_ctx->mbox->path);
 		return -1;
@@ -775,7 +775,7 @@
 
 	if (seq == 0) {
 		if (istream_raw_mbox_seek(mbox->mbox_stream, 0) < 0) {
-			mail_storage_set_error(&mbox->storage->storage,
+			mail_storage_set_error(STORAGE(mbox->storage),
 				"Mailbox isn't a valid mbox file");
 			return -1;
 		}
@@ -791,7 +791,7 @@
 			if (istream_raw_mbox_seek(mbox->mbox_stream,
 						  old_offset) < 0) {
 				mail_storage_set_critical(
-					&mbox->storage->storage,
+					STORAGE(mbox->storage),
 					"Error seeking back to original "
 					"offset %s in mbox file %s",
 					dec2str(old_offset), mbox->path);
@@ -849,7 +849,7 @@
 		if (istream_raw_mbox_seek(sync_ctx->mbox->mbox_stream,
 					  st->st_size) < 0) {
 			mail_storage_set_critical(
-				&sync_ctx->mbox->storage->storage,
+				STORAGE(sync_ctx->mbox->storage),
 				"Error seeking to end of mbox file %s",
 				sync_ctx->mbox->path);
 			return -1;
@@ -935,7 +935,7 @@
 		    sync_ctx->base_uid_validity !=
 		    sync_ctx->hdr->uid_validity) {
 			mail_storage_set_critical(
-				&sync_ctx->mbox->storage->storage,
+				STORAGE(sync_ctx->mbox->storage),
 				"UIDVALIDITY changed (%u -> %u) "
 				"in mbox file %s",
 				sync_ctx->hdr->uid_validity,