diff src/imap/imap-fetch-body.c @ 18706:93bba97afb2a

Added %{fetch_hdr/body_count/bytes} variables to imap_logout_format
author Timo Sirainen <tss@iki.fi>
date Fri, 15 May 2015 14:35:01 +0300
parents 8c49fb6d789b
children 1044c55fb4ef
line wrap: on
line diff
--- a/src/imap/imap-fetch-body.c	Fri May 15 14:34:54 2015 +0300
+++ b/src/imap/imap-fetch-body.c	Fri May 15 14:35:01 2015 +0300
@@ -99,8 +99,11 @@
 	ret = o_stream_send_istream(ctx->client->output, state->cur_input);
 	o_stream_set_max_buffer_size(ctx->client->output, (size_t)-1);
 
-	if (ret > 0)
+	if (ret > 0) {
 		state->cur_offset += ret;
+		if (ctx->state.cur_stats_sizep != NULL)
+			*ctx->state.cur_stats_sizep += ret;
+	}
 
 	if (state->cur_offset != state->cur_size) {
 		/* unfinished */
@@ -160,6 +163,18 @@
 	return p_strdup(pool, str_c(str));
 }
 
+static void fetch_state_update_stats(struct imap_fetch_context *ctx,
+				     const struct imap_msgpart *msgpart)
+{
+	if (!imap_msgpart_contains_body(msgpart)) {
+		ctx->client->fetch_hdr_count++;
+		ctx->state.cur_stats_sizep = &ctx->client->fetch_hdr_bytes;
+	} else {
+		ctx->client->fetch_body_count++;
+		ctx->state.cur_stats_sizep = &ctx->client->fetch_body_bytes;
+	}
+}
+
 static int fetch_body_msgpart(struct imap_fetch_context *ctx, struct mail *mail,
 			      struct imap_fetch_body_data *body)
 {
@@ -178,6 +193,7 @@
 	ctx->state.cur_size_field = result.size_field;
 	ctx->state.cur_human_name = get_body_human_name(ctx->ctx_pool, body);
 
+	fetch_state_update_stats(ctx, body->msgpart);
 	str = get_prefix(&ctx->state, body, ctx->state.cur_size,
 			 result.binary_decoded_input_has_nuls);
 	o_stream_nsend(ctx->client->output, str_data(str), str_len(str));
@@ -487,6 +503,7 @@
 		str++; ctx->state.cur_first = FALSE;
 	}
 	o_stream_nsend_str(ctx->client->output, str);
+	fetch_state_update_stats(ctx, msgpart);
 
 	ctx->state.cur_human_name = "RFC822";
 	return ctx->state.cont_handler(ctx);
@@ -509,6 +526,7 @@
 		str++; ctx->state.cur_first = FALSE;
 	}
 	o_stream_nsend_str(ctx->client->output, str);
+	fetch_state_update_stats(ctx, msgpart);
 
 	ctx->state.cur_human_name = "RFC822.HEADER";
 	return ctx->state.cont_handler(ctx);
@@ -531,6 +549,7 @@
 		str++; ctx->state.cur_first = FALSE;
 	}
 	o_stream_nsend_str(ctx->client->output, str);
+	fetch_state_update_stats(ctx, msgpart);
 
 	ctx->state.cur_human_name = "RFC822.TEXT";
 	return ctx->state.cont_handler(ctx);