dovecot-2.1: Added MAILBOX_LIST_ITER_SELECT_SPECIALUSE option an...

dovecot at dovecot.org dovecot at dovecot.org
Wed Jan 4 15:08:44 EET 2012


details:   http://hg.dovecot.org/dovecot-2.1/rev/0aa94d55dcff
changeset: 13886:0aa94d55dcff
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Jan 04 15:08:39 2012 +0200
description:
Added MAILBOX_LIST_ITER_SELECT_SPECIALUSE option and enable it for IMAP.
RECURSIVEMATCH option doesn't currently work properly with it.

diffstat:

 src/imap/cmd-list.c                 |   5 ++++-
 src/lib-storage/mailbox-list-iter.c |  33 +++++++++++++++++++++++----------
 src/lib-storage/mailbox-list.h      |   2 ++
 3 files changed, 29 insertions(+), 11 deletions(-)

diffs (94 lines):

diff -r 59f5238c6e61 -r 0aa94d55dcff src/imap/cmd-list.c
--- a/src/imap/cmd-list.c	Wed Jan 04 12:00:13 2012 +0200
+++ b/src/imap/cmd-list.c	Wed Jan 04 15:08:39 2012 +0200
@@ -115,6 +115,8 @@
 				MAILBOX_LIST_ITER_RETURN_SUBSCRIBED;
 		} else if (strcasecmp(str, "RECURSIVEMATCH") == 0)
 			list_flags |= MAILBOX_LIST_ITER_SELECT_RECURSIVEMATCH;
+		else if (strcasecmp(str, "SPECIAL-USE") == 0)
+			list_flags |= MAILBOX_LIST_ITER_SELECT_SPECIALUSE;
 		else if (strcasecmp(str, "REMOTE") == 0) {
 			/* not supported, ignore */
 		} else {
@@ -127,7 +129,8 @@
 	}
 
 	if ((list_flags & MAILBOX_LIST_ITER_SELECT_RECURSIVEMATCH) != 0 &&
-	    (list_flags & MAILBOX_LIST_ITER_SELECT_SUBSCRIBED) == 0) {
+	    (list_flags & (MAILBOX_LIST_ITER_SELECT_SUBSCRIBED |
+			   MAILBOX_LIST_ITER_SELECT_SPECIALUSE)) == 0) {
 		client_send_command_error(ctx->cmd,
 			"RECURSIVEMATCH must not be the only selection.");
 		return FALSE;
diff -r 59f5238c6e61 -r 0aa94d55dcff src/lib-storage/mailbox-list-iter.c
--- a/src/lib-storage/mailbox-list-iter.c	Wed Jan 04 12:00:13 2012 +0200
+++ b/src/lib-storage/mailbox-list-iter.c	Wed Jan 04 15:08:39 2012 +0200
@@ -528,8 +528,12 @@
 		actx->new_info.flags |= MAILBOX_NOCHILDREN;
 
 	match = imap_match(ctx->glob, actx->new_info.name);
-	if (match == IMAP_MATCH_YES)
+	if (match == IMAP_MATCH_YES) {
+		actx->new_info.special_use =
+			*autobox->set->special_use == '\0' ? NULL :
+			autobox->set->special_use;
 		return TRUE;
+	}
 	if ((match & IMAP_MATCH_PARENT) != 0 && !autobox->child_listed) {
 		enum mailbox_info_flags old_flags = actx->new_info.flags;
 		char sep = mail_namespace_get_sep(ctx->list->ns);
@@ -602,24 +606,33 @@
 	autoboxes = array_get(&actx->boxes, &count);
 	while (actx->idx < count) {
 		autobox = &autoboxes[actx->idx++];
-		if (autocreate_iter_autobox(ctx, autobox)) {
-			actx->new_info.special_use =
-				*autobox->set->special_use == '\0' ? NULL :
-				autobox->set->special_use;
+		if (autocreate_iter_autobox(ctx, autobox))
 			return &actx->new_info;
-		}
 	}
 	i_assert(array_count(&actx->boxes) == array_count(&actx->box_sets));
 	return NULL;
 }
 
+static bool
+special_use_selection(struct mailbox_list_iterate_context *ctx,
+		      const struct mailbox_info *info)
+{
+	return (ctx->flags & MAILBOX_LIST_ITER_SELECT_SPECIALUSE) == 0 ||
+		info->special_use != NULL;
+}
+
 const struct mailbox_info *
 mailbox_list_iter_next(struct mailbox_list_iterate_context *ctx)
 {
-	if (ctx->autocreate_ctx != NULL)
-		return autocreate_iter_next(ctx);
-	else
-		return mailbox_list_iter_next_call(ctx);
+	const struct mailbox_info *info;
+
+	do {
+		if (ctx->autocreate_ctx != NULL)
+			info = autocreate_iter_next(ctx);
+		else
+			info = mailbox_list_iter_next_call(ctx);
+	} while (info != NULL && !special_use_selection(ctx, info));
+	return info;
 }
 
 int mailbox_list_iter_deinit(struct mailbox_list_iterate_context **_ctx)
diff -r 59f5238c6e61 -r 0aa94d55dcff src/lib-storage/mailbox-list.h
--- a/src/lib-storage/mailbox-list.h	Wed Jan 04 12:00:13 2012 +0200
+++ b/src/lib-storage/mailbox-list.h	Wed Jan 04 15:08:39 2012 +0200
@@ -79,6 +79,8 @@
 	/* Return MAILBOX_CHILD_* if mailbox's children match selection
 	   criteria, even if the mailbox itself wouldn't match. */
 	MAILBOX_LIST_ITER_SELECT_RECURSIVEMATCH	= 0x000200,
+	/* Return only mailboxes that have special use flags */
+	MAILBOX_LIST_ITER_SELECT_SPECIALUSE	= 0x000400,
 
 	/* Don't return any flags unless it can be done without cost */
 	MAILBOX_LIST_ITER_RETURN_NO_FLAGS	= 0x001000,


More information about the dovecot-cvs mailing list