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 ?
"/", 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);
}
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;
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);
}
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;
}
return the parent mailbox. */
}
- if (!match_parents)
+ if (!ctx->match_parents)
break;
/* see if parent matches */
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;
}