dovecot-2.2: lib-storage: Moved per-mail data in struct mail_sav...

dovecot at dovecot.org dovecot at dovecot.org
Thu Aug 23 11:54:57 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/b966759dd48c
changeset: 14952:b966759dd48c
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Aug 23 11:54:46 2012 +0300
description:
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
This fixes previous save leaking metadata to the next save.

diffstat:

 src/lib-storage/index/cydir/cydir-save.c       |  28 ++++----
 src/lib-storage/index/dbox-common/dbox-save.c  |  49 ++++++++-------
 src/lib-storage/index/dbox-multi/mdbox-save.c  |   6 +-
 src/lib-storage/index/dbox-single/sdbox-copy.c |   2 +-
 src/lib-storage/index/dbox-single/sdbox-save.c |   8 +-
 src/lib-storage/index/imapc/imapc-save.c       |  25 ++++---
 src/lib-storage/index/index-attachment.c       |  82 ++++++++++++++-----------
 src/lib-storage/index/index-mail.c             |   5 +-
 src/lib-storage/index/index-storage.c          |   7 +-
 src/lib-storage/index/maildir/maildir-save.c   |  73 +++++++++++-----------
 src/lib-storage/index/mbox/mbox-save.c         |  29 ++++----
 src/lib-storage/mail-copy.c                    |  10 +-
 src/lib-storage/mail-storage-private.h         |  15 +++-
 src/lib-storage/mail-storage.c                 |  42 ++++++------
 src/plugins/acl/acl-mailbox.c                  |   4 +-
 src/plugins/lazy-expunge/lazy-expunge-plugin.c |   2 +-
 src/plugins/virtual/virtual-save.c             |  15 ++--
 src/plugins/zlib/zlib-plugin.c                 |   8 +-
 18 files changed, 216 insertions(+), 194 deletions(-)

diffs (truncated from 1180 to 300 lines):

diff -r d0441efd0efc -r b966759dd48c src/lib-storage/index/cydir/cydir-save.c
--- a/src/lib-storage/index/cydir/cydir-save.c	Thu Aug 23 11:26:13 2012 +0300
+++ b/src/lib-storage/index/cydir/cydir-save.c	Thu Aug 23 11:54:46 2012 +0300
@@ -90,9 +90,9 @@
 		path = cydir_get_save_path(ctx, ctx->mail_count);
 		ctx->fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0660);
 		if (ctx->fd != -1) {
-			_ctx->output =
+			_ctx->data.output =
 				o_stream_create_fd_file(ctx->fd, 0, FALSE);
-			o_stream_cork(_ctx->output);
+			o_stream_cork(_ctx->data.output);
 		} else {
 			mail_storage_set_critical(trans->box->storage,
 						  "open(%s) failed: %m", path);
@@ -103,17 +103,17 @@
 		return -1;
 
 	/* add to index */
-	save_flags = _ctx->flags & ~MAIL_RECENT;
+	save_flags = _ctx->data.flags & ~MAIL_RECENT;
 	mail_index_append(ctx->trans, 0, &ctx->seq);
 	mail_index_update_flags(ctx->trans, ctx->seq, MODIFY_REPLACE,
 				save_flags);
-	if (_ctx->keywords != NULL) {
+	if (_ctx->data.keywords != NULL) {
 		mail_index_update_keywords(ctx->trans, ctx->seq,
-					   MODIFY_REPLACE, _ctx->keywords);
+					   MODIFY_REPLACE, _ctx->data.keywords);
 	}
-	if (_ctx->min_modseq != 0) {
+	if (_ctx->data.min_modseq != 0) {
 		mail_index_update_modseq(ctx->trans, ctx->seq,
-					 _ctx->min_modseq);
+					 _ctx->data.min_modseq);
 	}
 
 	if (_ctx->dest_mail == NULL) {
@@ -138,7 +138,7 @@
 		return -1;
 
 	do {
-		if (o_stream_send_istream(_ctx->output, ctx->input) < 0) {
+		if (o_stream_send_istream(_ctx->data.output, ctx->input) < 0) {
 			if (!mail_storage_set_error_from_errno(storage)) {
 				mail_storage_set_critical(storage,
 					"write(%s) failed: %m",
@@ -162,7 +162,7 @@
 	struct stat st;
 	int ret = 0;
 
-	if (o_stream_nfinish(ctx->ctx.output) < 0) {
+	if (o_stream_nfinish(ctx->ctx.data.output) < 0) {
 		mail_storage_set_critical(storage, "write(%s) failed: %m", path);
 		ret = -1;
 	}
@@ -175,9 +175,9 @@
 		}
 	}
 
-	if (ctx->ctx.received_date == (time_t)-1) {
+	if (ctx->ctx.data.received_date == (time_t)-1) {
 		if (fstat(ctx->fd, &st) == 0)
-			ctx->ctx.received_date = st.st_mtime;
+			ctx->ctx.data.received_date = st.st_mtime;
 		else {
 			mail_storage_set_critical(storage,
 						  "fstat(%s) failed: %m", path);
@@ -187,7 +187,7 @@
 		struct utimbuf ut;
 
 		ut.actime = ioloop_time;
-		ut.modtime = ctx->ctx.received_date;
+		ut.modtime = ctx->ctx.data.received_date;
 		if (utime(path, &ut) < 0) {
 			mail_storage_set_critical(storage,
 						  "utime(%s) failed: %m", path);
@@ -195,7 +195,7 @@
 		}
 	}
 
-	o_stream_destroy(&ctx->ctx.output);
+	o_stream_destroy(&ctx->ctx.data.output);
 	if (close(ctx->fd) < 0) {
 		mail_storage_set_critical(storage,
 					  "close(%s) failed: %m", path);
@@ -227,7 +227,7 @@
 	}
 
 	index_mail_cache_parse_deinit(_ctx->dest_mail,
-				      _ctx->received_date, !ctx->failed);
+				      _ctx->data.received_date, !ctx->failed);
 	if (ctx->input != NULL)
 		i_stream_unref(&ctx->input);
 
diff -r d0441efd0efc -r b966759dd48c src/lib-storage/index/dbox-common/dbox-save.c
--- a/src/lib-storage/index/dbox-common/dbox-save.c	Thu Aug 23 11:26:13 2012 +0300
+++ b/src/lib-storage/index/dbox-common/dbox-save.c	Thu Aug 23 11:54:46 2012 +0300
@@ -13,19 +13,20 @@
 
 void dbox_save_add_to_index(struct dbox_save_context *ctx)
 {
+	struct mail_save_data *mdata = &ctx->ctx.data;
 	enum mail_flags save_flags;
 
-	save_flags = ctx->ctx.flags & ~MAIL_RECENT;
-	mail_index_append(ctx->trans, ctx->ctx.uid, &ctx->seq);
+	save_flags = mdata->flags & ~MAIL_RECENT;
+	mail_index_append(ctx->trans, mdata->uid, &ctx->seq);
 	mail_index_update_flags(ctx->trans, ctx->seq, MODIFY_REPLACE,
 				save_flags);
-	if (ctx->ctx.keywords != NULL) {
+	if (mdata->keywords != NULL) {
 		mail_index_update_keywords(ctx->trans, ctx->seq,
-					   MODIFY_REPLACE, ctx->ctx.keywords);
+					   MODIFY_REPLACE, mdata->keywords);
 	}
-	if (ctx->ctx.min_modseq != 0) {
+	if (mdata->min_modseq != 0) {
 		mail_index_update_modseq(ctx->trans, ctx->seq,
-					 ctx->ctx.min_modseq);
+					 mdata->min_modseq);
 	}
 }
 
@@ -59,10 +60,10 @@
 					  o_stream_get_name(ctx->dbox_output));
 		ctx->failed = TRUE;
 	}
-	_ctx->output = ctx->dbox_output;
+	_ctx->data.output = ctx->dbox_output;
 
-	if (_ctx->received_date == (time_t)-1)
-		_ctx->received_date = ioloop_time;
+	if (_ctx->data.received_date == (time_t)-1)
+		_ctx->data.received_date = ioloop_time;
 	index_attachment_save_begin(_ctx, storage->attachment_fs, ctx->input);
 }
 
@@ -74,15 +75,15 @@
 	if (ctx->failed)
 		return -1;
 
-	if (_ctx->attach != NULL)
+	if (_ctx->data.attach != NULL)
 		return index_attachment_save_continue(_ctx);
 
 	do {
-		if (o_stream_send_istream(_ctx->output, ctx->input) < 0) {
+		if (o_stream_send_istream(_ctx->data.output, ctx->input) < 0) {
 			if (!mail_storage_set_error_from_errno(storage)) {
 				mail_storage_set_critical(storage,
 					"write(%s) failed: %m",
-					o_stream_get_name(_ctx->output));
+					o_stream_get_name(_ctx->data.output));
 			}
 			ctx->failed = TRUE;
 			return -1;
@@ -98,25 +99,26 @@
 
 void dbox_save_end(struct dbox_save_context *ctx)
 {
+	struct mail_save_data *mdata = &ctx->ctx.data;
 	struct ostream *dbox_output = ctx->dbox_output;
 
-	if (ctx->ctx.attach != NULL) {
+	if (mdata->attach != NULL) {
 		if (index_attachment_save_finish(&ctx->ctx) < 0)
 			ctx->failed = TRUE;
 	}
-	if (o_stream_nfinish(ctx->ctx.output) < 0) {
+	if (o_stream_nfinish(mdata->output) < 0) {
 		mail_storage_set_critical(ctx->ctx.transaction->box->storage,
 					  "write(%s) failed: %m",
-					  o_stream_get_name(ctx->ctx.output));
+					  o_stream_get_name(mdata->output));
 		ctx->failed = TRUE;
 	}
-	if (ctx->ctx.output == dbox_output)
+	if (mdata->output == dbox_output)
 		return;
 
 	/* e.g. zlib plugin had changed this */
 	o_stream_ref(dbox_output);
-	o_stream_destroy(&ctx->ctx.output);
-	ctx->ctx.output = dbox_output;
+	o_stream_destroy(&mdata->output);
+	mdata->output = dbox_output;
 }
 
 void dbox_save_write_metadata(struct mail_save_context *_ctx,
@@ -125,6 +127,7 @@
 			      guid_128_t guid_128)
 {
 	struct dbox_save_context *ctx = (struct dbox_save_context *)_ctx;
+	struct mail_save_data *mdata = &ctx->ctx.data;
 	struct dbox_metadata_header metadata_hdr;
 	const char *guid;
 	string_t *str;
@@ -145,18 +148,18 @@
 			    (unsigned long long)ctx->input->v_offset);
 	}
 	str_printfa(str, "%c%lx\n", DBOX_METADATA_RECEIVED_TIME,
-		    (unsigned long)_ctx->received_date);
+		    (unsigned long)mdata->received_date);
 	if (mail_get_virtual_size(_ctx->dest_mail, &vsize) < 0)
 		i_unreached();
 	str_printfa(str, "%c%llx\n", DBOX_METADATA_VIRTUAL_SIZE,
 		    (unsigned long long)vsize);
-	if (_ctx->pop3_uidl != NULL) {
-		i_assert(strchr(_ctx->pop3_uidl, '\n') == NULL);
+	if (mdata->pop3_uidl != NULL) {
+		i_assert(strchr(mdata->pop3_uidl, '\n') == NULL);
 		str_printfa(str, "%c%s\n", DBOX_METADATA_POP3_UIDL,
-			    _ctx->pop3_uidl);
+			    mdata->pop3_uidl);
 	}
 
-	guid = _ctx->guid;
+	guid = mdata->guid;
 	if (guid != NULL)
 		mail_generate_guid_128_hash(guid, guid_128);
 	else {
diff -r d0441efd0efc -r b966759dd48c src/lib-storage/index/dbox-multi/mdbox-save.c
--- a/src/lib-storage/index/dbox-multi/mdbox-save.c	Thu Aug 23 11:26:13 2012 +0300
+++ b/src/lib-storage/index/dbox-multi/mdbox-save.c	Thu Aug 23 11:54:46 2012 +0300
@@ -199,8 +199,8 @@
 		return -1;
 
 	dbox_save_end(&ctx->ctx);
-	index_mail_cache_parse_deinit(_ctx->dest_mail,
-				      _ctx->received_date, !ctx->ctx.failed);
+	index_mail_cache_parse_deinit(_ctx->dest_mail, _ctx->data.received_date,
+				      !ctx->ctx.failed);
 
 	mail = array_idx_modifiable(&ctx->mails, array_count(&ctx->mails) - 1);
 	if (!ctx->ctx.failed) T_BEGIN {
@@ -421,7 +421,7 @@
 
 	if (mail->box->storage != _ctx->transaction->box->storage ||
 	    _ctx->transaction->box->disable_reflink_copy_to ||
-	    _ctx->guid != NULL)
+	    _ctx->data.guid != NULL)
 		return mail_storage_copy(_ctx, mail);
 	src_mbox = (struct mdbox_mailbox *)mail->box;
 
diff -r d0441efd0efc -r b966759dd48c src/lib-storage/index/dbox-single/sdbox-copy.c
--- a/src/lib-storage/index/dbox-single/sdbox-copy.c	Thu Aug 23 11:26:13 2012 +0300
+++ b/src/lib-storage/index/dbox-single/sdbox-copy.c	Thu Aug 23 11:54:46 2012 +0300
@@ -150,7 +150,7 @@
 
 	ctx->finished = TRUE;
 	if (mail_storage_copy_can_use_hardlink(mail->box, &mbox->box) &&
-	    _ctx->guid == NULL) {
+	    _ctx->data.guid == NULL) {
 		T_BEGIN {
 			ret = sdbox_copy_hardlink(_ctx, mail);
 		} T_END;
diff -r d0441efd0efc -r b966759dd48c src/lib-storage/index/dbox-single/sdbox-save.c
--- a/src/lib-storage/index/dbox-single/sdbox-save.c	Thu Aug 23 11:26:13 2012 +0300
+++ b/src/lib-storage/index/dbox-single/sdbox-save.c	Thu Aug 23 11:54:46 2012 +0300
@@ -174,16 +174,16 @@
 	if (ctx->ctx.dbox_output == NULL)
 		return -1;
 
-	if (_ctx->save_date != (time_t)-1) {
+	if (_ctx->data.save_date != (time_t)-1) {
 		/* we can't change ctime, but we can add the date to cache */
 		struct index_mail *mail = (struct index_mail *)_ctx->dest_mail;
-		uint32_t t = _ctx->save_date;
+		uint32_t t = _ctx->data.save_date;
 
 		index_mail_cache_add(mail, MAIL_CACHE_SAVE_DATE, &t, sizeof(t));
 	}
 
-	index_mail_cache_parse_deinit(_ctx->dest_mail,
-				      _ctx->received_date, !ctx->ctx.failed);
+	index_mail_cache_parse_deinit(_ctx->dest_mail, _ctx->data.received_date,
+				      !ctx->ctx.failed);
 
 	files = array_idx_modifiable(&ctx->files, array_count(&ctx->files) - 1);
 
diff -r d0441efd0efc -r b966759dd48c src/lib-storage/index/imapc/imapc-save.c
--- a/src/lib-storage/index/imapc/imapc-save.c	Thu Aug 23 11:26:13 2012 +0300
+++ b/src/lib-storage/index/imapc/imapc-save.c	Thu Aug 23 11:54:46 2012 +0300
@@ -79,8 +79,8 @@
 	ctx->finished = FALSE;
 	ctx->temp_path = i_strdup(path);
 	ctx->input = i_stream_create_crlf(input);
-	_ctx->output = o_stream_create_fd_file(ctx->fd, 0, FALSE);
-	o_stream_cork(_ctx->output);
+	_ctx->data.output = o_stream_create_fd_file(ctx->fd, 0, FALSE);
+	o_stream_cork(_ctx->data.output);
 	return 0;
 }
 
@@ -92,7 +92,7 @@
 	if (ctx->failed)
 		return -1;
 


More information about the dovecot-cvs mailing list