From: Timo Sirainen Date: Tue, 8 Dec 2009 18:51:49 +0000 (-0500) Subject: imap: Fixed listing namespaces with multiple hierarchy separators. X-Git-Tag: 2.0.beta1~52 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f62114b9566fbe5cf9a8d551429931422aff947d;p=thirdparty%2Fdovecot%2Fcore.git imap: Fixed listing namespaces with multiple hierarchy separators. --HG-- branch : HEAD --- diff --git a/src/imap/cmd-list.c b/src/imap/cmd-list.c index 6ae387588a..47d5b6df1d 100644 --- a/src/imap/cmd-list.c +++ b/src/imap/cmd-list.c @@ -251,6 +251,7 @@ list_namespace_send_prefix(struct cmd_list_context *ctx, bool have_children) enum mailbox_info_flags flags; const char *name; string_t *str; + bool same_ns, ends_with_sep; ctx->cur_ns_send_prefix = FALSE; @@ -261,9 +262,16 @@ list_namespace_send_prefix(struct cmd_list_context *ctx, bool have_children) return; } + name = ns_get_listed_prefix(ctx); len = strlen(ctx->ns->prefix); + ends_with_sep = ctx->ns->prefix[len-1] == ctx->ns->sep; + + /* we may be listing namespace's parent. in such case we always want to + set the name as nonexistent. */ + same_ns = strcmp(name, ctx->ns->prefix) == 0 || + (strncmp(name, ctx->ns->prefix, len - 1) == 0 && ends_with_sep); if (len == 6 && strncasecmp(ctx->ns->prefix, "INBOX", len-1) == 0 && - ctx->ns->prefix[len-1] == ctx->ns->sep) { + ends_with_sep) { /* INBOX namespace needs to be handled specially. */ if (ctx->inbox_found) { /* we're just now going to send it */ @@ -272,14 +280,13 @@ list_namespace_send_prefix(struct cmd_list_context *ctx, bool have_children) ctx->inbox_found = TRUE; flags = list_get_inbox_flags(ctx); - } else if (mailbox_list_mailbox(ctx->ns->list, "", &flags) > 0) { + } else if (same_ns && + mailbox_list_mailbox(ctx->ns->list, "", &flags) > 0) { /* mailbox with namespace prefix exists */ } else { flags = MAILBOX_NONEXISTENT; } - name = ns_get_listed_prefix(ctx); - if ((flags & MAILBOX_CHILDREN) == 0) { if (have_children || list_namespace_has_children(ctx)) { flags |= MAILBOX_CHILDREN;