dovecot-1.1: mbox: Don't write garbage to mbox if message doesn'...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Jun 24 23:55:12 EEST 2009
details: http://hg.dovecot.org/dovecot-1.1/rev/9d337f24fd0e
changeset: 8315:9d337f24fd0e
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 7ef77d3def36 -r 9d337f24fd0e src/lib-storage/index/mbox/mbox-save.c
--- a/src/lib-storage/index/mbox/mbox-save.c Wed Jun 24 14:20:11 2009 -0400
+++ b/src/lib-storage/index/mbox/mbox-save.c Wed Jun 24 16:54:06 2009 -0400
@@ -156,6 +156,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;
@@ -562,6 +564,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;
@@ -637,12 +652,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)
@@ -653,6 +664,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