changeset 5980:57b70f64f997 HEAD

Added imap_logout_format setting with default to bytes=%i/%o
author Timo Sirainen <tss@iki.fi>
date Fri, 13 Jul 2007 02:40:47 +0300
parents 433745f10290
children d585d0c65834
files dovecot-example.conf src/imap/client.c src/imap/common.h src/imap/main.c src/master/master-settings-defs.c src/master/master-settings.c src/master/master-settings.h
diffstat 7 files changed, 40 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/dovecot-example.conf	Fri Jul 13 02:37:19 2007 +0300
+++ b/dovecot-example.conf	Fri Jul 13 02:40:47 2007 +0300
@@ -550,6 +550,11 @@
   # Many clients however don't understand it and ask the CAPABILITY anyway.
   #login_greeting_capability = no
 
+  # IMAP logout format string:
+  #  %i - total number of bytes read from client
+  #  %o - total number of bytes sent to client
+  #imap_logout_format = bytes=%i/%o
+
   # Override the IMAP CAPABILITY response.
   #imap_capability = 
 
--- a/src/imap/client.c	Fri Jul 13 02:37:19 2007 +0300
+++ b/src/imap/client.c	Fri Jul 13 02:40:47 2007 +0300
@@ -2,9 +2,11 @@
 
 #include "common.h"
 #include "ioloop.h"
+#include "str.h"
 #include "network.h"
 #include "istream.h"
 #include "ostream.h"
+#include "var-expand.h"
 #include "commands.h"
 #include "mail-namespace.h"
 
@@ -70,6 +72,27 @@
 	}
 }
 
+static const char *client_stats(struct client *client)
+{
+	static struct var_expand_table static_tab[] = {
+		{ 'i', NULL },
+		{ 'o', NULL },
+		{ '\0', NULL }
+	};
+	struct var_expand_table *tab;
+	string_t *str;
+
+	tab = t_malloc(sizeof(static_tab));
+	memcpy(tab, static_tab, sizeof(static_tab));
+
+	tab[0].value = dec2str(client->input->v_offset);
+	tab[1].value = dec2str(client->output->offset);
+
+	str = t_str_new(128);
+	var_expand(str, logout_format, tab);
+	return str_c(str);
+}
+
 void client_destroy(struct client *client, const char *reason)
 {
 	i_assert(!client->destroyed);
@@ -79,7 +102,7 @@
 		client->disconnected = TRUE;
 		if (reason == NULL)
 			reason = "Disconnected";
-		i_info("%s", reason);
+		i_info("%s %s", reason, client_stats(client));
 	}
 
 	i_stream_close(client->input);
@@ -128,7 +151,7 @@
 	if (client->disconnected)
 		return;
 
-	i_info("Disconnected: %s", reason);
+	i_info("Disconnected: %s %s", reason, client_stats(client));
 	client->disconnected = TRUE;
 	(void)o_stream_flush(client->output);
 
--- a/src/imap/common.h	Fri Jul 13 02:37:19 2007 +0300
+++ b/src/imap/common.h	Fri Jul 13 02:40:47 2007 +0300
@@ -34,6 +34,7 @@
 extern unsigned int max_keyword_length;
 extern unsigned int imap_max_line_length;
 extern enum client_workarounds client_workarounds;
+extern const char *logout_format;
 
 extern string_t *capability_string;
 
--- a/src/imap/main.c	Fri Jul 13 02:37:19 2007 +0300
+++ b/src/imap/main.c	Fri Jul 13 02:40:47 2007 +0300
@@ -42,8 +42,9 @@
 unsigned int max_keyword_length;
 unsigned int imap_max_line_length;
 enum client_workarounds client_workarounds = 0;
+const char *logout_format;
+
 static struct io *log_io = NULL;
-
 static struct module *modules = NULL;
 static char log_prefix[128]; /* syslog() needs this to be permanent */
 static pool_t namespace_pool;
@@ -230,6 +231,10 @@
 		(unsigned int)strtoul(str, NULL, 10) :
 		DEFAULT_MAX_KEYWORD_LENGTH;
 
+	logout_format = getenv("IMAP_LOGOUT_FORMAT");
+	if (logout_format == NULL)
+		logout_format = "bytes=%i/%o";
+
         parse_workarounds();
 
 	namespace_pool = pool_alloconly_create("namespaces", 1024);
--- a/src/master/master-settings-defs.c	Fri Jul 13 02:37:19 2007 +0300
+++ b/src/master/master-settings-defs.c	Fri Jul 13 02:40:47 2007 +0300
@@ -111,6 +111,7 @@
 	DEF_INT(imap_max_line_length),
 	DEF_STR(imap_capability),
 	DEF_STR(imap_client_workarounds),
+	DEF_STR(imap_logout_format),
 
 	/* pop3 */
 	DEF_BOOL(pop3_no_flag_updates),
--- a/src/master/master-settings.c	Fri Jul 13 02:37:19 2007 +0300
+++ b/src/master/master-settings.c	Fri Jul 13 02:40:47 2007 +0300
@@ -267,6 +267,7 @@
 	MEMBER(imap_max_line_length) 65536,
 	MEMBER(imap_capability) "",
 	MEMBER(imap_client_workarounds) "outlook-idle",
+	MEMBER(imap_logout_format) "bytes=%i/%o",
 
 	/* pop3 */
 	MEMBER(pop3_no_flag_updates) FALSE,
--- a/src/master/master-settings.h	Fri Jul 13 02:37:19 2007 +0300
+++ b/src/master/master-settings.h	Fri Jul 13 02:40:47 2007 +0300
@@ -123,6 +123,7 @@
 	unsigned int imap_max_line_length;
 	const char *imap_capability;
 	const char *imap_client_workarounds;
+	const char *imap_logout_format;
 
 	/* pop3 */
 	bool pop3_no_flag_updates;