changeset 12632:2c599f0eab69

lib-storage: Made struct mailbox_list_iterate_context usable for plugins.
author Timo Sirainen <tss@iki.fi>
date Wed, 02 Feb 2011 01:14:57 +0200
parents 7701fb66d82a
children 1c8cc9bdb141
files src/lib-storage/index/imapc/imapc-list.c src/lib-storage/index/shared/shared-list.c src/lib-storage/list/mailbox-list-fs-iter.c src/lib-storage/list/mailbox-list-maildir-iter.c src/lib-storage/list/mailbox-list-none.c src/lib-storage/mailbox-list-private.h
diffstat 6 files changed, 51 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/imapc/imapc-list.c	Tue Feb 01 21:07:27 2011 +0200
+++ b/src/lib-storage/index/imapc/imapc-list.c	Wed Feb 02 01:14:57 2011 +0200
@@ -11,7 +11,6 @@
 struct imapc_mailbox_list_iterate_context {
 	struct mailbox_list_iterate_context ctx;
 	struct mailbox_tree_iterate_context *iter;
-	struct imap_match_glob *glob;
 	struct mailbox_info info;
 	bool failed;
 };
@@ -242,9 +241,11 @@
 	ctx = i_new(struct imapc_mailbox_list_iterate_context, 1);
 	ctx->ctx.list = _list;
 	ctx->ctx.flags = flags;
+	ctx->ctx.glob = imap_match_init_multiple(default_pool, patterns,
+						 FALSE, sep);
+	array_create(&ctx->ctx.module_contexts, default_pool, sizeof(void *), 5);
+
 	ctx->info.ns = _list->ns;
-	ctx->glob = imap_match_init_multiple(default_pool, patterns,
-					     FALSE, sep);
 	if (imapc_list_refresh(list, flags) < 0)
 		ctx->failed = TRUE;
 	else {
@@ -267,7 +268,7 @@
 		return NULL;
 
 	while ((node = mailbox_tree_iterate_next(ctx->iter, &name)) != NULL) {
-		if (imap_match(ctx->glob, name) == IMAP_MATCH_YES) {
+		if (imap_match(ctx->ctx.glob, name) == IMAP_MATCH_YES) {
 			ctx->info.flags &= ~(MAILBOX_CHILDREN |
 					     MAILBOX_NOCHILDREN);
 			if (node->children == NULL)
@@ -289,7 +290,8 @@
 
 	if (ctx->iter != NULL)
 		mailbox_tree_iterate_deinit(&ctx->iter);
-	imap_match_deinit(&ctx->glob);
+	imap_match_deinit(&ctx->ctx.glob);
+	array_free(&ctx->ctx.module_contexts);
 	i_free(ctx);
 	return ret;
 }
--- a/src/lib-storage/index/shared/shared-list.c	Tue Feb 01 21:07:27 2011 +0200
+++ b/src/lib-storage/index/shared/shared-list.c	Wed Feb 02 01:14:57 2011 +0200
@@ -9,7 +9,6 @@
 struct shared_mailbox_list_iterate_context {
 	struct mailbox_list_iterate_context ctx;
 	struct mail_namespace *cur_ns;
-	struct imap_match_glob *glob;
 	struct mailbox_info info;
 };
 
@@ -156,11 +155,13 @@
 	ctx = i_new(struct shared_mailbox_list_iterate_context, 1);
 	ctx->ctx.list = list;
 	ctx->ctx.flags = flags;
+	ctx->ctx.glob = imap_match_init_multiple(default_pool, patterns,
+						 FALSE, sep);
+	array_create(&ctx->ctx.module_contexts, default_pool, sizeof(void *), 5);
+
 	ctx->cur_ns = list->ns->user->namespaces;
 	ctx->info.ns = list->ns;
 	ctx->info.flags = MAILBOX_NONEXISTENT;
-	ctx->glob = imap_match_init_multiple(default_pool, patterns,
-					     FALSE, sep);
 	return &ctx->ctx;
 }
 
@@ -188,7 +189,7 @@
 		   prefix matches without the trailing separator */
 		i_assert(ns->prefix_len > 0);
 		ctx->info.name = t_strndup(ns->prefix, ns->prefix_len - 1);
-		if (imap_match(ctx->glob, ctx->info.name) == IMAP_MATCH_YES) {
+		if (imap_match(ctx->ctx.glob, ctx->info.name) == IMAP_MATCH_YES) {
 			ctx->cur_ns = ns->next;
 			return &ctx->info;
 		}
@@ -203,7 +204,8 @@
 	struct shared_mailbox_list_iterate_context *ctx =
 		(struct shared_mailbox_list_iterate_context *)_ctx;
 
-	imap_match_deinit(&ctx->glob);
+	imap_match_deinit(&ctx->ctx.glob);
+	array_free(&ctx->ctx.module_contexts);
 	i_free(ctx);
 	return 0;
 }
--- a/src/lib-storage/list/mailbox-list-fs-iter.c	Tue Feb 01 21:07:27 2011 +0200
+++ b/src/lib-storage/list/mailbox-list-fs-iter.c	Wed Feb 02 01:14:57 2011 +0200
@@ -36,7 +36,6 @@
 	struct mailbox_list_iterate_context ctx;
 
 	ARRAY_DEFINE(valid_patterns, char *);
-	struct imap_match_glob *glob;
 	struct mailbox_tree_context *subs_tree;
 	struct mailbox_tree_iterate_context *tree_iter;
 	char sep;
@@ -221,6 +220,8 @@
 	ctx = i_new(struct fs_list_iterate_context, 1);
 	ctx->ctx.list = _list;
 	ctx->ctx.flags = flags;
+	array_create(&ctx->ctx.module_contexts, default_pool, sizeof(void *), 5);
+
 	ctx->info_pool = pool_alloconly_create("fs list", 1024);
 	ctx->next = fs_list_next;
 	ctx->sep = mail_namespace_get_sep(_list->ns);
@@ -257,8 +258,8 @@
 		return &ctx->ctx;
 	}
 	patterns = (const void *)array_idx(&ctx->valid_patterns, 0);
-	ctx->glob = imap_match_init_multiple(default_pool, patterns, TRUE,
-					     ctx->sep);
+	ctx->ctx.glob = imap_match_init_multiple(default_pool, patterns, TRUE,
+						 ctx->sep);
 
 	if ((flags & (MAILBOX_LIST_ITER_SELECT_SUBSCRIBED |
 		      MAILBOX_LIST_ITER_RETURN_SUBSCRIBED)) != 0) {
@@ -266,7 +267,7 @@
 		   mailboxes. Build a mailbox tree of all the subscriptions. */
 		ctx->subs_tree = mailbox_tree_init(ctx->sep);
 		if (mailbox_list_subscriptions_fill(&ctx->ctx, ctx->subs_tree,
-						    ctx->glob, FALSE) < 0) {
+						    ctx->ctx.glob, FALSE) < 0) {
 			ctx->ctx.failed = TRUE;
 			return &ctx->ctx;
 		}
@@ -336,8 +337,9 @@
 		mailbox_tree_deinit(&ctx->subs_tree);
 	if (ctx->info_pool != NULL)
 		pool_unref(&ctx->info_pool);
-	if (ctx->glob != NULL)
-		imap_match_deinit(&ctx->glob);
+	if (ctx->ctx.glob != NULL)
+		imap_match_deinit(&ctx->ctx.glob);
+	array_free(&ctx->ctx.module_contexts);
 	i_free(ctx);
 
 	return ret;
@@ -504,7 +506,7 @@
 	int ret;
 
 	vpath = t_strdup_printf("%s%c", list_path, ctx->sep);
-	match2 = imap_match(ctx->glob, vpath);
+	match2 = imap_match(ctx->ctx.glob, vpath);
 
 	if (match == IMAP_MATCH_YES)
 		ctx->info.name = p_strdup(ctx->info_pool, list_path);
@@ -573,7 +575,7 @@
 
 	/* check the pattern */
 	list_path = t_strconcat(ctx->dir->virtual_path, fname, NULL);
-	match = imap_match(ctx->glob, list_path);
+	match = imap_match(ctx->ctx.glob, list_path);
 	if (match != IMAP_MATCH_YES && (match & IMAP_MATCH_CHILDREN) == 0 &&
 	    !ctx->dir->delayed_send)
 		return 0;
@@ -809,8 +811,8 @@
 
 	if (!ctx->inbox_found &&
 	    (ctx->ctx.list->ns->flags & NAMESPACE_FLAG_INBOX_ANY) != 0 &&
-	    ((ctx->glob != NULL &&
-	      imap_match(ctx->glob,
+	    ((ctx->ctx.glob != NULL &&
+	      imap_match(ctx->ctx.glob,
 			 fs_list_get_inbox_vname(ctx)) == IMAP_MATCH_YES) ||
 	     ctx->inbox_match)) {
 		/* INBOX wasn't seen while listing other mailboxes. It might
--- a/src/lib-storage/list/mailbox-list-maildir-iter.c	Tue Feb 01 21:07:27 2011 +0200
+++ b/src/lib-storage/list/mailbox-list-maildir-iter.c	Wed Feb 02 01:14:57 2011 +0200
@@ -1,6 +1,7 @@
 /* Copyright (c) 2002-2010 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
+#include "array.h"
 #include "str.h"
 #include "ioloop.h"
 #include "unlink-directory.h"
@@ -442,7 +443,6 @@
 	struct maildir_mailbox_list *list =
 		(struct maildir_mailbox_list *)_list;
 	struct maildir_list_iterate_context *ctx;
-        struct imap_match_glob *glob;
 	pool_t pool;
 	char ns_sep = mail_namespace_get_sep(_list->ns);
 	int ret;
@@ -451,21 +451,22 @@
 	ctx = p_new(pool, struct maildir_list_iterate_context, 1);
 	ctx->ctx.list = _list;
 	ctx->ctx.flags = flags;
+	ctx->ctx.glob = imap_match_init_multiple(pool, patterns, TRUE, ns_sep);
+	array_create(&ctx->ctx.module_contexts, pool, sizeof(void *), 5);
+
 	ctx->pool = pool;
 	ctx->tree_ctx = mailbox_tree_init(ns_sep);
 	ctx->info.ns = _list->ns;
 	ctx->prefix_char = strcmp(_list->name, MAILBOX_LIST_NAME_IMAPDIR) == 0 ?
 		'\0' : list->sep;
 
-	glob = imap_match_init_multiple(pool, patterns, TRUE, ns_sep);
-
 	ctx->dir = _list->set.root_dir;
 
 	if ((flags & MAILBOX_LIST_ITER_SELECT_SUBSCRIBED) != 0) {
 		/* Listing only subscribed mailboxes.
 		   Flags are set later if needed. */
 		if (mailbox_list_subscriptions_fill(&ctx->ctx, ctx->tree_ctx,
-						    glob, FALSE) < 0) {
+						    ctx->ctx.glob, FALSE) < 0) {
 			ctx->ctx.failed = TRUE;
 			return &ctx->ctx;
 		}
@@ -478,7 +479,8 @@
 			(flags & MAILBOX_LIST_ITER_SELECT_SUBSCRIBED) != 0;
 
 		T_BEGIN {
-			ret = maildir_fill_readdir(ctx, glob, update_only);
+			ret = maildir_fill_readdir(ctx, ctx->ctx.glob,
+						   update_only);
 		} T_END;
 		if (ret < 0) {
 			ctx->ctx.failed = TRUE;
@@ -502,7 +504,7 @@
 		/* we're listing all mailboxes but we want to know
 		   \Subscribed flags */
 		if (mailbox_list_subscriptions_fill(&ctx->ctx, ctx->tree_ctx,
-						    glob, TRUE) < 0) {
+						    ctx->ctx.glob, TRUE) < 0) {
 			ctx->ctx.failed = TRUE;
 			return &ctx->ctx;
 		}
--- a/src/lib-storage/list/mailbox-list-none.c	Tue Feb 01 21:07:27 2011 +0200
+++ b/src/lib-storage/list/mailbox-list-none.c	Wed Feb 02 01:14:57 2011 +0200
@@ -1,6 +1,8 @@
 /* Copyright (c) 2006-2010 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
+#include "array.h"
+#include "imap-match.h"
 #include "mailbox-list-private.h"
 
 #define MAILBOX_LIST_NAME_NONE "none"
@@ -114,7 +116,7 @@
 
 static struct mailbox_list_iterate_context *
 none_list_iter_init(struct mailbox_list *list,
-		    const char *const *patterns ATTR_UNUSED,
+		    const char *const *patterns,
 		    enum mailbox_list_iter_flags flags)
 {
 	struct mailbox_list_iterate_context *ctx;
@@ -122,12 +124,17 @@
 	ctx = i_new(struct mailbox_list_iterate_context, 1);
 	ctx->list = list;
 	ctx->flags = flags;
+	ctx->glob = imap_match_init_multiple(default_pool, patterns, TRUE,
+					     mail_namespace_get_sep(list->ns));
+	array_create(&ctx->module_contexts, default_pool, sizeof(void *), 5);
 	return ctx;
 }
 
 static int
 none_list_iter_deinit(struct mailbox_list_iterate_context *ctx)
 {
+	array_free(&ctx->module_contexts);
+	imap_match_deinit(&ctx->glob);
 	i_free(ctx);
 	return 0;
 }
--- a/src/lib-storage/mailbox-list-private.h	Tue Feb 01 21:07:27 2011 +0200
+++ b/src/lib-storage/mailbox-list-private.h	Wed Feb 02 01:14:57 2011 +0200
@@ -124,10 +124,19 @@
 	unsigned int index_root_dir_created:1;
 };
 
+union mailbox_list_iterate_module_context {
+	struct mailbox_list_module_register *reg;
+};
+
 struct mailbox_list_iterate_context {
 	struct mailbox_list *list;
 	enum mailbox_list_iter_flags flags;
 	bool failed;
+
+	struct imap_match_glob *glob;
+
+	ARRAY_DEFINE(module_contexts,
+		     union mailbox_list_iterate_module_context *);
 };
 
 struct mailbox_list_iter_update_context {