changeset 370:b0a62e264b22 HEAD

Write Content-Length header for rewritten messages.
author Timo Sirainen <tss@iki.fi>
date Sun, 06 Oct 2002 12:34:54 +0300
parents d037915978ca
children 3ac9badb73ba
files src/lib-index/mbox/mbox-rewrite.c
diffstat 1 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mbox/mbox-rewrite.c	Sun Oct 06 12:20:20 2002 +0300
+++ b/src/lib-index/mbox/mbox-rewrite.c	Sun Oct 06 12:34:54 2002 +0300
@@ -18,6 +18,7 @@
 	IOBuffer *outbuf;
 	int failed;
 
+	uoff_t content_length;
 	unsigned int seq;
 	unsigned int msg_flags;
         const char **custom_flags;
@@ -29,6 +30,7 @@
 	unsigned int xkeywords_found:1;
 	unsigned int status_found:1;
 	unsigned int xstatus_found:1;
+	unsigned int content_length_found:1;
 } MboxRewriteContext;
 
 /* Remove dirty flag from all messages */
@@ -172,6 +174,18 @@
 	return TRUE;
 }
 
+static int mbox_write_content_length(MboxRewriteContext *ctx)
+{
+	char str[MAX_LARGEST_T_STRLEN+30];
+
+	i_snprintf(str, sizeof(str), "Content-Length: %"PRIuUOFF_T"\n",
+		   ctx->content_length);
+
+	if (io_buffer_send(ctx->outbuf, str, strlen(str)) < 0)
+		return FALSE;
+	return TRUE;
+}
+
 static const char *strip_chars(const char *value, size_t value_len,
 			       const char *list)
 {
@@ -254,6 +268,10 @@
 			ctx->ximapbase_found = TRUE;
 			(void)mbox_write_ximapbase(ctx);
 		}
+	} else if (name_len == 14 &&
+		   strncasecmp(name, "Content-Length", 14) == 0) {
+		ctx->content_length_found = TRUE;
+		(void)mbox_write_content_length(ctx);
 	} else if (name_len > 0) {
 		/* save this header */
 		(void)io_buffer_send(ctx->outbuf, name, name_len);
@@ -298,6 +316,7 @@
 	memset(&ctx, 0, sizeof(ctx));
 	ctx.outbuf = outbuf;
 	ctx.seq = seq;
+	ctx.content_length = rec->body_size;
 	ctx.msg_flags = rec->msg_flags;
 	ctx.uid_validity = index->header->uid_validity-1;
 	ctx.custom_flags = mail_custom_flags_list_get(index->custom_flags);
@@ -320,6 +339,8 @@
 		(void)mbox_write_status(&ctx, NULL);
 	if (!ctx.xstatus_found)
 		(void)mbox_write_xstatus(&ctx, NULL);
+	if (!ctx.content_length_found)
+		(void)mbox_write_content_length(&ctx);
 
 	t_pop();