dovecot-1.2: Added mailbox_list_iter_init_namespaces() for listi...

dovecot at dovecot.org dovecot at dovecot.org
Fri Aug 8 23:50:48 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/4e1b54eb7407
changeset: 8079:4e1b54eb7407
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Aug 08 16:48:44 2008 -0400
description:
Added mailbox_list_iter_init_namespaces() for listing mailboxes from multiple namespaces.
struct mailbox_info now always contains the listed namespace.

diffstat:

3 files changed, 82 insertions(+), 1 deletion(-)
src/lib-storage/list/mailbox-list-maildir-iter.c |    1 
src/lib-storage/mailbox-list.c                   |   73 ++++++++++++++++++++++
src/lib-storage/mailbox-list.h                   |    9 ++

diffs (127 lines):

diff -r c8d3024015a8 -r 4e1b54eb7407 src/lib-storage/list/mailbox-list-maildir-iter.c
--- a/src/lib-storage/list/mailbox-list-maildir-iter.c	Fri Aug 08 16:45:23 2008 -0400
+++ b/src/lib-storage/list/mailbox-list-maildir-iter.c	Fri Aug 08 16:48:44 2008 -0400
@@ -282,6 +282,7 @@ maildir_list_iter_init(struct mailbox_li
 	ctx->ctx.flags = flags;
 	ctx->pool = pool;
 	ctx->tree_ctx = mailbox_tree_init(sep);
+	ctx->info.ns = _list->ns;
 
 	glob = imap_match_init_multiple(pool, patterns, TRUE, sep);
 
diff -r c8d3024015a8 -r 4e1b54eb7407 src/lib-storage/mailbox-list.c
--- a/src/lib-storage/mailbox-list.c	Fri Aug 08 16:45:23 2008 -0400
+++ b/src/lib-storage/mailbox-list.c	Fri Aug 08 16:48:44 2008 -0400
@@ -26,6 +26,14 @@
 #define CRITICAL_MSG \
 	"Internal error occurred. Refer to server log for more information."
 #define CRITICAL_MSG_STAMP CRITICAL_MSG " [%Y-%m-%d %H:%M:%S]"
+
+struct ns_list_iterate_context {
+	struct mailbox_list_iterate_context ctx;
+	struct mailbox_list_iterate_context *backend_ctx;
+	struct mail_namespace *namespaces;
+	pool_t pool;
+	const char **patterns;
+};
 
 struct mailbox_list_module_register mailbox_list_module_register = { 0 };
 
@@ -390,6 +398,71 @@ mailbox_list_iter_init_multiple(struct m
 
 	mailbox_list_clear_error(list);
 	return list->v.iter_init(list, patterns, flags);
+}
+
+static const struct mailbox_info *
+mailbox_list_ns_iter_next(struct mailbox_list_iterate_context *_ctx)
+{
+	struct ns_list_iterate_context *ctx =
+		(struct ns_list_iterate_context *)_ctx;
+	const struct mailbox_info *info;
+
+	info = mailbox_list_iter_next(ctx->backend_ctx);
+	if (info == NULL && ctx->namespaces != NULL) {
+		/* go to the next namespace */
+		if (mailbox_list_iter_deinit(&ctx->backend_ctx) < 0)
+			_ctx->failed = TRUE;
+		ctx->backend_ctx =
+			mailbox_list_iter_init_multiple(ctx->namespaces->list,
+							ctx->patterns,
+							_ctx->flags);
+		ctx->namespaces = ctx->namespaces->next;
+		return mailbox_list_ns_iter_next(_ctx);
+	}
+	return info;
+}
+
+static int
+mailbox_list_ns_iter_deinit(struct mailbox_list_iterate_context *_ctx)
+{
+	struct ns_list_iterate_context *ctx =
+		(struct ns_list_iterate_context *)_ctx;
+	int ret;
+
+	if (mailbox_list_iter_deinit(&ctx->backend_ctx) < 0)
+		_ctx->failed = TRUE;
+	ret = _ctx->failed ? -1 : 0;
+	pool_unref(&ctx->pool);
+	return ret;
+}
+
+struct mailbox_list_iterate_context *
+mailbox_list_iter_init_namespaces(struct mail_namespace *namespaces,
+				  const char *const *patterns,
+				  enum mailbox_list_iter_flags flags)
+{
+	struct ns_list_iterate_context *ctx;
+	unsigned int i, count;
+	pool_t pool;
+
+	i_assert(namespaces != NULL);
+
+	pool = pool_alloconly_create("mailbox list namespaces", 256);
+	ctx = p_new(pool, struct ns_list_iterate_context, 1);
+	ctx->pool = pool;
+	ctx->ctx.list = p_new(pool, struct mailbox_list, 1);
+	ctx->ctx.list->v.iter_next = mailbox_list_ns_iter_next;
+	ctx->ctx.list->v.iter_deinit = mailbox_list_ns_iter_deinit;
+
+	count = str_array_length(patterns);
+	ctx->patterns = p_new(pool, const char *, count + 1);
+	for (i = 0; i < count; i++)
+		ctx->patterns[i] = p_strdup(pool, patterns[i]);
+
+	ctx->backend_ctx = mailbox_list_iter_init_multiple(namespaces->list,
+							   patterns, flags);
+	ctx->namespaces = namespaces->next;
+	return &ctx->ctx;
 }
 
 const struct mailbox_info *
diff -r c8d3024015a8 -r 4e1b54eb7407 src/lib-storage/mailbox-list.h
--- a/src/lib-storage/mailbox-list.h	Fri Aug 08 16:45:23 2008 -0400
+++ b/src/lib-storage/mailbox-list.h	Fri Aug 08 16:48:44 2008 -0400
@@ -111,7 +111,8 @@ struct mailbox_list_settings {
 
 struct mailbox_info {
 	const char *name;
-        enum mailbox_info_flags flags;
+	enum mailbox_info_flags flags;
+	struct mail_namespace *ns;
 };
 
 /* register all drivers */
@@ -187,6 +188,12 @@ mailbox_list_iter_init_multiple(struct m
 mailbox_list_iter_init_multiple(struct mailbox_list *list,
 				const char *const *patterns,
 				enum mailbox_list_iter_flags flags);
+/* List mailbox_list_iter_init_multiple(), but list mailboxes from all the
+   specified namespaces. */
+struct mailbox_list_iterate_context *
+mailbox_list_iter_init_namespaces(struct mail_namespace *namespaces,
+				  const char *const *patterns,
+				  enum mailbox_list_iter_flags flags);
 /* Get next mailbox. Returns the mailbox name */
 const struct mailbox_info *
 mailbox_list_iter_next(struct mailbox_list_iterate_context *ctx);


More information about the dovecot-cvs mailing list