dovecot-2.2: Added %{fetch_hdr/body_count/bytes} variables to im...

dovecot at dovecot.org dovecot at dovecot.org
Fri May 15 11:37:11 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/93bba97afb2a
changeset: 18706:93bba97afb2a
user:      Timo Sirainen <tss at iki.fi>
date:      Fri May 15 14:35:01 2015 +0300
description:
Added %{fetch_hdr/body_count/bytes} variables to imap_logout_format

diffstat:

 doc/example-config/conf.d/20-imap.conf |   4 ++++
 src/imap/imap-client.c                 |   8 ++++++++
 src/imap/imap-client.h                 |   4 ++++
 src/imap/imap-fetch-body.c             |  21 ++++++++++++++++++++-
 src/imap/imap-fetch.h                  |   1 +
 5 files changed, 37 insertions(+), 1 deletions(-)

diffs (131 lines):

diff -r 4cd9e46e0c78 -r 93bba97afb2a doc/example-config/conf.d/20-imap.conf
--- a/doc/example-config/conf.d/20-imap.conf	Fri May 15 14:34:54 2015 +0300
+++ b/doc/example-config/conf.d/20-imap.conf	Fri May 15 14:35:01 2015 +0300
@@ -10,6 +10,10 @@
 # IMAP logout format string:
 #  %i - total number of bytes read from client
 #  %o - total number of bytes sent to client
+#  %{fetch_hdr_count} - Number of mails with mail header data sent to client
+#  %{fetch_hdr_bytes} - Number of bytes with mail header data sent to client
+#  %{fetch_body_count} - Number of mails with mail body data sent to client
+#  %{fetch_body_bytes} - Number of bytes with mail body data sent to client
 #imap_logout_format = in=%i out=%o
 
 # Override the IMAP CAPABILITY response. If the value begins with '+',
diff -r 4cd9e46e0c78 -r 93bba97afb2a src/imap/imap-client.c
--- a/src/imap/imap-client.c	Fri May 15 14:34:54 2015 +0300
+++ b/src/imap/imap-client.c	Fri May 15 14:35:01 2015 +0300
@@ -217,6 +217,10 @@
 		{ 'i', NULL, "input" },
 		{ 'o', NULL, "output" },
 		{ '\0', NULL, "session" },
+		{ '\0', NULL, "fetch_hdr_count" },
+		{ '\0', NULL, "fetch_hdr_bytes" },
+		{ '\0', NULL, "fetch_body_count" },
+		{ '\0', NULL, "fetch_body_bytes" },
 		{ '\0', NULL, NULL }
 	};
 	struct var_expand_table *tab;
@@ -228,6 +232,10 @@
 	tab[0].value = dec2str(i_stream_get_absolute_offset(client->input));
 	tab[1].value = dec2str(client->output->offset);
 	tab[2].value = client->session_id;
+	tab[3].value = dec2str(client->fetch_hdr_count);
+	tab[4].value = dec2str(client->fetch_hdr_bytes);
+	tab[5].value = dec2str(client->fetch_body_count);
+	tab[6].value = dec2str(client->fetch_body_bytes);
 
 	str = t_str_new(128);
 	var_expand(str, client->set->imap_logout_format, tab);
diff -r 4cd9e46e0c78 -r 93bba97afb2a src/imap/imap-client.h
--- a/src/imap/imap-client.h	Fri May 15 14:34:54 2015 +0300
+++ b/src/imap/imap-client.h	Fri May 15 14:35:01 2015 +0300
@@ -136,6 +136,10 @@
 	uint64_t sync_last_full_modseq;
 	uint64_t highest_fetch_modseq;
 
+	/* For imap_logout_format statistics: */
+	unsigned int fetch_hdr_count, fetch_body_count;
+	uint64_t fetch_hdr_bytes, fetch_body_bytes;
+
 	/* SEARCHRES extension: Last saved SEARCH result */
 	ARRAY_TYPE(seq_range) search_saved_uidset;
 	/* SEARCH=CONTEXT extension: Searches that get updated */
diff -r 4cd9e46e0c78 -r 93bba97afb2a src/imap/imap-fetch-body.c
--- 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);
diff -r 4cd9e46e0c78 -r 93bba97afb2a src/imap/imap-fetch.h
--- a/src/imap/imap-fetch.h	Fri May 15 14:34:54 2015 +0300
+++ b/src/imap/imap-fetch.h	Fri May 15 14:35:01 2015 +0300
@@ -59,6 +59,7 @@
 	struct istream *cur_input;
 	bool skip_cr;
 	int (*cont_handler)(struct imap_fetch_context *ctx);
+	uint64_t *cur_stats_sizep;
 
 	unsigned int fetching:1;
 	unsigned int seen_flags_changed:1;


More information about the dovecot-cvs mailing list