From 68f5090e9de1285077358a8eda2576aea88a047f Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sat, 18 Oct 2008 23:54:50 +0300 Subject: [PATCH] autocreate plugin: Added support for namespaces. --HG-- branch : HEAD --- src/plugins/autocreate/autocreate-plugin.c | 48 ++++++++++++---------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/plugins/autocreate/autocreate-plugin.c b/src/plugins/autocreate/autocreate-plugin.c index 7f8042b47b..bf5cf0e616 100644 --- a/src/plugins/autocreate/autocreate-plugin.c +++ b/src/plugins/autocreate/autocreate-plugin.c @@ -12,48 +12,54 @@ const char *autocreate_plugin_version = PACKAGE_VERSION; 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) -- 2.47.3