Mercurial > dovecot > original-hg > dovecot-1.2
changeset 5802:8416f66ac5ab HEAD
Make sure all listable namespaces use the same separator. If there's no ref
or "" namespace, use that separator instead of INBOX's.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 27 Jun 2007 15:17:58 +0300 |
parents | 3d14f363f921 |
children | 6ae0dc6dc3b3 |
files | src/imap/cmd-list.c src/lib-storage/mail-namespace.c src/lib-storage/mail-namespace.h |
diffstat | 3 files changed, 36 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ { 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 @@ 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, "\"\"");
--- 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 @@ { 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 @@ "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 @@ return FALSE; } } + if (list_sep == '\0') { + i_error("namespace configuration error: " + "no list=yes namespaces"); + return FALSE; + } return TRUE; } @@ -235,6 +251,13 @@ 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 * mail_namespace_find_int(struct mail_namespace *namespaces, const char **mailbox, bool show_hidden)
--- 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 @@ /* 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