dovecot-2.0: mbox: Don't write garbage to mbox if message doesn'...

dovecot at dovecot.org dovecot at dovecot.org
Thu Jun 25 20:25:53 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/d8556f68f6a7
changeset: 9528:d8556f68f6a7
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Jun 24 16:54:06 2009 -0400
description:
mbox: Don't write garbage to mbox if message doesn't have a body.

diffstat:

1 file changed, 20 insertions(+), 6 deletions(-)
src/lib-storage/index/mbox/mbox-save.c |   26 ++++++++++++++++++++------

diffs (57 lines):

diff -r a1535b151afa -r d8556f68f6a7 src/lib-storage/index/mbox/mbox-save.c
--- a/src/lib-storage/index/mbox/mbox-save.c	Wed Jun 24 16:42:15 2009 -0400
+++ b/src/lib-storage/index/mbox/mbox-save.c	Wed Jun 24 16:54:06 2009 -0400
@@ -139,6 +139,8 @@ static int mbox_write_content_length(str
 	const char *str;
 	size_t len;
 
+	i_assert(ctx->eoh_offset != (uoff_t)-1);
+
 	if (ctx->mbox->mbox_writeonly) {
 		/* we can't seek, don't set Content-Length */
 		return 0;
@@ -549,6 +551,19 @@ static int mbox_save_body(struct mbox_sa
 	return 0;
 }
 
+static int mbox_save_finish_headers(struct mbox_save_context *ctx)
+{
+	i_assert(ctx->eoh_offset == (uoff_t)-1);
+
+	/* append our own headers and ending empty line */
+	ctx->extra_hdr_offset = ctx->output->offset;
+	if (o_stream_send(ctx->output, str_data(ctx->headers),
+			  str_len(ctx->headers)) < 0)
+		return write_error(ctx);
+	ctx->eoh_offset = ctx->output->offset;
+	return 0;
+}
+
 int mbox_save_continue(struct mail_save_context *_ctx)
 {
 	struct mbox_save_context *ctx = (struct mbox_save_context *)_ctx;
@@ -624,12 +639,8 @@ int mbox_save_continue(struct mail_save_
 				      hdr_md5_sum, NULL);
 	}
 
-	/* append our own headers and ending empty line */
-	ctx->extra_hdr_offset = ctx->output->offset;
-	if (o_stream_send(ctx->output, str_data(ctx->headers),
-			  str_len(ctx->headers)) < 0)
-		return write_error(ctx);
-	ctx->eoh_offset = ctx->output->offset;
+	if (mbox_save_finish_headers(ctx) < 0)
+		return -1;
 
 	/* write body */
 	if (mbox_save_body_input(ctx) < 0)
@@ -640,6 +651,9 @@ int mbox_save_finish(struct mail_save_co
 int mbox_save_finish(struct mail_save_context *_ctx)
 {
 	struct mbox_save_context *ctx = (struct mbox_save_context *)_ctx;
+
+	if (!ctx->failed && ctx->eoh_offset == (uoff_t)-1)
+		(void)mbox_save_finish_headers(ctx);
 
 	if (ctx->output != NULL) {
 		/* make sure everything is written */


More information about the dovecot-cvs mailing list