Skip to content

Commit

Permalink
imapc: If root separator lookup fails, fail all further lookups.
Browse files Browse the repository at this point in the history
We already returned a potentially wrong separator (since there's no way to
return error), so we don't want to continue and possibly make things worse.
  • Loading branch information
sirainen authored and GitLab committed Apr 12, 2016
1 parent 2a7a7f6 commit 461bcfc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/lib-storage/index/imapc/imapc-list.c
Expand Up @@ -324,9 +324,11 @@ static char imapc_list_get_hierarchy_sep(struct mailbox_list *_list)
struct imapc_mailbox_list *list = (struct imapc_mailbox_list *)_list;
char sep;

if (imapc_list_try_get_root_sep(list, &sep) < 0) {
/* we can't really fail here. just return a common separator
and keep failing all list commands until it succeeds. */
if (list->root_sep_lookup_failed ||
imapc_list_try_get_root_sep(list, &sep) < 0) {
/* we can't really return a failure here. just return a common
separator and fail all the future list operations. */
list->root_sep_lookup_failed = TRUE;
return '/';
}
return sep;
Expand Down Expand Up @@ -546,6 +548,10 @@ static int imapc_list_refresh(struct imapc_mailbox_list *list)
struct mailbox_node *node;
const char *pattern;

if (list->root_sep_lookup_failed) {
mailbox_list_set_internal_error(&list->list);
return -1;
}
if (list->refreshed_mailboxes)
return 0;

Expand Down Expand Up @@ -774,6 +780,11 @@ imapc_list_subscriptions_refresh(struct mailbox_list *_src_list,

i_assert(src_list->tmp_subscriptions == NULL);

if (src_list->root_sep_lookup_failed) {
mailbox_list_set_internal_error(_src_list);
return -1;
}

if (src_list->refreshed_subscriptions) {
if (dest_list->subscriptions == NULL)
dest_list->subscriptions = mailbox_tree_init(dest_sep);
Expand Down
1 change: 1 addition & 0 deletions src/lib-storage/index/imapc/imapc-list.h
Expand Up @@ -30,6 +30,7 @@ struct imapc_mailbox_list {
unsigned int refreshed_mailboxes_recently:1;
unsigned int index_list_failed:1;
unsigned int root_sep_pending:1;
unsigned int root_sep_lookup_failed:1;
};

int imapc_list_get_mailbox_flags(struct mailbox_list *list, const char *name,
Expand Down

0 comments on commit 461bcfc

Please sign in to comment.