dovecot-1.1: mailbox_list_iter_update() was always setting subsc...

dovecot at dovecot.org dovecot at dovecot.org
Sun May 4 23:47:45 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.1/rev/2dd86c2f8efb
changeset: 7494:2dd86c2f8efb
user:      Timo Sirainen <tss at iki.fi>
date:      Sun May 04 23:44:56 2008 +0300
description:
mailbox_list_iter_update() was always setting subscribed flags to processed
nodes. Changed the API so the flags can be specified.

diffstat:

3 files changed, 45 insertions(+), 35 deletions(-)
src/lib-storage/list/mailbox-list-subscriptions.c |   14 ++++--
src/lib-storage/mailbox-list-private.h            |   17 +++++--
src/lib-storage/mailbox-list.c                    |   49 +++++++++------------

diffs (163 lines):

diff -r 3d5379e33664 -r 2dd86c2f8efb src/lib-storage/list/mailbox-list-subscriptions.c
--- a/src/lib-storage/list/mailbox-list-subscriptions.c	Sun May 04 23:43:18 2008 +0300
+++ b/src/lib-storage/list/mailbox-list-subscriptions.c	Sun May 04 23:44:56 2008 +0300
@@ -13,10 +13,10 @@ mailbox_list_subscriptions_fill_real(str
 				     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(str
 			   "/", 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 -r 3d5379e33664 -r 2dd86c2f8efb src/lib-storage/mailbox-list-private.h
--- a/src/lib-storage/mailbox-list-private.h	Sun May 04 23:43:18 2008 +0300
+++ b/src/lib-storage/mailbox-list-private.h	Sun May 04 23:44:56 2008 +0300
@@ -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_delete_index_control(st
 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 -r 3d5379e33664 -r 2dd86c2f8efb src/lib-storage/mailbox-list.c
--- a/src/lib-storage/mailbox-list.c	Sun May 04 23:43:18 2008 +0300
+++ b/src/lib-storage/mailbox-list.c	Sun May 04 23:44:56 2008 +0300
@@ -474,38 +474,36 @@ static void node_fix_parents(struct mail
 }
 
 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)
-{
-	struct mail_namespace *ns = ctx->list->ns;
+mailbox_list_iter_update_real(struct mailbox_list_iter_update_context *ctx,
+			      const char *name)
+{
+	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 mai
 			   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 mai
 
 		name = t_strdup_until(name, p);
 		create_flags &= ~MAILBOX_NOCHILDREN;
-		always_flags = MAILBOX_CHILDREN | MAILBOX_CHILD_SUBSCRIBED;
-	}
-}
-
-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)
+		always_flags = MAILBOX_CHILDREN | ctx->parent_flags;
+	}
+}
+
+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;
 }
 


More information about the dovecot-cvs mailing list