dovecot: Added list setting to namespaces to control whether mai...

dovecot at dovecot.org dovecot at dovecot.org
Tue Jun 26 15:44:29 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/c192277a81b3
changeset: 5800:c192277a81b3
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Jun 25 19:24:53 2007 +0300
description:
Added list setting to namespaces to control whether mailboxes in the
namespace are visible with LIST command without giving the namespace prefix
(eg. does LIST "" * show the mailboxes or not)

diffstat:

7 files changed, 27 insertions(+), 7 deletions(-)
dovecot-example.conf             |    4 ++++
src/imap/cmd-list.c              |    9 +++++----
src/lib-storage/mail-namespace.c |   12 +++++++++++-
src/lib-storage/mail-namespace.h |    2 +-
src/master/mail-process.c        |    2 ++
src/master/master-settings.c     |    4 +++-
src/master/master-settings.h     |    1 +

diffs (133 lines):

diff -r 75e3aedc0568 -r c192277a81b3 dovecot-example.conf
--- a/dovecot-example.conf	Mon Jun 25 18:35:17 2007 +0300
+++ b/dovecot-example.conf	Mon Jun 25 19:24:53 2007 +0300
@@ -250,6 +250,10 @@
    # but still keep working. For example you can create hidden namespaces with
    # prefixes "~/mail/", "~%u/mail/" and "mail/".
    #hidden = yes
+
+   # Show the mailboxes under this namespace with LIST command. This makes the
+   # namespace visible for clients that don't support NAMESPACE extension.
+   #list = yes
 #}
 
 # Grant access to these extra groups for mail processes. Typical use would be
diff -r 75e3aedc0568 -r c192277a81b3 src/imap/cmd-list.c
--- a/src/imap/cmd-list.c	Mon Jun 25 18:35:17 2007 +0300
+++ b/src/imap/cmd-list.c	Mon Jun 25 19:24:53 2007 +0300
@@ -308,15 +308,16 @@ list_namespace_init(struct client_comman
 			cur_ns_prefix = t_strndup(cur_ns_prefix, len-1);
 		}
 
-		/* hidden namespaces should still be seen without wildcards.
-		   some clients rely on this. */
-		match = (ns->hidden && list_mask_has_wildcards(cur_mask)) ?
+		/* hidden and non-listable namespaces should still be seen
+		   without wildcards. */
+		match = (!ns->list_prefix &&
+			 list_mask_has_wildcards(cur_mask)) ?
 			IMAP_MATCH_NO : imap_match(ctx->glob, cur_ns_prefix);
 		if (match < 0)
 			return;
 
 		len = strlen(ns->prefix);
-		if (match == IMAP_MATCH_YES &&
+		if (match == IMAP_MATCH_YES && ctx->ns->list_prefix &&
 		    (ctx->list_flags & MAILBOX_LIST_ITER_SUBSCRIBED) == 0 &&
 		    (!ctx->ns->inbox ||
 		     strncmp(ns->prefix, "INBOX", len-1) != 0)) {
diff -r 75e3aedc0568 -r c192277a81b3 src/lib-storage/mail-namespace.c
--- a/src/lib-storage/mail-namespace.c	Mon Jun 25 18:35:17 2007 +0300
+++ b/src/lib-storage/mail-namespace.c	Mon Jun 25 19:24:53 2007 +0300
@@ -40,6 +40,8 @@ namespace_add_env(pool_t pool, const cha
 	ns->inbox = getenv(t_strdup_printf("NAMESPACE_%u_INBOX", num)) != NULL;
 	ns->hidden = getenv(t_strdup_printf("NAMESPACE_%u_HIDDEN",
 					    num)) != NULL;
+	ns->list_prefix = !ns->hidden && *prefix != '\0' &&
+		getenv(t_strdup_printf("NAMESPACE_%u_LIST", num)) != NULL;
 	ns->subscriptions = getenv(t_strdup_printf("NAMESPACE_%u_SUBSCRIPTIONS",
 						   num)) != NULL;
 
@@ -59,10 +61,11 @@ namespace_add_env(pool_t pool, const cha
 
 	if ((flags & MAIL_STORAGE_FLAG_DEBUG) != 0) {
 		i_info("Namespace: type=%s, prefix=%s, sep=%s, "
-		       "inbox=%s, hidden=%s, subscriptions=%s",
+		       "inbox=%s, hidden=%s, list=%s, subscriptions=%s",
 		       type == NULL ? "" : type, prefix, sep == NULL ? "" : sep,
 		       ns->inbox ? "yes" : "no",
 		       ns->hidden ? "yes" : "no",
+		       ns->list ? "yes" : "no",
 		       ns->subscriptions ? "yes" : "no");
 	}
 
@@ -97,6 +100,13 @@ static bool namespaces_check(struct mail
 		if (ns->type == NAMESPACE_PRIVATE) {
 			private_ns = ns;
 			private_ns_count++;
+		}
+		if (ns->list_prefix &&
+		    ns->prefix[strlen(ns->prefix)-1] != ns->sep) {
+			i_error("namespace configuration error: "
+				"list=yes requires prefix=%s "
+				"to end with separator", ns->prefix);
+			return FALSE;
 		}
 	}
 
diff -r 75e3aedc0568 -r c192277a81b3 src/lib-storage/mail-namespace.h
--- a/src/lib-storage/mail-namespace.h	Mon Jun 25 18:35:17 2007 +0300
+++ b/src/lib-storage/mail-namespace.h	Mon Jun 25 19:24:53 2007 +0300
@@ -16,7 +16,7 @@ struct mail_namespace {
 	const char *prefix;
 	size_t prefix_len;
 
-	bool inbox, hidden, subscriptions;
+	bool inbox, hidden, list_prefix, subscriptions;
 	struct mailbox_list *list;
 	/* FIXME: we should support multiple storages in one namespace */
 	struct mail_storage *storage;
diff -r 75e3aedc0568 -r c192277a81b3 src/master/mail-process.c
--- a/src/master/mail-process.c	Mon Jun 25 18:35:17 2007 +0300
+++ b/src/master/mail-process.c	Mon Jun 25 19:24:53 2007 +0300
@@ -193,6 +193,8 @@ env_put_namespace(struct namespace_setti
 			env_put(t_strdup_printf("NAMESPACE_%u_INBOX=1", i));
 		if (ns->hidden)
 			env_put(t_strdup_printf("NAMESPACE_%u_HIDDEN=1", i));
+		else if (ns->list)
+			env_put(t_strdup_printf("NAMESPACE_%u_LIST=1", i));
 		t_pop();
 	}
 }
diff -r 75e3aedc0568 -r c192277a81b3 src/master/master-settings.c
--- a/src/master/master-settings.c	Mon Jun 25 18:35:17 2007 +0300
+++ b/src/master/master-settings.c	Mon Jun 25 19:24:53 2007 +0300
@@ -149,6 +149,7 @@ static struct setting_def namespace_sett
 	DEF_STR(location),
 	DEF_BOOL(inbox),
 	DEF_BOOL(hidden),
+	DEF_BOOL(list),
 
 	{ 0, NULL, 0 }
 };
@@ -332,7 +333,8 @@ struct namespace_settings default_namesp
 	MEMBER(location) "",
 
 	MEMBER(inbox) FALSE,
-	MEMBER(hidden) FALSE
+	MEMBER(hidden) FALSE,
+	MEMBER(list) TRUE
 };
 
 static pool_t settings_pool, settings2_pool;
diff -r 75e3aedc0568 -r c192277a81b3 src/master/master-settings.h
--- a/src/master/master-settings.h	Mon Jun 25 18:35:17 2007 +0300
+++ b/src/master/master-settings.h	Mon Jun 25 19:24:53 2007 +0300
@@ -218,6 +218,7 @@ struct namespace_settings {
 
 	bool inbox;
 	bool hidden;
+	bool list;
 };
 
 struct server_settings {


More information about the dovecot-cvs mailing list