changeset 8298:e88c6b43665a HEAD

autocreate plugin: Added support for namespaces.
author Timo Sirainen <tss@iki.fi>
date Sat, 18 Oct 2008 23:54:50 +0300
parents 0d1bd98a6387
children da848018d760
files src/plugins/autocreate/autocreate-plugin.c
diffstat 1 files changed, 27 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/autocreate/autocreate-plugin.c	Sat Oct 18 23:45:41 2008 +0300
+++ b/src/plugins/autocreate/autocreate-plugin.c	Sat Oct 18 23:54:50 2008 +0300
@@ -12,48 +12,54 @@
 static void (*autocreate_next_hook_mail_namespaces_created)
 	(struct mail_namespace *ns);
 
-static void autocreate_mailboxes(struct mail_storage *storage)
+static void autocreate_mailboxes(struct mail_namespace *namespaces)
 {
+	struct mail_namespace *ns;
 	char env_name[20];
-	const char *env;
+	const char *name;
 	unsigned int i;
 
 	i = 1;
-	env = getenv("AUTOCREATE");
-	while (env != NULL) {
-		(void)mail_storage_mailbox_create(storage, env, FALSE);
+	name = getenv("AUTOCREATE");
+	while (name != NULL) {
+		ns = mail_namespace_find(namespaces, &name);
+		if (ns != NULL) {
+			(void)mail_storage_mailbox_create(ns->storage,
+							  name, FALSE);
+		}
+
 		i_snprintf(env_name, sizeof(env_name), "AUTOCREATE%d", ++i);
-		env = getenv(env_name);
+		name = getenv(env_name);
 	}
 }
 
-static void autosubscribe_mailboxes(struct mailbox_list *list)
+static void autosubscribe_mailboxes(struct mail_namespace *namespaces)
 {
+	struct mail_namespace *ns;
 	char env_name[20];
-	const char *env;
+	const char *name;
 	unsigned int i;
 
 	i = 1;
-	env = getenv("AUTOSUBSCRIBE");
-	while (env != NULL) {
-		(void)mailbox_list_set_subscribed(list, env, TRUE);
+	name = getenv("AUTOSUBSCRIBE");
+	while (name != NULL) {
+		ns = mail_namespace_find(namespaces, &name);
+		if (ns != NULL)
+			(void)mailbox_list_set_subscribed(ns->list, name, TRUE);
+
 		i_snprintf(env_name, sizeof(env_name), "AUTOSUBSCRIBE%d", ++i);
-		env = getenv(env_name);
+		name = getenv(env_name);
 	}
 }
 
-static void autocreate_mail_namespaces_created(struct mail_namespace *ns)
+static void
+autocreate_mail_namespaces_created(struct mail_namespace *namespaces)
 {
 	if (autocreate_next_hook_mail_namespaces_created != NULL)
-		autocreate_next_hook_mail_namespaces_created(ns);
+		autocreate_next_hook_mail_namespaces_created(namespaces);
 
-	for (; ns != NULL; ns = ns->next) {
-		if (ns->type == NAMESPACE_PRIVATE) {
-			autocreate_mailboxes(ns->storage);
-			autosubscribe_mailboxes(ns->list);
-			break;
-		}
-	}
+	autocreate_mailboxes(namespaces);
+	autosubscribe_mailboxes(namespaces);
 }
 
 void autocreate_plugin_init(void)