]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
autocreate plugin: Added support for namespaces.
authorTimo Sirainen <tss@iki.fi>
Sat, 18 Oct 2008 20:54:50 +0000 (23:54 +0300)
committerTimo Sirainen <tss@iki.fi>
Sat, 18 Oct 2008 20:54:50 +0000 (23:54 +0300)
--HG--
branch : HEAD

src/plugins/autocreate/autocreate-plugin.c

index 7f8042b47bce40e21e7ca03e626d0d34ab992a0b..bf5cf0e616797ef8929f2b217fedeaa5b7622311 100644 (file)
@@ -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)