dovecot-1.2: virtual: Minor code cleanup.

dovecot at dovecot.org dovecot at dovecot.org
Mon Jul 27 02:51:42 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/b24bdff70c63
changeset: 9251:b24bdff70c63
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Jul 26 19:37:05 2009 -0400
description:
virtual: Minor code cleanup.

diffstat:

1 file changed, 50 insertions(+), 37 deletions(-)
src/plugins/virtual/virtual-storage.c |   87 ++++++++++++++++++---------------

diffs (105 lines):

diff -r 5b07514466c3 -r b24bdff70c63 src/plugins/virtual/virtual-storage.c
--- a/src/plugins/virtual/virtual-storage.c	Sun Jul 26 18:14:34 2009 -0400
+++ b/src/plugins/virtual/virtual-storage.c	Sun Jul 26 19:37:05 2009 -0400
@@ -199,51 +199,64 @@ static bool virtual_mailbox_is_in_open_s
 	return FALSE;
 }
 
+static int virtual_backend_box_open(struct virtual_mailbox *mbox,
+				    struct virtual_backend_box *bbox,
+				    enum mailbox_open_flags open_flags)
+{
+	struct mail_user *user = mbox->storage->storage.ns->user;
+	struct mail_namespace *ns;
+	struct mail_storage *storage;
+	enum mail_error error;
+	const char *str, *mailbox;
+
+	open_flags |= MAILBOX_OPEN_KEEP_RECENT;
+
+	mailbox = bbox->name;
+	ns = mail_namespace_find(user->namespaces, &mailbox);
+	storage = ns->storage;
+	bbox->box = mailbox_open(&storage, mailbox, NULL, open_flags);
+
+	if (bbox->box == NULL) {
+		str = mail_storage_get_last_error(storage, &error);
+		if (bbox->wildcard && (error == MAIL_ERROR_PERM ||
+				       error == MAIL_ERROR_NOTFOUND)) {
+			/* this mailbox wasn't explicitly specified.
+			   just skip it. */
+			return 0;
+		}
+		if (storage != mbox->ibox.box.storage) {
+			/* copy the error */
+			mail_storage_set_error(mbox->ibox.box.storage,
+					       error, str);
+		}
+		return -1;
+	}
+	i_array_init(&bbox->uids, 64);
+	i_array_init(&bbox->sync_pending_removes, 64);
+	mail_search_args_init(bbox->search_args, bbox->box, FALSE, NULL);
+	return 1;
+}
+
 static int virtual_mailboxes_open(struct virtual_mailbox *mbox,
 				  enum mailbox_open_flags open_flags)
 {
-	struct mail_user *user = mbox->storage->storage.ns->user;
 	struct virtual_backend_box *const *bboxes;
-	struct mail_namespace *ns;
-	struct mail_storage *storage;
 	unsigned int i, count;
-	enum mail_error error;
-	const char *str, *mailbox;
-
-	open_flags |= MAILBOX_OPEN_KEEP_RECENT;
+	int ret;
 
 	bboxes = array_get(&mbox->backend_boxes, &count);
 	for (i = 0; i < count; ) {
-		mailbox = bboxes[i]->name;
-		ns = mail_namespace_find(user->namespaces, &mailbox);
-		storage = ns->storage;
-		bboxes[i]->box = mailbox_open(&storage, mailbox,
-					      NULL, open_flags);
-
-		if (bboxes[i]->box == NULL) {
-			str = mail_storage_get_last_error(storage, &error);
-			if (bboxes[i]->wildcard &&
-			    (error == MAIL_ERROR_PERM ||
-			     error == MAIL_ERROR_NOTFOUND)) {
-				/* this mailbox wasn't explicitly specified.
-				   just skip it. */
-				mail_search_args_unref(&bboxes[i]->search_args);
-				array_delete(&mbox->backend_boxes, i, 1);
-				bboxes = array_get(&mbox->backend_boxes, &count);
-				continue;
-			}
-			if (storage != mbox->ibox.box.storage) {
-				/* copy the error */
-				mail_storage_set_error(mbox->ibox.box.storage,
-						       error, str);
-			}
-			break;
-		}
-		i_array_init(&bboxes[i]->uids, 64);
-		i_array_init(&bboxes[i]->sync_pending_removes, 64);
-		mail_search_args_init(bboxes[i]->search_args, bboxes[i]->box,
-				      FALSE, NULL);
-		i++;
+		ret = virtual_backend_box_open(mbox, bboxes[i], open_flags);
+		if (ret <= 0) {
+			if (ret < 0)
+				break;
+
+			mail_search_args_unref(&bboxes[i]->search_args);
+			array_delete(&mbox->backend_boxes, i, 1);
+			bboxes = array_get(&mbox->backend_boxes, &count);
+		} else {
+			i++;
+		}
 	}
 	if (i == count)
 		return 0;


More information about the dovecot-cvs mailing list