dovecot-1.2: mailbox_save_init() API was split to multiple funct...

dovecot at dovecot.org dovecot at dovecot.org
Thu Aug 7 21:05:56 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/8a068f879cd1
changeset: 8075:8a068f879cd1
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Aug 07 14:05:47 2008 -0400
description:
mailbox_save_init() API was split to multiple functions.
This allows adding more parameters easily in future.

diffstat:

21 files changed, 303 insertions(+), 275 deletions(-)
src/imap/cmd-append.c                           |    8 +-
src/lib-storage/index/cydir/cydir-save.c        |   80 +++++++++-----------
src/lib-storage/index/cydir/cydir-storage.c     |    3 
src/lib-storage/index/cydir/cydir-storage.h     |    8 --
src/lib-storage/index/dbox/dbox-save.c          |   90 ++++++++++-------------
src/lib-storage/index/dbox/dbox-storage.c       |    3 
src/lib-storage/index/dbox/dbox-storage.h       |    8 --
src/lib-storage/index/maildir/maildir-save.c    |   57 +++++++-------
src/lib-storage/index/maildir/maildir-storage.c |    3 
src/lib-storage/index/maildir/maildir-storage.h |    9 --
src/lib-storage/index/mbox/mbox-save.c          |   85 +++++++++++----------
src/lib-storage/index/mbox/mbox-storage.c       |    3 
src/lib-storage/index/mbox/mbox-storage.h       |    8 --
src/lib-storage/index/raw/raw-storage.c         |    1 
src/lib-storage/mail-copy.c                     |    9 +-
src/lib-storage/mail-storage-private.h          |   18 ++--
src/lib-storage/mail-storage.c                  |   68 +++++++++++++----
src/lib-storage/mail-storage.h                  |   43 ++++++----
src/plugins/acl/acl-mailbox.c                   |   30 +++----
src/plugins/quota/quota-storage.c               |   24 ++----
src/plugins/virtual/virtual-storage.c           |   20 -----

diffs (truncated from 1102 to 300 lines):

diff -r 05565bfadc6b -r 8a068f879cd1 src/imap/cmd-append.c
--- a/src/imap/cmd-append.c	Thu Aug 07 13:50:18 2008 -0400
+++ b/src/imap/cmd-append.c	Thu Aug 07 14:05:47 2008 -0400
@@ -327,9 +327,11 @@ static bool cmd_append_continue_parsing(
 
 	/* save the mail */
 	ctx->input = i_stream_create_limit(client->input, ctx->msg_size);
-	ret = mailbox_save_init(ctx->t, flags, keywords,
-				internal_date, timezone_offset, NULL,
-				ctx->input, FALSE, &ctx->save_ctx);
+	ctx->save_ctx = mailbox_save_alloc(ctx->t);
+	mailbox_save_set_flags(ctx->save_ctx, flags, keywords);
+	mailbox_save_set_received_date(ctx->save_ctx,
+				       internal_date, timezone_offset);
+	ret = mailbox_save_begin(&ctx->save_ctx, ctx->input);
 
 	if (keywords != NULL)
 		mailbox_keywords_free(ctx->box, &keywords);
diff -r 05565bfadc6b -r 8a068f879cd1 src/lib-storage/index/cydir/cydir-save.c
--- a/src/lib-storage/index/cydir/cydir-save.c	Thu Aug 07 13:50:18 2008 -0400
+++ b/src/lib-storage/index/cydir/cydir-save.c	Thu Aug 07 14:05:47 2008 -0400
@@ -28,8 +28,7 @@ struct cydir_save_context {
 	uint32_t seq;
 	struct istream *input;
 	struct ostream *output;
-	struct mail *mail, *cur_dest_mail;
-	time_t cur_received_date;
+	struct mail *mail;
 	int fd;
 
 	unsigned int failed:1;
@@ -57,29 +56,33 @@ cydir_get_save_path(struct cydir_save_co
 	return t_strdup_printf("%s/%s.%u", dir, ctx->tmp_basename, num);
 }
 
-int cydir_save_init(struct mailbox_transaction_context *_t,
-		    enum mail_flags flags, struct mail_keywords *keywords,
-		    time_t received_date, int timezone_offset ATTR_UNUSED,
-		    const char *from_envelope ATTR_UNUSED,
-		    struct istream *input, struct mail **dest_mail,
-		    struct mail_save_context **ctx_r)
+struct mail_save_context *
+cydir_save_alloc(struct mailbox_transaction_context *_t)
 {
 	struct cydir_transaction_context *t =
 		(struct cydir_transaction_context *)_t;
 	struct cydir_mailbox *mbox = (struct cydir_mailbox *)t->ictx.ibox;
 	struct cydir_save_context *ctx = t->save_ctx;
+
+	i_assert((t->ictx.flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0);
+
+	if (t->save_ctx != NULL)
+		return &t->save_ctx->ctx;
+
+	ctx = t->save_ctx = i_new(struct cydir_save_context, 1);
+	ctx->ctx.transaction = &t->ictx.mailbox_ctx;
+	ctx->mbox = mbox;
+	ctx->trans = t->ictx.trans;
+	ctx->tmp_basename = cydir_generate_tmp_filename();
+	return &ctx->ctx;
+}
+
+int cydir_save_begin(struct mail_save_context *_ctx, struct istream *input)
+{
+	struct cydir_save_context *ctx = (struct cydir_save_context *)_ctx;
+	struct mailbox_transaction_context *trans = _ctx->transaction;
 	enum mail_flags save_flags;
 	struct istream *crlf_input;
-
-	i_assert((t->ictx.flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0);
-
-	if (ctx == NULL) {
-		ctx = t->save_ctx = i_new(struct cydir_save_context, 1);
-		ctx->ctx.transaction = &t->ictx.mailbox_ctx;
-		ctx->mbox = mbox;
-		ctx->trans = t->ictx.trans;
-		ctx->tmp_basename = cydir_generate_tmp_filename();
-	}
 
 	T_BEGIN {
 		const char *path;
@@ -91,7 +94,7 @@ int cydir_save_init(struct mailbox_trans
 				o_stream_create_fd_file(ctx->fd, 0, FALSE);
 			o_stream_cork(ctx->output);
 		} else {
-			mail_storage_set_critical(_t->box->storage,
+			mail_storage_set_critical(trans->box->storage,
 						  "open(%s) failed: %m", path);
 			ctx->failed = TRUE;
 		}
@@ -100,30 +103,25 @@ int cydir_save_init(struct mailbox_trans
 		return -1;
 
 	/* add to index */
-	save_flags = flags & ~MAIL_RECENT;
+	save_flags = _ctx->flags & ~MAIL_RECENT;
 	mail_index_append(ctx->trans, 0, &ctx->seq);
 	mail_index_update_flags(ctx->trans, ctx->seq, MODIFY_REPLACE,
 				save_flags);
-	if (keywords != NULL) {
+	if (_ctx->keywords != NULL) {
 		mail_index_update_keywords(ctx->trans, ctx->seq,
-					   MODIFY_REPLACE, keywords);
-	}
-
-	if (*dest_mail == NULL) {
+					   MODIFY_REPLACE, _ctx->keywords);
+	}
+
+	if (_ctx->dest_mail == NULL) {
 		if (ctx->mail == NULL)
-			ctx->mail = mail_alloc(_t, 0, NULL);
-		*dest_mail = ctx->mail;
-	}
-	mail_set_seq(*dest_mail, ctx->seq);
+			ctx->mail = mail_alloc(trans, 0, NULL);
+		_ctx->dest_mail = ctx->mail;
+	}
+	mail_set_seq(_ctx->dest_mail, ctx->seq);
 
 	crlf_input = i_stream_create_crlf(input);
-	ctx->input = index_mail_cache_parse_init(*dest_mail, crlf_input);
+	ctx->input = index_mail_cache_parse_init(_ctx->dest_mail, crlf_input);
 	i_stream_unref(&crlf_input);
-
-	ctx->cur_dest_mail = *dest_mail;
-	ctx->cur_received_date = received_date;
-
-	*ctx_r = &ctx->ctx;
 	return ctx->failed ? -1 : 0;
 }
 
@@ -145,7 +143,7 @@ int cydir_save_continue(struct mail_save
 			ctx->failed = TRUE;
 			return -1;
 		}
-		index_mail_cache_parse_continue(ctx->cur_dest_mail);
+		index_mail_cache_parse_continue(_ctx->dest_mail);
 
 		/* both tee input readers may consume data from our primary
 		   input stream. we'll have to make sure we don't return with
@@ -177,9 +175,9 @@ int cydir_save_finish(struct mail_save_c
 		}
 	}
 
-	if (ctx->cur_received_date == (time_t)-1) {
+	if (_ctx->received_date == (time_t)-1) {
 		if (fstat(ctx->fd, &st) == 0)
-			ctx->cur_received_date = st.st_mtime;
+			_ctx->received_date = st.st_mtime;
 		else {
 			mail_storage_set_critical(storage,
 						  "fstat(%s) failed: %m", path);
@@ -189,7 +187,7 @@ int cydir_save_finish(struct mail_save_c
 		struct utimbuf ut;
 
 		ut.actime = ioloop_time;
-		ut.modtime = ctx->cur_received_date;
+		ut.modtime = _ctx->received_date;
 		if (utime(path, &ut) < 0) {
 			mail_storage_set_critical(storage,
 						  "utime(%s) failed: %m", path);
@@ -214,8 +212,8 @@ int cydir_save_finish(struct mail_save_c
 		}
 	}
 
-	index_mail_cache_parse_deinit(ctx->cur_dest_mail,
-				      ctx->cur_received_date, !ctx->failed);
+	index_mail_cache_parse_deinit(_ctx->dest_mail,
+				      _ctx->received_date, !ctx->failed);
 	i_stream_unref(&ctx->input);
 
 	return ctx->failed ? -1 : 0;
diff -r 05565bfadc6b -r 8a068f879cd1 src/lib-storage/index/cydir/cydir-storage.c
--- a/src/lib-storage/index/cydir/cydir-storage.c	Thu Aug 07 13:50:18 2008 -0400
+++ b/src/lib-storage/index/cydir/cydir-storage.c	Thu Aug 07 14:05:47 2008 -0400
@@ -453,7 +453,8 @@ struct mailbox cydir_mailbox = {
 		index_storage_search_deinit,
 		index_storage_search_next_nonblock,
 		index_storage_search_next_update_seq,
-		cydir_save_init,
+		cydir_save_alloc,
+		cydir_save_begin,
 		cydir_save_continue,
 		cydir_save_finish,
 		cydir_save_cancel,
diff -r 05565bfadc6b -r 8a068f879cd1 src/lib-storage/index/cydir/cydir-storage.h
--- a/src/lib-storage/index/cydir/cydir-storage.h	Thu Aug 07 13:50:18 2008 -0400
+++ b/src/lib-storage/index/cydir/cydir-storage.h	Thu Aug 07 14:05:47 2008 -0400
@@ -33,11 +33,9 @@ void cydir_transaction_class_init(void);
 void cydir_transaction_class_init(void);
 void cydir_transaction_class_deinit(void);
 
-int cydir_save_init(struct mailbox_transaction_context *_t,
-		    enum mail_flags flags, struct mail_keywords *keywords,
-		    time_t received_date, int timezone_offset,
-		    const char *from_envelope, struct istream *input,
-		    struct mail **dest_mail, struct mail_save_context **ctx_r);
+struct mail_save_context *
+cydir_save_alloc(struct mailbox_transaction_context *_t);
+int cydir_save_begin(struct mail_save_context *ctx, struct istream *input);
 int cydir_save_continue(struct mail_save_context *ctx);
 int cydir_save_finish(struct mail_save_context *ctx);
 void cydir_save_cancel(struct mail_save_context *ctx);
diff -r 05565bfadc6b -r 8a068f879cd1 src/lib-storage/index/dbox/dbox-save.c
--- a/src/lib-storage/index/dbox/dbox-save.c	Thu Aug 07 13:50:18 2008 -0400
+++ b/src/lib-storage/index/dbox/dbox-save.c	Thu Aug 07 14:05:47 2008 -0400
@@ -36,9 +36,7 @@ struct dbox_save_context {
 	/* updated for each appended mail: */
 	uint32_t seq;
 	struct istream *input;
-	struct mail *mail, *cur_dest_mail;
-	time_t cur_received_date;
-	enum mail_flags cur_flags;
+	struct mail *mail;
 	string_t *cur_keywords;
 
 	struct dbox_file *cur_file;
@@ -61,17 +59,31 @@ static void dbox_save_keywords(struct db
 					   keywords);
 }
 
-int dbox_save_init(struct mailbox_transaction_context *_t,
-		   enum mail_flags flags, struct mail_keywords *keywords,
-		   time_t received_date, int timezone_offset ATTR_UNUSED,
-		   const char *from_envelope ATTR_UNUSED,
-		   struct istream *input, struct mail **dest_mail,
-		   struct mail_save_context **ctx_r)
+struct mail_save_context *
+dbox_save_alloc(struct mailbox_transaction_context *_t)
 {
 	struct dbox_transaction_context *t =
 		(struct dbox_transaction_context *)_t;
 	struct dbox_mailbox *mbox = (struct dbox_mailbox *)t->ictx.ibox;
-	struct dbox_save_context *ctx = t->save_ctx;
+	struct dbox_save_context *ctx;
+
+	i_assert((t->ictx.flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0);
+
+	if (t->save_ctx != NULL)
+		return &t->save_ctx->ctx;
+
+	ctx = t->save_ctx = i_new(struct dbox_save_context, 1);
+	ctx->ctx.transaction = &t->ictx.mailbox_ctx;
+	ctx->mbox = mbox;
+	ctx->trans = t->ictx.trans;
+	ctx->append_ctx = dbox_index_append_begin(mbox->dbox_index);
+	i_array_init(&ctx->mails, 32);
+	return &ctx->ctx;
+}
+
+int dbox_save_begin(struct mail_save_context *_ctx, struct istream *input)
+{
+	struct dbox_save_context *ctx = (struct dbox_save_context *)_ctx;
 	struct dbox_message_header dbox_msg_hdr;
 	struct dbox_save_mail *save_mail;
 	struct istream *crlf_input;
@@ -79,17 +91,6 @@ int dbox_save_init(struct mailbox_transa
 	const struct stat *st;
 	uoff_t mail_size;
 
-	i_assert((t->ictx.flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0);
-
-	if (ctx == NULL) {
-		ctx = t->save_ctx = i_new(struct dbox_save_context, 1);
-		ctx->ctx.transaction = &t->ictx.mailbox_ctx;
-		ctx->mbox = mbox;
-		ctx->trans = t->ictx.trans;
-		ctx->append_ctx = dbox_index_append_begin(mbox->dbox_index);
-		i_array_init(&ctx->mails, 32);
-	}
-
 	/* get the size of the mail to be saved, if possible */
 	st = i_stream_stat(input, TRUE);
 	mail_size = st == NULL || st->st_size == -1 ? 0 : st->st_size;
@@ -101,26 +102,24 @@ int dbox_save_init(struct mailbox_transa
 	}
 
 	/* add to index */
-	save_flags = flags & ~MAIL_RECENT;
+	save_flags = _ctx->flags & ~MAIL_RECENT;
 	mail_index_append(ctx->trans, 0, &ctx->seq);
 	mail_index_update_flags(ctx->trans, ctx->seq, MODIFY_REPLACE,
 				save_flags);
-	if (keywords != NULL) {
+	if (_ctx->keywords != NULL) {
 		mail_index_update_keywords(ctx->trans, ctx->seq,
-					   MODIFY_REPLACE, keywords);
-	}
-
-	if (*dest_mail == NULL) {
+					   MODIFY_REPLACE, _ctx->keywords);
+	}
+
+	if (_ctx->dest_mail == NULL) {
 		if (ctx->mail == NULL)
-			ctx->mail = mail_alloc(_t, 0, NULL);
-		*dest_mail = ctx->mail;
-	}
-	mail_set_seq(*dest_mail, ctx->seq);


More information about the dovecot-cvs mailing list