changeset 4462:de27599764c1 HEAD

Messages' received time wasn't saved properly when saving/copying multiple messages at a time. Also if using quota plugin the S= size was only set for the first saved file, and even that was wrong.
author Timo Sirainen <tss@iki.fi>
date Sat, 01 Jul 2006 21:33:04 +0300
parents ce727f4e53e5
children 193f524562ca
files src/lib-storage/index/maildir/maildir-save.c
diffstat 1 files changed, 16 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/maildir/maildir-save.c	Sat Jul 01 20:53:55 2006 +0300
+++ b/src/lib-storage/index/maildir/maildir-save.c	Sat Jul 01 21:33:04 2006 +0300
@@ -41,7 +41,7 @@
 	struct mail *mail, *cur_dest_mail;
 
 	const char *tmpdir, *newdir, *curdir;
-	struct maildir_filename *files, **files_tail;
+	struct maildir_filename *files, **files_tail, *file_last;
 
 	buffer_t *keywords_buffer;
 	ARRAY_TYPE(keyword_indexes) keywords_array;
@@ -152,8 +152,8 @@
 	mf->flags = flags;
 	mf->size = (uoff_t)-1;
 
-	if (*ctx->files_tail != NULL)
-		(*ctx->files_tail)->next = mf;
+	ctx->file_last = mf;
+	i_assert(*ctx->files_tail == NULL);
 	*ctx->files_tail = mf;
 	ctx->files_tail = &mf->next;
 
@@ -348,7 +348,7 @@
 		mail_storage_set_critical(STORAGE(ctx->mbox->storage),
 			"o_stream_send_istream(%s) failed: %m",
 			t_strconcat(ctx->tmpdir, "/",
-				    ctx->files->basename, NULL));
+				    ctx->file_last->basename, NULL));
 		ctx->failed = TRUE;
 		return -1;
 	}
@@ -375,10 +375,10 @@
 	}
 
 	/* remember the size in case we want to add it to filename */
-	ctx->files->size = ctx->output->offset;
+	ctx->file_last->size = ctx->output->offset;
 
 	t_push();
-	path = t_strconcat(ctx->tmpdir, "/", ctx->files->basename, NULL);
+	path = t_strconcat(ctx->tmpdir, "/", ctx->file_last->basename, NULL);
 
 	if (ctx->received_date != (time_t)-1) {
 		/* set the received_date by modifying mtime */
@@ -410,6 +410,8 @@
 	ctx->fd = -1;
 
 	if (ctx->failed) {
+		struct maildir_filename **fm;
+
 		/* delete the tmp file */
 		if (unlink(path) < 0 && errno != ENOENT) {
 			mail_storage_set_critical(STORAGE(ctx->mbox->storage),
@@ -425,12 +427,19 @@
 				"write(%s) failed: %m", ctx->mbox->path);
 		}
 
-		ctx->files = ctx->files->next;
+		/* remove from the linked list */
+		for (fm = &ctx->files; (*fm)->next != NULL; fm = &(*fm)->next) ;
+		i_assert(*fm == ctx->file_last);
+		*fm = NULL;
+		ctx->files_tail = fm;
+		ctx->file_last = NULL;
+
 		t_pop();
 		return -1;
 	}
 	t_pop();
 
+	ctx->file_last = NULL;
 	return 0;
 }