dovecot-2.0: imap: imap_capability = +foo only adds new capabili...

dovecot at dovecot.org dovecot at dovecot.org
Mon Aug 2 18:25:28 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/ac31be20d279
changeset: 11919:ac31be20d279
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Aug 02 16:25:19 2010 +0100
description:
imap: imap_capability = +foo only adds new capabilities instead of replacing everything.

diffstat:

 doc/example-config/conf.d/20-imap.conf |   3 ++-
 src/imap-login/client-authenticate.c   |   6 +-----
 src/imap-login/client-authenticate.h   |   2 +-
 src/imap-login/client.c                |  27 ++++++++++++++++++---------
 src/imap/imap-client.c                 |  12 ++++++++++--
 5 files changed, 32 insertions(+), 18 deletions(-)

diffs (111 lines):

diff -r 59af5fd42221 -r ac31be20d279 doc/example-config/conf.d/20-imap.conf
--- a/doc/example-config/conf.d/20-imap.conf	Mon Aug 02 15:33:00 2010 +0100
+++ b/doc/example-config/conf.d/20-imap.conf	Mon Aug 02 16:25:19 2010 +0100
@@ -20,7 +20,8 @@
   #  %o - total number of bytes sent to client
   #imap_logout_format = bytes=%i/%o
 
-  # Override the IMAP CAPABILITY response.
+  # Override the IMAP CAPABILITY response. If the value begins with '+',
+  # add the given capabilities on top of the defaults (e.g. +XFOO XBAR).
   #imap_capability = 
 
   # How long to wait between "OK Still here" notifications when client is
diff -r 59af5fd42221 -r ac31be20d279 src/imap-login/client-authenticate.c
--- a/src/imap-login/client-authenticate.c	Mon Aug 02 15:33:00 2010 +0100
+++ b/src/imap-login/client-authenticate.c	Mon Aug 02 16:25:19 2010 +0100
@@ -18,21 +18,17 @@
 
 #include <stdlib.h>
 
-const char *client_authenticate_get_capabilities(struct client *client)
+void client_authenticate_get_capabilities(struct client *client, string_t *str)
 {
 	const struct auth_mech_desc *mech;
 	unsigned int i, count;
-	string_t *str;
 
-	str = t_str_new(128);
 	mech = sasl_server_get_advertised_mechs(client, &count);
 	for (i = 0; i < count; i++) {
 		str_append_c(str, ' ');
 		str_append(str, "AUTH=");
 		str_append(str, mech[i].name);
 	}
-
-	return str_c(str);
 }
 
 bool imap_client_auth_handle_reply(struct client *client,
diff -r 59af5fd42221 -r ac31be20d279 src/imap-login/client-authenticate.h
--- a/src/imap-login/client-authenticate.h	Mon Aug 02 15:33:00 2010 +0100
+++ b/src/imap-login/client-authenticate.h	Mon Aug 02 16:25:19 2010 +0100
@@ -3,7 +3,7 @@
 
 struct imap_arg;
 
-const char *client_authenticate_get_capabilities(struct client *client);
+void client_authenticate_get_capabilities(struct client *client, string_t *str);
 
 bool imap_client_auth_handle_reply(struct client *client,
 				   const struct client_auth_reply *reply);
diff -r 59af5fd42221 -r ac31be20d279 src/imap-login/client.c
--- a/src/imap-login/client.c	Mon Aug 02 15:33:00 2010 +0100
+++ b/src/imap-login/client.c	Mon Aug 02 16:25:19 2010 +0100
@@ -62,16 +62,25 @@
 static const char *get_capability(struct client *client)
 {
 	struct imap_client *imap_client = (struct imap_client *)client;
-	const char *auths, *cap_str;
+	string_t *cap_str = t_str_new(256);
 
-	cap_str = *imap_client->set->imap_capability != '\0' ?
-		imap_client->set->imap_capability : CAPABILITY_BANNER_STRING;
-	auths = client_authenticate_get_capabilities(client);
-	return t_strconcat(cap_str,
-			   (ssl_initialized && !client->tls) ? " STARTTLS" : "",
-			   client->set->disable_plaintext_auth &&
-			   !client->secured ? " LOGINDISABLED" : "",
-			   auths, NULL);
+	if (*imap_client->set->imap_capability == '\0')
+		str_append(cap_str, CAPABILITY_BANNER_STRING);
+	else if (*imap_client->set->imap_capability != '+')
+		str_append(cap_str, imap_client->set->imap_capability);
+	else {
+		str_append(cap_str, CAPABILITY_BANNER_STRING);
+		str_append_c(cap_str, ' ');
+		str_append(cap_str, imap_client->set->imap_capability + 1);
+	}
+
+	if (ssl_initialized && !client->tls)
+		str_append(cap_str, " STARTTLS");
+	if (client->set->disable_plaintext_auth && !client->secured)
+		str_append(cap_str, " LOGINDISABLED");
+
+	client_authenticate_get_capabilities(client, cap_str);
+	return str_c(cap_str);
 }
 
 static int cmd_capability(struct imap_client *imap_client)
diff -r 59af5fd42221 -r ac31be20d279 src/imap/imap-client.c
--- a/src/imap/imap-client.c	Mon Aug 02 15:33:00 2010 +0100
+++ b/src/imap/imap-client.c	Mon Aug 02 16:25:19 2010 +0100
@@ -72,8 +72,16 @@
 
 	client->capability_string =
 		str_new(client->pool, sizeof(CAPABILITY_STRING)+64);
-	str_append(client->capability_string, *set->imap_capability != '\0' ?
-		   set->imap_capability : CAPABILITY_STRING);
+
+	if (*set->imap_capability == '\0')
+		str_append(client->capability_string, CAPABILITY_STRING);
+	else if (*set->imap_capability != '+')
+		str_append(client->capability_string, set->imap_capability);
+	else {
+		str_append(client->capability_string, CAPABILITY_STRING);
+		str_append_c(client->capability_string, ' ');
+		str_append(client->capability_string, set->imap_capability + 1);
+	}
 
 	ident = mail_user_get_anvil_userip_ident(client->user);
 	if (ident != NULL) {


More information about the dovecot-cvs mailing list