changeset 9251:b24bdff70c63 HEAD

virtual: Minor code cleanup.
author Timo Sirainen <tss@iki.fi>
date Sun, 26 Jul 2009 19:37:05 -0400
parents 5b07514466c3
children 88d4e83fcea5
files src/plugins/virtual/virtual-storage.c
diffstat 1 files changed, 45 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- 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 @@
 	return FALSE;
 }
 
-static int virtual_mailboxes_open(struct virtual_mailbox *mbox,
-				  enum mailbox_open_flags open_flags)
+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 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;
 
+	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 virtual_backend_box *const *bboxes;
+	unsigned int i, count;
+	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);
+		ret = virtual_backend_box_open(mbox, bboxes[i], open_flags);
+		if (ret <= 0) {
+			if (ret < 0)
+				break;
 
-		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;
+			mail_search_args_unref(&bboxes[i]->search_args);
+			array_delete(&mbox->backend_boxes, i, 1);
+			bboxes = array_get(&mbox->backend_boxes, &count);
+		} else {
+			i++;
 		}
-		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++;
 	}
 	if (i == count)
 		return 0;