Mercurial > dovecot > original-hg > dovecot-1.2
changeset 3856:b97de2e354bd HEAD
Fixes to handling namespace prefixes.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 12 Jan 2006 21:43:30 +0200 |
parents | 8ce85fb481aa |
children | d3342c78ed44 |
files | src/imap/cmd-list.c |
diffstat | 1 files changed, 46 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/imap/cmd-list.c Thu Jan 12 12:54:27 2006 +0200 +++ b/src/imap/cmd-list.c Thu Jan 12 21:43:30 2006 +0200 @@ -92,6 +92,20 @@ return TRUE; } +static void +list_namespace_inbox(struct client *client, struct cmd_list_context *ctx) +{ + const char *str; + + if (!ctx->inbox_found && ctx->ns->inbox && ctx->match_inbox && + (ctx->list_flags & MAILBOX_LIST_SUBSCRIBED) == 0) { + /* INBOX always exists */ + str = t_strdup_printf("* LIST (\\Unmarked) \"%s\" \"INBOX\"", + ctx->ns->sep_str); + client_send_line(client, str); + } +} + static int list_namespace_mailboxes(struct client *client, struct cmd_list_context *ctx) { @@ -100,8 +114,10 @@ string_t *str, *name_str; int ret; - if (ctx->list_ctx == NULL) + if (ctx->list_ctx == NULL) { + list_namespace_inbox(client, ctx); return 1; + } t_push(); str = t_str_new(256); @@ -147,14 +163,7 @@ } } - if (!ctx->inbox_found && ctx->ns->inbox && ctx->match_inbox && - (ctx->list_flags & MAILBOX_LIST_SUBSCRIBED) == 0) { - /* INBOX always exists */ - str_truncate(str, 0); - str_printfa(str, "* LIST (\\Unmarked) \"%s\" \"INBOX\"", - ctx->ns->sep_str); - client_send_line(client, str_c(str)); - } + list_namespace_inbox(client, ctx); t_pop(); ret = mail_storage_mailbox_list_deinit(ctx->list_ctx); @@ -164,17 +173,28 @@ static void skip_prefix(const char **prefix, const char **mask, int inbox) { - size_t mask_len, prefix_len, len; + size_t mask_len, prefix_len; + int match; prefix_len = strlen(*prefix); mask_len = strlen(*mask); - len = I_MIN(prefix_len, mask_len); + + if (mask_len < prefix_len) { + /* eg. namespace prefix = "INBOX.", mask = "INBOX" */ + return; + } - if (strncmp(*prefix, *mask, len) == 0 || - (inbox && len >= 6 && - strncasecmp(*prefix, *mask, 6) == 0)) { - *prefix += len; - *mask += len; + match = strncmp(*prefix, *mask, prefix_len) == 0; + if (!match && inbox) { + /* try INBOX check. */ + match = prefix_len >= 5 && + strncasecmp(*prefix, *mask, 5) == 0 && + strncmp(*prefix + 5, *mask + 5, prefix_len - 5) == 0; + } + + if (match) { + *prefix += prefix_len; + *mask += prefix_len; } } @@ -205,12 +225,13 @@ } if (*cur_ref == '\0' && *cur_prefix != '\0') { + /* no reference parameter. skip namespace prefix from mask. */ skip_prefix(&cur_prefix, &cur_mask, ctx->inbox && cur_ref == ctx->ref); } ctx->glob = imap_match_init(cmd->pool, ctx->mask, - ctx->inbox && cur_ref == ctx->ref, ns->sep); + cur_ref == ctx->ref, ns->sep); if (*cur_ref != '\0' || *cur_prefix == '\0') match = IMAP_MATCH_CHILDREN; @@ -246,6 +267,8 @@ } } + ctx->match_inbox = imap_match(ctx->glob, "INBOX") == IMAP_MATCH_YES; + if (match < 0) return; @@ -281,8 +304,6 @@ } } - ctx->match_inbox = imap_match(ctx->glob, "INBOX") == IMAP_MATCH_YES; - if (*cur_mask != '*' || strcmp(ctx->mask, "*") == 0) { /* a) we don't have '*' in mask b) we want to display everything @@ -405,15 +426,19 @@ } client_send_tagline(cmd, "OK List completed."); } else { + const char *inbox_arg; + ctx = p_new(cmd->pool, struct cmd_list_context, 1); ctx->ref = ref; ctx->mask = mask; ctx->list_flags = list_flags; ctx->lsub = lsub; - ctx->inbox = strncasecmp(ref, "INBOX", 5) == 0 || - (*ref == '\0' && strncasecmp(mask, "INBOX", 5) == 0); ctx->ns = client->namespaces; + inbox_arg = *ref != '\0' ? ref : mask; + ctx->inbox = strncasecmp(inbox_arg, "INBOX", 5) == 0 && + (inbox_arg[5] == ctx->ns->sep || inbox_arg[5] == '\0'); + cmd->context = ctx; if (!cmd_list_continue(cmd)) { /* unfinished */