]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Add mail_namespace_alloc()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 14 Nov 2016 17:33:37 +0000 (18:33 +0100)
committerGitLab <gitlab@git.dovecot.net>
Fri, 18 Nov 2016 11:42:01 +0000 (13:42 +0200)
This makes it easier to create new namespaces.
Based on patch by Jeff Sipek

src/lib-storage/mail-namespace.c
src/lib-storage/mail-namespace.h

index d6db49b1f7d183820bffad2e2cbfd4c49a3197dc..91ad9f6394ba078a063fb490b30c4dd6c0fa1c7f 100644 (file)
@@ -82,19 +82,23 @@ namespace_has_special_use_mailboxes(struct mail_namespace_settings *ns_set)
        return FALSE;
 }
 
-int mail_namespaces_init_add(struct mail_user *user,
-                            struct mail_namespace_settings *ns_set,
-                            struct mail_namespace_settings *unexpanded_ns_set,
-                            struct mail_namespace **ns_p, const char **error_r)
+int mail_namespace_alloc(struct mail_user *user,
+                        struct mail_namespace_settings *ns_set,
+                        struct mail_namespace_settings *unexpanded_set,
+                        struct mail_namespace **ns_r,
+                        const char **error_r)
 {
-       const struct mail_storage_settings *mail_set =
-               mail_user_set_get_storage_set(user);
-        struct mail_namespace *ns;
-       const char *driver, *error;
+       struct mail_namespace *ns;
 
        ns = i_new(struct mail_namespace, 1);
        ns->refcount = 1;
        ns->user = user;
+       ns->prefix = i_strdup(ns_set->prefix);
+       ns->set = ns_set;
+       ns->unexpanded_set = unexpanded_set;
+       ns->mail_set = mail_user_set_get_storage_set(user);
+       i_array_init(&ns->all_storages, 2);
+
        if (strcmp(ns_set->type, "private") == 0) {
                ns->owner = user;
                ns->type = MAIL_NAMESPACE_TYPE_PRIVATE;
@@ -128,11 +132,22 @@ int mail_namespaces_init_add(struct mail_user *user,
                ns->flags |= NAMESPACE_FLAG_HIDDEN;
        if (ns_set->subscriptions)
                ns->flags |= NAMESPACE_FLAG_SUBSCRIPTIONS;
-       if (ns_set == &prefixless_ns_set) {
-               /* autocreated prefix="" namespace */
-               ns->flags |= NAMESPACE_FLAG_UNUSABLE |
-                       NAMESPACE_FLAG_AUTOCREATED;
-       }
+
+       *ns_r = ns;
+
+       return 0;
+}
+
+int mail_namespaces_init_add(struct mail_user *user,
+                            struct mail_namespace_settings *ns_set,
+                            struct mail_namespace_settings *unexpanded_ns_set,
+                            struct mail_namespace **ns_p, const char **error_r)
+{
+       const struct mail_storage_settings *mail_set =
+               mail_user_set_get_storage_set(user);
+       struct mail_namespace *ns;
+       const char *driver, *error;
+       int ret;
 
        if (*ns_set->location == '\0')
                ns_set->location = mail_set->mail_location;
@@ -149,12 +164,17 @@ int mail_namespaces_init_add(struct mail_user *user,
                        ns_set->subscriptions ? "yes" : "no", ns_set->location);
        }
 
-       ns->set = ns_set;
-       ns->unexpanded_set = unexpanded_ns_set;
-       ns->mail_set = mail_set;
-       ns->prefix = i_strdup(ns_set->prefix);
+       if ((ret = mail_namespace_alloc(user, ns_set, unexpanded_ns_set,
+                                       &ns, error_r)) < 0)
+               return ret;
+
+       if (ns_set == &prefixless_ns_set) {
+               /* autocreated prefix="" namespace */
+               ns->flags |= NAMESPACE_FLAG_UNUSABLE |
+                       NAMESPACE_FLAG_AUTOCREATED;
+       }
+
        ns->special_use_mailboxes = namespace_has_special_use_mailboxes(ns_set);
-       i_array_init(&ns->all_storages, 2);
 
        if (ns->type == MAIL_NAMESPACE_TYPE_SHARED &&
            (strchr(ns->prefix, '%') != NULL ||
index a789f80b709788f6f7932d6a406beaaed073f807..474b5dff78e7e339c409d0eb74d789d9ce7ba886 100644 (file)
@@ -77,15 +77,29 @@ struct mail_namespace {
        bool destroyed:1;
 };
 
+
+/* Allocate a new namespace, and fill it based on the passed in settings.
+   This is the most low-level namespace creation function. The storage isn't
+   initialized for the namespace. */
+int mail_namespace_alloc(struct mail_user *user,
+                        struct mail_namespace_settings *ns_set,
+                        struct mail_namespace_settings *unexpanded_set,
+                        struct mail_namespace **ns_r,
+                        const char **error_r);
+
+/* Add and initialize namespaces to user based on namespace settings. */
 int mail_namespaces_init(struct mail_user *user, const char **error_r);
+/* Add and initialize INBOX namespace to user based on the given location. */
 int mail_namespaces_init_location(struct mail_user *user, const char *location,
                                  const char **error_r) ATTR_NULL(2);
+/* Add an empty namespace to user. */
 struct mail_namespace *mail_namespaces_init_empty(struct mail_user *user);
 /* Deinitialize all namespaces. mail_user_deinit() calls this automatically
    for user's namespaces. */
 void mail_namespaces_deinit(struct mail_namespace **namespaces);
 
-/* Manually initialize namespaces one by one. */
+/* Allocate a new namespace and initialize it. This is called automatically by
+   mail_namespaces_init(). */
 int mail_namespaces_init_add(struct mail_user *user,
                             struct mail_namespace_settings *ns_set,
                             struct mail_namespace_settings *unexpanded_ns_set,