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;
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;
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 ||
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,