dovecot: If mail saving fails, don't try to update cache file (o...

dovecot at dovecot.org dovecot at dovecot.org
Fri Jan 25 13:44:44 EET 2008


details:   http://hg.dovecot.org/dovecot/rev/34057a03a357
changeset: 7189:34057a03a357
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jan 25 13:44:40 2008 +0200
description:
If mail saving fails, don't try to update cache file (only to have the
changes rollbacked).

diffstat:

6 files changed, 24 insertions(+), 11 deletions(-)
src/lib-storage/index/cydir/cydir-save.c     |    2 +-
src/lib-storage/index/dbox/dbox-save.c       |    2 +-
src/lib-storage/index/index-mail.c           |   19 ++++++++++++++-----
src/lib-storage/index/index-mail.h           |    4 +++-
src/lib-storage/index/maildir/maildir-save.c |    2 +-
src/lib-storage/index/mbox/mbox-save.c       |    6 ++++--

diffs (108 lines):

diff -r febb2592e616 -r 34057a03a357 src/lib-storage/index/cydir/cydir-save.c
--- 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 @@ int cydir_save_finish(struct mail_save_c
 	}
 
 	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;
diff -r febb2592e616 -r 34057a03a357 src/lib-storage/index/dbox/dbox-save.c
--- 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 @@ int dbox_save_finish(struct mail_save_co
 		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;
diff -r febb2592e616 -r 34057a03a357 src/lib-storage/index/index-mail.c
--- 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 @@ void index_mail_cache_add_idx(struct ind
 			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,9 +1268,16 @@ void index_mail_cache_parse_continue(str
 	}
 }
 
-void index_mail_cache_parse_deinit(struct mail *_mail, time_t received_date)
-{
-	struct index_mail *mail = (struct index_mail *)_mail;
+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);
diff -r febb2592e616 -r 34057a03a357 src/lib-storage/index/index-mail.h
--- 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 @@ struct index_mail_data {
 	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_i
 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
diff -r febb2592e616 -r 34057a03a357 src/lib-storage/index/maildir/maildir-save.c
--- 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 @@ static int maildir_save_finish_real(stru
 
 	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);
 
diff -r febb2592e616 -r 34057a03a357 src/lib-storage/index/mbox/mbox-save.c
--- 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 @@ int mbox_save_finish(struct mail_save_co
 		);
 	}
 
-	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);
 


More information about the dovecot-cvs mailing list