From: Timo Sirainen Date: Sun, 4 May 2008 20:44:56 +0000 (+0300) Subject: mailbox_list_iter_update() was always setting subscribed flags to processed X-Git-Tag: 1.1.rc5~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4366a21968093172d9b757fe6894b1ee8916434e;p=thirdparty%2Fdovecot%2Fcore.git mailbox_list_iter_update() was always setting subscribed flags to processed nodes. Changed the API so the flags can be specified. --HG-- branch : HEAD --- diff --git a/src/lib-storage/list/mailbox-list-subscriptions.c b/src/lib-storage/list/mailbox-list-subscriptions.c index a7ce5033a9..edc3027da3 100644 --- a/src/lib-storage/list/mailbox-list-subscriptions.c +++ b/src/lib-storage/list/mailbox-list-subscriptions.c @@ -13,10 +13,10 @@ mailbox_list_subscriptions_fill_real(struct mailbox_list_iterate_context *ctx, bool update_only) { struct mail_namespace *ns = ctx->list->ns; + struct mailbox_list_iter_update_context update_ctx; struct subsfile_list_context *subsfile_ctx; const char *path, *name; string_t *vname; - bool match_parents; vname = t_str_new(256); path = t_strconcat(ctx->list->set.control_dir != NULL ? @@ -25,13 +25,19 @@ mailbox_list_subscriptions_fill_real(struct mailbox_list_iterate_context *ctx, "/", ctx->list->set.subscription_fname, NULL); subsfile_ctx = subsfile_list_init(ctx->list, path); - match_parents = + memset(&update_ctx, 0, sizeof(update_ctx)); + update_ctx.iter_ctx = ctx; + update_ctx.tree_ctx = tree_ctx; + update_ctx.glob = glob; + update_ctx.leaf_flags = MAILBOX_SUBSCRIBED; + update_ctx.parent_flags = MAILBOX_CHILD_SUBSCRIBED; + update_ctx.update_only = update_only; + update_ctx.match_parents = (ctx->flags & MAILBOX_LIST_ITER_SELECT_RECURSIVEMATCH) != 0; while ((name = subsfile_list_next(subsfile_ctx)) != NULL) { name = mail_namespace_get_vname(ns, vname, name); - mailbox_list_iter_update(ctx, tree_ctx, glob, update_only, - match_parents, name); + mailbox_list_iter_update(&update_ctx, name); } return subsfile_list_deinit(subsfile_ctx); } diff --git a/src/lib-storage/mailbox-list-private.h b/src/lib-storage/mailbox-list-private.h index 9544b85600..20464d7703 100644 --- a/src/lib-storage/mailbox-list-private.h +++ b/src/lib-storage/mailbox-list-private.h @@ -93,6 +93,17 @@ struct mailbox_list_iterate_context { bool failed; }; +struct mailbox_list_iter_update_context { + struct mailbox_list_iterate_context *iter_ctx; + struct mailbox_tree_context *tree_ctx; + + struct imap_match_glob *glob; + enum mailbox_info_flags leaf_flags, parent_flags; + + unsigned int update_only:1; + unsigned int match_parents:1; +}; + /* Modules should use do "my_id = mailbox_list_module_id++" and use objects' module_contexts[id] for their own purposes. */ extern struct mailbox_list_module_register mailbox_list_module_register; @@ -110,10 +121,8 @@ int mailbox_list_settings_parse(const char *data, int mailbox_list_delete_index_control(struct mailbox_list *list, const char *name); -void mailbox_list_iter_update(struct mailbox_list_iterate_context *ctx, - struct mailbox_tree_context *tree_ctx, - struct imap_match_glob *glob, bool update_only, - bool match_parents, const char *name); +void mailbox_list_iter_update(struct mailbox_list_iter_update_context *ctx, + const char *name); bool mailbox_list_name_is_too_large(const char *name, char sep); enum mailbox_list_file_type mailbox_list_get_file_type(const struct dirent *d); diff --git a/src/lib-storage/mailbox-list.c b/src/lib-storage/mailbox-list.c index 6994115942..860f9e6028 100644 --- a/src/lib-storage/mailbox-list.c +++ b/src/lib-storage/mailbox-list.c @@ -474,38 +474,36 @@ static void node_fix_parents(struct mailbox_node *node) } static void -mailbox_list_iter_update_real(struct mailbox_list_iterate_context *ctx, - struct mailbox_tree_context *tree_ctx, - struct imap_match_glob *glob, bool update_only, - bool match_parents, const char *name) +mailbox_list_iter_update_real(struct mailbox_list_iter_update_context *ctx, + const char *name) { - struct mail_namespace *ns = ctx->list->ns; + struct mail_namespace *ns = ctx->iter_ctx->list->ns; struct mailbox_node *node; - enum mailbox_info_flags create_flags, always_flags; + enum mailbox_info_flags create_flags = 0, always_flags; enum imap_match_result match; const char *p; bool created, add_matched; - create_flags = (update_only || - (ctx->flags & MAILBOX_LIST_ITER_RETURN_NO_FLAGS) == 0) ? - (MAILBOX_NONEXISTENT | MAILBOX_NOCHILDREN) : 0; - always_flags = MAILBOX_SUBSCRIBED; + if (ctx->update_only || + (ctx->iter_ctx->flags & MAILBOX_LIST_ITER_RETURN_NO_FLAGS) == 0) + create_flags = MAILBOX_NONEXISTENT | MAILBOX_NOCHILDREN; + always_flags = ctx->leaf_flags; add_matched = TRUE; for (;;) { created = FALSE; - match = imap_match(glob, name); + match = imap_match(ctx->glob, name); if (match == IMAP_MATCH_YES) { - node = update_only ? - mailbox_tree_lookup(tree_ctx, name) : - mailbox_tree_get(tree_ctx, name, &created); + node = ctx->update_only ? + mailbox_tree_lookup(ctx->tree_ctx, name) : + mailbox_tree_get(ctx->tree_ctx, name, &created); if (created) { node->flags = create_flags; if (create_flags != 0) node_fix_parents(node); } if (node != NULL) { - if (!update_only && add_matched) + if (!ctx->update_only && add_matched) node->flags |= MAILBOX_MATCHED; node->flags |= always_flags; } @@ -521,7 +519,7 @@ mailbox_list_iter_update_real(struct mailbox_list_iterate_context *ctx, return the parent mailbox. */ } - if (!match_parents) + if (!ctx->match_parents) break; /* see if parent matches */ @@ -531,18 +529,15 @@ mailbox_list_iter_update_real(struct mailbox_list_iterate_context *ctx, name = t_strdup_until(name, p); create_flags &= ~MAILBOX_NOCHILDREN; - always_flags = MAILBOX_CHILDREN | MAILBOX_CHILD_SUBSCRIBED; + always_flags = MAILBOX_CHILDREN | ctx->parent_flags; } } -void mailbox_list_iter_update(struct mailbox_list_iterate_context *ctx, - struct mailbox_tree_context *tree_ctx, - struct imap_match_glob *glob, bool update_only, - bool match_parents, const char *name) +void mailbox_list_iter_update(struct mailbox_list_iter_update_context *ctx, + const char *name) { T_BEGIN { - mailbox_list_iter_update_real(ctx, tree_ctx, glob, update_only, - match_parents, name); + mailbox_list_iter_update_real(ctx, name); } T_END; }