changeset 8808:a05a7a73b475 HEAD

Maildir and Cydir: When saving mail, expose ostream to mail_save_context.output. This would allow plugins to hook into it.
author Timo Sirainen <tss@iki.fi>
date Mon, 09 Mar 2009 21:52:42 -0400
parents 2a3fd0d46bc6
children 8081eb6b1c61
files src/lib-storage/index/cydir/cydir-save.c src/lib-storage/index/maildir/maildir-save.c src/lib-storage/mail-storage-private.h
diffstat 3 files changed, 15 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/cydir/cydir-save.c	Mon Mar 09 21:00:48 2009 -0400
+++ b/src/lib-storage/index/cydir/cydir-save.c	Mon Mar 09 21:52:42 2009 -0400
@@ -27,7 +27,6 @@
 	/* updated for each appended mail: */
 	uint32_t seq;
 	struct istream *input;
-	struct ostream *output;
 	struct mail *mail;
 	int fd;
 
@@ -90,9 +89,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->output =
 				o_stream_create_fd_file(ctx->fd, 0, FALSE);
-			o_stream_cork(ctx->output);
+			o_stream_cork(_ctx->output);
 		} else {
 			mail_storage_set_critical(trans->box->storage,
 						  "open(%s) failed: %m", path);
@@ -134,7 +133,7 @@
 		return -1;
 
 	do {
-		if (o_stream_send_istream(ctx->output, ctx->input) < 0) {
+		if (o_stream_send_istream(_ctx->output, ctx->input) < 0) {
 			if (!mail_storage_set_error_from_errno(storage)) {
 				mail_storage_set_critical(storage,
 					"o_stream_send_istream(%s) failed: %m",
@@ -161,7 +160,7 @@
 
 	ctx->finished = TRUE;
 
-	if (o_stream_flush(ctx->output) < 0) {
+	if (o_stream_flush(_ctx->output) < 0) {
 		mail_storage_set_critical(storage,
 			"o_stream_flush(%s) failed: %m", path);
 		ctx->failed = TRUE;
@@ -195,7 +194,7 @@
 		}
 	}
 
-	o_stream_destroy(&ctx->output);
+	o_stream_destroy(&_ctx->output);
 	if (close(ctx->fd) < 0) {
 		mail_storage_set_critical(storage,
 					  "close(%s) failed: %m", path);
--- a/src/lib-storage/index/maildir/maildir-save.c	Mon Mar 09 21:00:48 2009 -0400
+++ b/src/lib-storage/index/maildir/maildir-save.c	Mon Mar 09 21:52:42 2009 -0400
@@ -52,7 +52,6 @@
 	ARRAY_TYPE(keyword_indexes) keywords_array;
 
 	struct istream *input;
-	struct ostream *output;
 	int fd;
 	uint32_t first_seq, seq;
 
@@ -389,8 +388,8 @@
 	} T_END;
 
 	if (!ctx->failed) {
-		ctx->output = o_stream_create_fd_file(ctx->fd, 0, FALSE);
-		o_stream_cork(ctx->output);
+		_ctx->output = o_stream_create_fd_file(ctx->fd, 0, FALSE);
+		o_stream_cork(_ctx->output);
 	}
 	return ctx->failed ? -1 : 0;
 }
@@ -404,7 +403,7 @@
 		return -1;
 
 	do {
-		if (o_stream_send_istream(ctx->output, ctx->input) < 0) {
+		if (o_stream_send_istream(_ctx->output, ctx->input) < 0) {
 			if (!mail_storage_set_error_from_errno(storage)) {
 				mail_storage_set_critical(storage,
 					"o_stream_send_istream(%s/%s) "
@@ -440,7 +439,7 @@
 	}
 
 	path = t_strconcat(ctx->tmpdir, "/", ctx->file_last->basename, NULL);
-	if (o_stream_flush(ctx->output) < 0) {
+	if (o_stream_flush(_ctx->output) < 0) {
 		if (!mail_storage_set_error_from_errno(storage)) {
 			mail_storage_set_critical(storage,
 				"o_stream_flush(%s) failed: %m", path);
@@ -485,14 +484,14 @@
 	i_stream_unref(&ctx->input);
 
 	/* remember the size in case we want to add it to filename */
-	ctx->file_last->size = ctx->output->offset;
+	ctx->file_last->size = _ctx->output->offset;
 	if (ctx->cur_dest_mail == NULL ||
 	    mail_get_virtual_size(ctx->cur_dest_mail,
 				  &ctx->file_last->vsize) < 0)
 		ctx->file_last->vsize = (uoff_t)-1;
 
-	output_errno = ctx->output->stream_errno;
-	o_stream_destroy(&ctx->output);
+	output_errno = _ctx->output->stream_errno;
+	o_stream_destroy(&_ctx->output);
 
 	if (!ctx->mbox->ibox.fsync_disable && !ctx->failed) {
 		if (fsync(ctx->fd) < 0) {
@@ -672,7 +671,7 @@
 	bool newdir, new_changed, cur_changed;
 	int ret;
 
-	i_assert(ctx->output == NULL);
+	i_assert(ctx->ctx.output == NULL);
 	i_assert(ctx->finished);
 
 	sync_flags = MAILDIR_UIDLIST_SYNC_PARTIAL |
@@ -819,7 +818,7 @@
 	size_t dir_len;
 	bool hardlinks = FALSE;
 
-	i_assert(ctx->output == NULL);
+	i_assert(ctx->ctx.output == NULL);
 
 	if (!ctx->finished)
 		maildir_save_cancel(&ctx->ctx);
--- a/src/lib-storage/mail-storage-private.h	Mon Mar 09 21:00:48 2009 -0400
+++ b/src/lib-storage/mail-storage-private.h	Mon Mar 09 21:52:42 2009 -0400
@@ -341,6 +341,7 @@
 	int received_tz_offset;
 
 	char *guid, *from_envelope;
+	struct ostream *output;
 };
 
 struct mailbox_sync_context {