dovecot-2.1: imapc: Connect to server immediately at startup and...

dovecot at dovecot.org dovecot at dovecot.org
Wed Sep 7 10:38:15 EEST 2011


details:   http://hg.dovecot.org/dovecot-2.1/rev/e5570ee5d695
changeset: 13416:e5570ee5d695
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Sep 07 10:38:01 2011 +0300
description:
imapc: Connect to server immediately at startup and lookup hierarchy separator.
If connecting to server fails, this makes it fail earlier. Also we don't
have to worry about what to do later if hierarchy separator lookup fails.

diffstat:

 src/lib-storage/index/imapc/imapc-list.c    |  14 ++------------
 src/lib-storage/index/imapc/imapc-list.h    |   3 ---
 src/lib-storage/index/imapc/imapc-storage.c |  29 +++++++++++++++++++++++++++++
 3 files changed, 31 insertions(+), 15 deletions(-)

diffs (85 lines):

diff -r 0e1a65d30964 -r e5570ee5d695 src/lib-storage/index/imapc/imapc-list.c
--- a/src/lib-storage/index/imapc/imapc-list.c	Wed Sep 07 10:24:11 2011 +0300
+++ b/src/lib-storage/index/imapc/imapc-list.c	Wed Sep 07 10:38:01 2011 +0300
@@ -165,20 +165,10 @@
 static char imapc_list_get_hierarchy_sep(struct mailbox_list *_list)
 {
 	struct imapc_mailbox_list *list = (struct imapc_mailbox_list *)_list;
-	struct imapc_simple_context ctx;
 
-	if (list->sep == '\0') {
-		imapc_simple_context_init(&ctx, list->storage);
-		imapc_client_cmdf(list->storage->client,
-				  imapc_list_simple_callback, &ctx,
-				  "LIST \"\" \"\"");
-		imapc_simple_run(&ctx);
+	/* storage should have looked this up when it was created */
+	i_assert(list->sep != '\0');
 
-		if (ctx.ret < 0) {
-			list->broken = TRUE;
-			return '/';
-		}
-	}
 	return list->sep;
 }
 
diff -r 0e1a65d30964 -r e5570ee5d695 src/lib-storage/index/imapc/imapc-list.h
--- a/src/lib-storage/index/imapc/imapc-list.h	Wed Sep 07 10:24:11 2011 +0300
+++ b/src/lib-storage/index/imapc/imapc-list.h	Wed Sep 07 10:38:01 2011 +0300
@@ -17,9 +17,6 @@
 
 	unsigned int iter_count;
 
-	/* we've returned wrong separator. all mailbox list operations must
-	   fail from now on. */
-	unsigned int broken:1;
 	unsigned int refreshed_subscriptions:1;
 	unsigned int refreshed_mailboxes:1;
 	unsigned int index_list_failed:1;
diff -r 0e1a65d30964 -r e5570ee5d695 src/lib-storage/index/imapc/imapc-storage.c
--- a/src/lib-storage/index/imapc/imapc-storage.c	Wed Sep 07 10:24:11 2011 +0300
+++ b/src/lib-storage/index/imapc/imapc-storage.c	Wed Sep 07 10:38:01 2011 +0300
@@ -203,6 +203,30 @@
 }
 
 static int
+imapc_storage_get_hierarchy_sep(struct imapc_storage *storage,
+				const char **error_r)
+{
+	struct imapc_simple_context sctx;
+
+	imapc_simple_context_init(&sctx, storage);
+	imapc_client_cmdf(storage->client, imapc_simple_callback, &sctx,
+			  "LIST \"\" \"\"");
+	imapc_simple_run(&sctx);
+
+	if (sctx.ret < 0) {
+		*error_r = t_strdup_printf("LIST failed: %s",
+			mail_storage_get_last_error(&storage->storage, NULL));
+		return -1;
+	}
+
+	if (storage->list->sep == '\0') {
+		*error_r = "LIST didn't return hierarchy separator";
+		return -1;
+	}
+	return sctx.ret;
+}
+
+static int
 imapc_storage_create(struct mail_storage *_storage,
 		     struct mail_namespace *ns,
 		     const char **error_r)
@@ -253,6 +277,11 @@
 	imapc_list_register_callbacks(storage->list);
 	imapc_storage_register_untagged(storage, "STATUS",
 					imapc_untagged_status);
+	/* connect to imap server and get the hierarchy separator. */
+	if (imapc_storage_get_hierarchy_sep(storage, error_r) < 0) {
+		imapc_client_deinit(&storage->client);
+		return -1;
+	}
 	return 0;
 }
 


More information about the dovecot-cvs mailing list