dovecot: Make sure all listable namespaces use the same separato...

dovecot at dovecot.org dovecot at dovecot.org
Wed Jun 27 16:38:21 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/8416f66ac5ab
changeset: 5802:8416f66ac5ab
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Jun 27 15:17:58 2007 +0300
description:
Make sure all listable namespaces use the same separator. If there's no ref
or "" namespace, use that separator instead of INBOX's.

diffstat:

3 files changed, 36 insertions(+), 13 deletions(-)
src/imap/cmd-list.c              |   24 +++++++++++-------------
src/lib-storage/mail-namespace.c |   23 +++++++++++++++++++++++
src/lib-storage/mail-namespace.h |    2 ++

diffs (118 lines):

diff -r 3d14f363f921 -r 8416f66ac5ab src/imap/cmd-list.c
--- a/src/imap/cmd-list.c	Tue Jun 26 15:44:21 2007 +0300
+++ b/src/imap/cmd-list.c	Wed Jun 27 15:17:58 2007 +0300
@@ -430,29 +430,27 @@ static void cmd_list_ref_root(struct cli
 {
 	struct mail_namespace *ns;
 	const char *ns_prefix;
+	char ns_sep;
 	string_t *str;
 
 	/* Special request to return the hierarchy delimiter and mailbox root
 	   name. If namespace has a prefix, it's returned as the mailbox root.
 	   Otherwise we'll emulate UW-IMAP behavior. */
 	ns = mail_namespace_find_visible(client->namespaces, &ref);
-	if (ns != NULL)
+	if (ns != NULL) {
 		ns_prefix = ns->prefix;
-	else {
+		ns_sep = ns->sep;
+	} else {
 		ns_prefix = "";
-		ns = mail_namespace_find(client->namespaces, &ns_prefix);
-		if (ns == NULL) {
-			/* we must reply something. use INBOX namespace's
-			   separator. */
-			const char *inbox = "INBOX";
-
-			ns = mail_namespace_find(client->namespaces, &inbox);
-		}
+		ns_sep = mail_namespace_get_root_sep(client->namespaces);
 	}
 
 	str = t_str_new(64);
-	str_printfa(str, "* LIST (\\Noselect) \"%s\" ", ns->sep_str);
-	if (*ns_prefix != '\0' && !ns->hidden) {
+	str_append(str, "* LIST (\\Noselect) \"");
+	if (ns_sep == '\\' || ns_sep == '"')
+		str_append_c(str, '\\');
+	str_printfa(str, "%c\" ", ns_sep);
+	if (*ns_prefix != '\0') {
 		/* non-hidden namespace, use it as the root name */
 		imap_quote_append_string(str, ns_prefix, FALSE);
 	} else {
@@ -460,7 +458,7 @@ static void cmd_list_ref_root(struct cli
 		   return an empty root name, but it's safer to emulate what
 		   UW-IMAP does. With full filesystem access this might even
 		   matter (root of "~user/mail/" is "~user/", not "") */
-		const char *p = strchr(ref, ns->sep);
+		const char *p = strchr(ref, ns_sep);
 
 		if (p == NULL)
 			str_append(str, "\"\"");
diff -r 3d14f363f921 -r 8416f66ac5ab src/lib-storage/mail-namespace.c
--- a/src/lib-storage/mail-namespace.c	Tue Jun 26 15:44:21 2007 +0300
+++ b/src/lib-storage/mail-namespace.c	Wed Jun 27 15:17:58 2007 +0300
@@ -86,6 +86,7 @@ static bool namespaces_check(struct mail
 {
 	struct mail_namespace *ns, *inbox_ns = NULL, *private_ns = NULL;
 	unsigned int private_ns_count = 0;
+	char list_sep = '\0';
 
 	for (ns = namespaces; ns != NULL; ns = ns->next) {
 		if (ns->inbox) {
@@ -108,6 +109,16 @@ static bool namespaces_check(struct mail
 				"to end with separator", ns->prefix);
 			return FALSE;
 		}
+		if (ns->list_prefix) {
+			if (list_sep == '\0')
+				list_sep = ns->sep;
+			else if (list_sep != ns->sep) {
+				i_error("namespace configuration error: "
+					"All list=yes namespaces must use "
+					"the same separator");
+				return FALSE;
+			}
+		}
 	}
 
 	if (inbox_ns == NULL) {
@@ -121,6 +132,11 @@ static bool namespaces_check(struct mail
 			return FALSE;
 		}
 	}
+	if (list_sep == '\0') {
+		i_error("namespace configuration error: "
+			"no list=yes namespaces");
+		return FALSE;
+	}
 	return TRUE;
 }
 
@@ -233,6 +249,13 @@ const char *mail_namespace_fix_sep(struc
 			*p = ns->real_sep;
 	}
 	return ret;
+}
+
+char mail_namespace_get_root_sep(struct mail_namespace *namespaces)
+{
+	while (!namespaces->list_prefix)
+		namespaces = namespaces->next;
+	return namespaces->sep;
 }
 
 static struct mail_namespace *
diff -r 3d14f363f921 -r 8416f66ac5ab src/lib-storage/mail-namespace.h
--- a/src/lib-storage/mail-namespace.h	Tue Jun 26 15:44:21 2007 +0300
+++ b/src/lib-storage/mail-namespace.h	Wed Jun 27 15:17:58 2007 +0300
@@ -29,6 +29,8 @@ void mail_namespaces_deinit(struct mail_
 
 /* Update hierarchy separators in given name to real_sep characters. */
 const char *mail_namespace_fix_sep(struct mail_namespace *ns, const char *name);
+/* Returns the hierarchy separator for mailboxes that are listed at root. */
+char mail_namespace_get_root_sep(struct mail_namespace *namespaces);
 
 /* Returns namespace based on the mailbox name's prefix. Updates mailbox to
    be a valid name inside the namespace (prefix is skipped, hierarchy separator


More information about the dovecot-cvs mailing list