changeset 7189:34057a03a357 HEAD

If mail saving fails, don't try to update cache file (only to have the changes rollbacked).
author Timo Sirainen <tss@iki.fi>
date Fri, 25 Jan 2008 13:44:40 +0200
parents febb2592e616
children b9a9c7257f4e
files src/lib-storage/index/cydir/cydir-save.c src/lib-storage/index/dbox/dbox-save.c src/lib-storage/index/index-mail.c src/lib-storage/index/index-mail.h src/lib-storage/index/maildir/maildir-save.c src/lib-storage/index/mbox/mbox-save.c
diffstat 6 files changed, 22 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/cydir/cydir-save.c	Fri Jan 25 13:36:35 2008 +0200
+++ b/src/lib-storage/index/cydir/cydir-save.c	Fri Jan 25 13:44:40 2008 +0200
@@ -215,7 +215,7 @@
 	}
 
 	index_mail_cache_parse_deinit(ctx->cur_dest_mail,
-				      ctx->cur_received_date);
+				      ctx->cur_received_date, !ctx->failed);
 	i_stream_unref(&ctx->input);
 
 	return ctx->failed ? -1 : 0;
--- a/src/lib-storage/index/dbox/dbox-save.c	Fri Jan 25 13:36:35 2008 +0200
+++ b/src/lib-storage/index/dbox/dbox-save.c	Fri Jan 25 13:44:40 2008 +0200
@@ -231,7 +231,7 @@
 		return -1;
 
 	index_mail_cache_parse_deinit(ctx->cur_dest_mail,
-				      ctx->cur_received_date);
+				      ctx->cur_received_date, !ctx->failed);
 
 	if (!ctx->failed) T_FRAME_BEGIN {
 		const char *cur_path;
--- a/src/lib-storage/index/index-mail.c	Fri Jan 25 13:36:35 2008 +0200
+++ b/src/lib-storage/index/index-mail.c	Fri Jan 25 13:44:40 2008 +0200
@@ -405,8 +405,10 @@
 			return;
 	}
 
-	mail_cache_add(mail->trans->cache_trans, mail->data.seq,
-		       field_idx, data, data_size);
+	if (!mail->data.no_caching) {
+		mail_cache_add(mail->trans->cache_trans, mail->data.seq,
+			       field_idx, data, data_size);
+	}
 }
 
 static void parse_bodystructure_part_header(struct message_part *part,
@@ -1266,10 +1268,17 @@
 	}
 }
 
-void index_mail_cache_parse_deinit(struct mail *_mail, time_t received_date)
+void index_mail_cache_parse_deinit(struct mail *_mail, time_t received_date,
+				   bool success)
 {
 	struct index_mail *mail = (struct index_mail *)_mail;
 
+	if (!success) {
+		/* we're going to delete this mail anyway,
+		   don't bother trying to update cache file */
+		mail->data.no_caching = TRUE;
+	}
+
 	/* This is needed with 0 byte mails to get hdr=NULL call done. */
 	index_mail_cache_parse_continue(_mail);
 
--- a/src/lib-storage/index/index-mail.h	Fri Jan 25 13:36:35 2008 +0200
+++ b/src/lib-storage/index/index-mail.h	Fri Jan 25 13:44:40 2008 +0200
@@ -103,6 +103,7 @@
 	unsigned int body_size_set:1;
 	unsigned int messageparts_saved_to_cache:1;
 	unsigned int header_parsed:1;
+	unsigned int no_caching:1;
 	unsigned int destroying_stream:1;
 };
 
@@ -204,6 +205,7 @@
 struct istream *index_mail_cache_parse_init(struct mail *mail,
 					    struct istream *input);
 void index_mail_cache_parse_continue(struct mail *mail);
-void index_mail_cache_parse_deinit(struct mail *mail, time_t received_date);
+void index_mail_cache_parse_deinit(struct mail *mail, time_t received_date,
+				   bool success);
 
 #endif
--- a/src/lib-storage/index/maildir/maildir-save.c	Fri Jan 25 13:36:35 2008 +0200
+++ b/src/lib-storage/index/maildir/maildir-save.c	Fri Jan 25 13:44:40 2008 +0200
@@ -476,7 +476,7 @@
 
 	if (ctx->cur_dest_mail != NULL) {
 		index_mail_cache_parse_deinit(ctx->cur_dest_mail,
-					      ctx->received_date);
+					      ctx->received_date, !ctx->failed);
 	}
 	i_stream_unref(&ctx->input);
 
--- a/src/lib-storage/index/mbox/mbox-save.c	Fri Jan 25 13:36:35 2008 +0200
+++ b/src/lib-storage/index/mbox/mbox-save.c	Fri Jan 25 13:44:40 2008 +0200
@@ -662,8 +662,10 @@
 		);
 	}
 
-	if (ctx->mail != NULL)
-		index_mail_cache_parse_deinit(ctx->mail, ctx->received_date);
+	if (ctx->mail != NULL) {
+		index_mail_cache_parse_deinit(ctx->mail, ctx->received_date,
+					      !ctx->failed);
+	}
 	if (ctx->input != NULL)
 		i_stream_destroy(&ctx->input);