[dovecot-cvs] dovecot/src/lib-storage/index/maildir maildir-copy.c, 1.33, 1.34 maildir-mail.c, 1.11, 1.12 maildir-save.c, 1.47, 1.48 maildir-storage.c, 1.92, 1.93 maildir-storage.h, 1.34, 1.35 maildir-transaction.c, 1.6, 1.7

cras at dovecot.org cras at dovecot.org
Tue Mar 15 21:01:56 EET 2005


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

Modified Files:
	maildir-copy.c maildir-mail.c maildir-save.c maildir-storage.c 
	maildir-storage.h maildir-transaction.c 
Log Message:
Major mail-storage API changes. It's now a bit cleaner and much more plugin
friendly. Removed proxy_mailbox* stuff, they were difficult to use and
there's now much easier way to replace them.



Index: maildir-copy.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-copy.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- maildir-copy.c	26 Dec 2004 09:12:43 -0000	1.33
+++ maildir-copy.c	15 Mar 2005 19:01:52 -0000	1.34
@@ -3,6 +3,7 @@
 #include "lib.h"
 #include "ioloop.h"
 #include "maildir-storage.h"
+#include "index-mail.h"
 #include "mail-copy.h"
 
 #include <stdlib.h>
@@ -63,8 +64,8 @@
 	const char *const *keywords;
 	const char *dest_fname;
 
-        flags = mail->get_flags(mail);
-        keywords = mail->get_keywords(mail);
+        flags = mail_get_flags(mail);
+        keywords = mail_get_keywords(mail);
 	dest_fname = maildir_generate_tmp_filename(&ioloop_timeval);
 	dest_fname = maildir_filename_set_flags(dest_fname, flags, keywords);
 
@@ -72,7 +73,7 @@
 	do_ctx.dest_path =
 		t_strconcat(ctx->ibox->path, "/new/", dest_fname, NULL);
 
-	if (maildir_file_do(imail->ibox, imail->mail.uid,
+	if (maildir_file_do(imail->ibox, imail->mail.mail.uid,
 			    do_hardlink, &do_ctx) < 0)
 		return -1;
 
@@ -123,7 +124,7 @@
 }
 
 int maildir_copy(struct mailbox_transaction_context *_t, struct mail *mail,
-		 struct mail **dest_mail_r)
+		 struct mail *dest_mail)
 {
 	struct maildir_transaction_context *t =
 		(struct maildir_transaction_context *)_t;
@@ -135,7 +136,7 @@
 	ctx = t->copy_ctx;
 
 	if (ctx->hardlink && mail->box->storage == ctx->ibox->box.storage) {
-		// FIXME: handle dest_mail_r
+		// FIXME: handle dest_mail
 		t_push();
 		ret = maildir_copy_hardlink(mail, ctx);
 		t_pop();
@@ -148,5 +149,5 @@
 		/* non-fatal hardlinking failure, try the slow way */
 	}
 
-	return mail_storage_copy(_t, mail, dest_mail_r);
+	return mail_storage_copy(_t, mail, dest_mail);
 }

Index: maildir-mail.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-mail.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- maildir-mail.c	15 Mar 2005 11:30:12 -0000	1.11
+++ maildir-mail.c	15 Mar 2005 19:01:52 -0000	1.12
@@ -77,7 +77,7 @@
 
 	if (data->open_mail && data->stream == NULL) {
 		/* we're going to open the mail anyway */
-		(void)_mail->get_stream(_mail, NULL, NULL);
+		(void)mail_get_stream(_mail, NULL, NULL);
 	}
 
 	if (data->stream != NULL) {
@@ -90,7 +90,7 @@
 			return (time_t)-1;
 		}
 	} else {
-		if (maildir_file_do(mail->ibox, mail->mail.uid,
+		if (maildir_file_do(mail->ibox, mail->mail.mail.uid,
 				    do_stat, &st) <= 0)
 			return (time_t)-1;
 	}
@@ -120,7 +120,7 @@
 	}
 
 	fname = maildir_uidlist_lookup(mail->ibox->uidlist,
-				       mail->mail.uid, &flags);
+				       mail->mail.mail.uid, &flags);
 	if (fname == NULL)
 		return (uoff_t)-1;
 
@@ -154,7 +154,7 @@
 
 	if (field == MAIL_FETCH_UIDL_FILE_NAME) {
 	    	fname = maildir_uidlist_lookup(mail->ibox->uidlist,
-					       mail->mail.uid, &flags);
+					       mail->mail.mail.uid, &flags);
 		end = strchr(fname, ':');
 		return end == NULL ? fname : t_strdup_until(fname, end);
 	}
@@ -176,7 +176,7 @@
 		return size;
 
 	fname = maildir_uidlist_lookup(mail->ibox->uidlist,
-				       mail->mail.uid, &flags);
+				       mail->mail.mail.uid, &flags);
 	if (fname == NULL)
 		return (uoff_t)-1;
 
@@ -195,7 +195,7 @@
 	}
 
 	if (size == (uoff_t)-1) {
-		if (maildir_file_do(mail->ibox, mail->mail.uid,
+		if (maildir_file_do(mail->ibox, mail->mail.mail.uid,
 				    do_stat, &st) <= 0)
 			return (uoff_t)-1;
 		size = st.st_size;
@@ -217,8 +217,8 @@
 	int deleted;
 
 	if (data->stream == NULL) {
-		data->stream = maildir_open_mail(mail->ibox, mail->mail.uid,
-						 &deleted);
+		data->stream = maildir_open_mail(mail->ibox,
+						 mail->mail.mail.uid, &deleted);
 		if (data->stream == NULL) {
 			_mail->expunged = deleted;
 			return NULL;
@@ -228,8 +228,9 @@
 	return index_mail_init_stream(mail, hdr_size, body_size);
 }
 
-struct mail maildir_mail = {
-	0, 0, 0, 0, 0, 0, 0,
+struct mail_vfuncs maildir_mail_vfuncs = {
+	index_mail_free,
+	index_mail_set_seq,
 
 	index_mail_get_flags,
 	index_mail_get_keywords,

Index: maildir-save.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-save.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- maildir-save.c	10 Jan 2005 17:37:24 -0000	1.47
+++ maildir-save.c	15 Mar 2005 19:01:52 -0000	1.48
@@ -27,7 +27,6 @@
 	struct index_mailbox *ibox;
 	struct mail_index_transaction *trans;
 	struct maildir_uidlist_sync_ctx *sync_ctx;
-	struct index_mail mail;
 
 	const char *tmpdir, *newdir, *curdir;
 	struct maildir_filename *files;
@@ -81,7 +80,7 @@
 }
 
 static struct maildir_save_context *
-maildir_transaction_save_init(struct maildir_transaction_context *t)
+maildir_save_transaction_init(struct maildir_transaction_context *t)
 {
         struct index_mailbox *ibox = t->ictx.ibox;
 	struct maildir_save_context *ctx;
@@ -89,12 +88,10 @@
 
 	pool = pool_alloconly_create("maildir_save_context", 4096);
 	ctx = p_new(pool, struct maildir_save_context, 1);
-	ctx->ctx.box = &ibox->box;
+	ctx->ctx.transaction = &t->ictx.mailbox_ctx;
 	ctx->pool = pool;
 	ctx->ibox = ibox;
-	ctx->trans = mail_index_transaction_begin(ibox->view, FALSE, TRUE);
-
-	index_mail_init(&t->ictx, &ctx->mail, 0, NULL);
+	ctx->trans = t->ictx.trans;
 
 	ctx->tmpdir = p_strconcat(pool, ibox->path, "/tmp", NULL);
 	ctx->newdir = p_strconcat(pool, ibox->path, "/new", NULL);
@@ -119,10 +116,12 @@
 	struct ostream *output;
 	const char *fname, *dest_fname, *path;
 
+	i_assert((t->ictx.flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0);
+
 	t_push();
 
 	if (t->save_ctx == NULL)
-		t->save_ctx = maildir_transaction_save_init(t);
+		t->save_ctx = maildir_save_transaction_init(t);
 	ctx = t->save_ctx;
 
 	/* create a new file in tmp/ directory */
@@ -191,7 +190,7 @@
 	return 0;
 }
 
-int maildir_save_finish(struct mail_save_context *_ctx, struct mail **mail_r)
+int maildir_save_finish(struct mail_save_context *_ctx, struct mail *dest_mail)
 {
 	struct maildir_save_context *ctx = (struct maildir_save_context *)_ctx;
 	struct utimbuf buf;
@@ -257,12 +256,11 @@
 		return -1;
 	}
 
-	if (mail_r != NULL) {
+	if (dest_mail != NULL) {
 		i_assert(ctx->seq != 0);
 
-		if (index_mail_next(&ctx->mail, ctx->seq) < 0)
+		if (mail_set_seq(dest_mail, ctx->seq) < 0)
 			return -1;
-		*mail_r = &ctx->mail.mail;
 	}
 
 	t_pop();
@@ -308,9 +306,7 @@
 	uint32_t first_uid, last_uid;
 	enum maildir_uidlist_rec_flag flags;
 	const char *fname;
-	uint32_t seq;
-	uoff_t offset;
-	int ret = 0;
+	int ret;
 
 	i_assert(ctx->output == NULL);
 
@@ -352,10 +348,7 @@
 		}
 	}
 
-	if (mail_index_transaction_commit(ctx->trans, &seq, &offset) < 0)
-		ret = -1;
-	return ret;
-
+	return 0;
 }
 
 void maildir_transaction_save_commit_post(struct maildir_save_context *ctx)
@@ -363,7 +356,6 @@
 	/* can't do anything anymore if we fail */
 	(void)maildir_uidlist_sync_deinit(ctx->sync_ctx);
 
-	index_mail_deinit(&ctx->mail);
 	pool_unref(ctx->pool);
 }
 
@@ -385,7 +377,5 @@
 	}
 	t_pop();
 
-	mail_index_transaction_rollback(ctx->trans);
-	index_mail_deinit(&ctx->mail);
 	pool_unref(ctx->pool);
 }

Index: maildir-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-storage.c,v
retrieving revision 1.92
retrieving revision 1.93
diff -u -d -r1.92 -r1.93
--- maildir-storage.c	9 Feb 2005 21:14:13 -0000	1.92
+++ maildir-storage.c	15 Mar 2005 19:01:52 -0000	1.93
@@ -8,6 +8,7 @@
 #include "subscription-file/subscription-file.h"
 #include "maildir-storage.h"
 #include "maildir-uidlist.h"
+#include "index-mail.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -38,6 +39,7 @@
 	const char *root_dir, *inbox_dir, *index_dir, *control_dir;
 	const char *home, *path, *p;
 	size_t len;
+	pool_t pool;
 
 	inbox_dir = root_dir = index_dir = control_dir = NULL;
 
@@ -114,19 +116,21 @@
 		       inbox_dir == NULL ? "" : inbox_dir);
 	}
 
-	storage = i_new(struct index_storage, 1);
+	pool = pool_alloconly_create("storage", 256);
+	storage = p_new(pool, struct index_storage, 1);
 	storage->storage = maildir_storage;
+	storage->storage.pool = pool;
 
 	/* the default ".temp.xxx" prefix would be treated as directory */
 	storage->temp_prefix =
-		i_strconcat("temp.", my_hostname, ".", my_pid, ".", NULL);
+		p_strconcat(pool, "temp.", my_hostname, ".", my_pid, ".", NULL);
 
-	storage->dir = i_strdup(home_expand(root_dir));
-	storage->inbox_path = i_strdup(home_expand(inbox_dir));
-	storage->index_dir = i_strdup(home_expand(index_dir));
-	storage->control_dir = i_strdup(home_expand(control_dir));
-	storage->user = i_strdup(user);
-	storage->callbacks = i_new(struct mail_storage_callbacks, 1);
+	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);
 
 	(void)verify_inbox(storage);
@@ -138,15 +142,7 @@
 	struct index_storage *storage = (struct index_storage *) _storage;
 
 	index_storage_deinit(storage);
-
-	i_free(storage->temp_prefix);
-	i_free(storage->dir);
-	i_free(storage->inbox_path);
-	i_free(storage->index_dir);
-	i_free(storage->control_dir);
-	i_free(storage->user);
-	i_free(storage->callbacks);
-	i_free(storage);
+	pool_unref(storage->storage.pool);
 }
 
 static int maildir_autodetect(const char *data, enum mail_storage_flags flags)
@@ -406,6 +402,7 @@
 	const char *path, *index_dir, *control_dir;
 	struct stat st;
 	int shared;
+	pool_t pool;
 
 	path = maildir_get_path(storage, name);
 	index_dir = maildir_get_index_path(storage, name);
@@ -419,15 +416,21 @@
 	if (shared)
 		mail_index_set_permissions(index, st.st_mode & 0666, st.st_gid);
 
-	ibox = index_storage_mailbox_init(storage, &maildir_mailbox,
-					  index, name, flags);
-	if (ibox == NULL)
+	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;
+
+	if (index_storage_mailbox_init(ibox, index, name, flags) < 0) {
+		/* the memory was already freed */
 		return NULL;
+	}
 
-	ibox->path = i_strdup(path);
-	ibox->control_dir = i_strdup(control_dir);
+	ibox->path = p_strdup(pool, path);
+	ibox->control_dir = p_strdup(pool, control_dir);
 
-	ibox->mail_interface = &maildir_mail;
+	ibox->mail_vfuncs = &maildir_mail_vfuncs;
 	ibox->uidlist = maildir_uidlist_init(ibox);
 	ibox->is_recent = maildir_is_recent;
 
@@ -836,59 +839,67 @@
 }
 
 struct mail_storage maildir_storage = {
-	"maildir", /* name */
-
-	'.', /* hierarchy separator */
+	MEMBER(name) "maildir",
+	MEMBER(hierarchy_sep) '.',
 
-	maildir_create,
-	maildir_free,
-	maildir_autodetect,
-	index_storage_set_callbacks,
-	maildir_mailbox_open,
-	maildir_mailbox_create,
-	maildir_mailbox_delete,
-	maildir_mailbox_rename,
-	maildir_mailbox_list_init,
-	maildir_mailbox_list_next,
-	maildir_mailbox_list_deinit,
-	maildir_set_subscribed,
-	maildir_get_mailbox_name_status,
-	index_storage_get_last_error,
+	{
+		maildir_create,
+		maildir_free,
+		maildir_autodetect,
+		index_storage_set_callbacks,
+		maildir_mailbox_open,
+		maildir_mailbox_create,
+		maildir_mailbox_delete,
+		maildir_mailbox_rename,
+		maildir_mailbox_list_init,
+		maildir_mailbox_list_next,
+		maildir_mailbox_list_deinit,
+		maildir_set_subscribed,
+		maildir_get_mailbox_name_status,
+		index_storage_get_last_error
+	},
 
-	NULL,
-	0,
-	0
+	MEMBER(pool) NULL,
+	MEMBER(error) NULL,
+	MEMBER(flags) 0,
+	MEMBER(module_contexts) ARRAY_INIT,
+	MEMBER(syntax_error) 0
 };
 
 struct mailbox maildir_mailbox = {
-	NULL, /* name */
-	NULL, /* storage */
+	MEMBER(name) NULL, 
+	MEMBER(storage) NULL, 
 
-	index_storage_is_readonly,
-        index_storage_allow_new_keywords,
-	maildir_storage_close,
-	index_storage_get_status,
-	maildir_storage_sync_init,
-	index_mailbox_sync_next,
-	index_mailbox_sync_deinit,
-	maildir_notify_changes,
-	maildir_transaction_begin,
-	maildir_transaction_commit,
-	maildir_transaction_rollback,
-	index_keywords_create,
-	index_keywords_free,
-	index_storage_fetch,
-	index_storage_get_uids,
-	index_header_lookup_init,
-        index_header_lookup_deinit,
-	index_storage_search_get_sorting,
-	index_storage_search_init,
-	index_storage_search_deinit,
-	index_storage_search_next,
-	maildir_save_init,
-	maildir_save_continue,
-	maildir_save_finish,
-	maildir_save_cancel,
-	maildir_copy,
-	index_storage_is_inconsistent
+	{
+		index_storage_is_readonly,
+		index_storage_allow_new_keywords,
+		maildir_storage_close,
+		index_storage_get_status,
+		maildir_storage_sync_init,
+		index_mailbox_sync_next,
+		index_mailbox_sync_deinit,
+		maildir_notify_changes,
+		maildir_transaction_begin,
+		maildir_transaction_commit,
+		maildir_transaction_rollback,
+		index_keywords_create,
+		index_keywords_free,
+		index_storage_get_uids,
+		index_mail_alloc,
+		index_header_lookup_init,
+		index_header_lookup_deinit,
+		index_storage_search_get_sorting,
+		index_storage_search_init,
+		index_storage_search_deinit,
+		index_storage_search_next,
+		maildir_save_init,
+		maildir_save_continue,
+		maildir_save_finish,
+		maildir_save_cancel,
+		maildir_copy,
+		index_storage_is_inconsistent
+	},
+
+	MEMBER(pool) NULL,
+	MEMBER(module_contexts) ARRAY_INIT
 };

Index: maildir-storage.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-storage.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- maildir-storage.h	10 Jan 2005 17:37:24 -0000	1.34
+++ maildir-storage.h	15 Mar 2005 19:01:52 -0000	1.35
@@ -20,7 +20,7 @@
 	struct maildir_copy_context *copy_ctx;
 };
 
-extern struct mail maildir_mail;
+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,
@@ -51,7 +51,8 @@
 			      int partial);
 
 struct mailbox_transaction_context *
-maildir_transaction_begin(struct mailbox *box, int hide);
+maildir_transaction_begin(struct mailbox *box,
+			  enum mailbox_transaction_flags flags);
 int maildir_transaction_commit(struct mailbox_transaction_context *t,
 			       enum mailbox_sync_flags flags);
 void maildir_transaction_rollback(struct mailbox_transaction_context *t);
@@ -63,7 +64,7 @@
 		  const char *from_envelope, struct istream *input,
 		  int want_mail);
 int maildir_save_continue(struct mail_save_context *ctx);
-int maildir_save_finish(struct mail_save_context *ctx, struct mail **mail_r);
+int maildir_save_finish(struct mail_save_context *ctx, struct mail *dest_mail);
 void maildir_save_cancel(struct mail_save_context *ctx);
 
 int maildir_transaction_save_commit_pre(struct maildir_save_context *ctx);
@@ -71,7 +72,7 @@
 void maildir_transaction_save_rollback(struct maildir_save_context *ctx);
 
 int maildir_copy(struct mailbox_transaction_context *t, struct mail *mail,
-		 struct mail **dest_mail_r);
+		 struct mail *dest_mail);
 int maildir_transaction_copy_commit(struct maildir_copy_context *ctx);
 void maildir_transaction_copy_rollback(struct maildir_copy_context *ctx);
 

Index: maildir-transaction.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-transaction.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- maildir-transaction.c	21 Oct 2004 20:58:23 -0000	1.6
+++ maildir-transaction.c	15 Mar 2005 19:01:52 -0000	1.7
@@ -4,13 +4,14 @@
 #include "maildir-storage.h"
 
 struct mailbox_transaction_context *
-maildir_transaction_begin(struct mailbox *box, int hide)
+maildir_transaction_begin(struct mailbox *box,
+			  enum mailbox_transaction_flags flags)
 {
 	struct index_mailbox *ibox = (struct index_mailbox *)box;
 	struct maildir_transaction_context *t;
 
 	t = i_new(struct maildir_transaction_context, 1);
-        index_transaction_init(&t->ictx, ibox, hide);
+	index_transaction_init(&t->ictx, ibox, flags);
 	return &t->ictx.mailbox_ctx;
 }
 



More information about the dovecot-cvs mailing list