changeset 5798:0d409ce8daae HEAD

Make sure there is exactly one inbox=yes namespace.
author Timo Sirainen <tss@iki.fi>
date Mon, 25 Jun 2007 18:26:36 +0300
parents de3a087ea8d2
children 75e3aedc0568
files src/lib-storage/mail-namespace.c
diffstat 1 files changed, 37 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/mail-namespace.c	Mon Jun 25 18:19:28 2007 +0300
+++ b/src/lib-storage/mail-namespace.c	Mon Jun 25 18:26:36 2007 +0300
@@ -79,6 +79,41 @@
 	return ns;
 }
 
+static bool namespaces_check(struct mail_namespace *namespaces)
+{
+	struct mail_namespace *ns, *inbox_ns = NULL, *private_ns = NULL;
+	unsigned int private_ns_count = 0;
+
+	for (ns = namespaces; ns != NULL; ns = ns->next) {
+		if (ns->inbox) {
+			if (inbox_ns != NULL) {
+				i_error("namespace configuration error: "
+					"There can be only one namespace with "
+					"inbox=yes");
+				return FALSE;
+			}
+			inbox_ns = ns;
+		}
+		if (ns->type == NAMESPACE_PRIVATE) {
+			private_ns = ns;
+			private_ns_count++;
+		}
+	}
+
+	if (inbox_ns == NULL) {
+		if (private_ns_count == 1) {
+			/* just one private namespace. we'll assume it's
+			   the INBOX namespace. */
+			private_ns->inbox = TRUE;
+		} else {
+			i_error("namespace configuration error: "
+				"inbox=yes namespace missing");
+			return FALSE;
+		}
+	}
+	return TRUE;
+}
+
 int mail_namespaces_init(pool_t pool, const char *user,
 			 struct mail_namespace **namespaces_r)
 {
@@ -112,6 +147,8 @@
 	}
 
 	if (namespaces != NULL) {
+		if (!namespaces_check(namespaces))
+			return -1;
 		*namespaces_r = namespaces;
 		return 0;
 	}