Skip to content

Commit

Permalink
lib-storage: Changed mail storage initialization.
Browse files Browse the repository at this point in the history
Most importantly require mail_namespaces_init_finish() after
mail_storage_create(). This was needed so that
mail_namespaces_created/added hook would always have the ns->list set, which
is required for several of the hooks to work (e.g. mailbox list index)
  • Loading branch information
sirainen committed May 2, 2016
1 parent 9e6c76c commit fc4e528
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/lib-storage/index/raw/raw-storage.c
Expand Up @@ -47,6 +47,8 @@ raw_storage_create_from_set(const struct setting_parser_info *set_info,

if (mail_storage_create(ns, "raw", 0, &error) < 0)
i_fatal("Couldn't create internal raw storage: %s", error);
if (mail_namespaces_init_finish(ns, &error) < 0)
i_fatal("Couldn't create internal raw namespace: %s", error);
return user;
}

Expand Down
22 changes: 9 additions & 13 deletions src/lib-storage/mail-namespace.c
Expand Up @@ -341,7 +341,9 @@ int mail_namespaces_init_finish(struct mail_namespace *namespaces,
ns->next = namespaces;
namespaces = ns;
}
if (!namespaces_check(namespaces, error_r)) {
if (namespaces->user->autocreated) {
/* e.g. raw user - don't check namespaces' validity */
} else if (!namespaces_check(namespaces, error_r)) {
*error_r = t_strconcat("namespace configuration error: ",
*error_r, NULL);
while (namespaces != NULL) {
Expand Down Expand Up @@ -401,11 +403,12 @@ int mail_namespaces_init(struct mail_user *user, const char **error_r)
}
}

if (namespaces != NULL)
return mail_namespaces_init_finish(namespaces, error_r);

/* no namespaces defined, create a default one */
return mail_namespaces_init_location(user, NULL, error_r);
if (namespaces == NULL) {
/* no namespaces defined, create a default one */
if (mail_namespaces_init_location(user, NULL, error_r) < 0)
return -1;
}
return mail_namespaces_init_finish(namespaces, error_r);
}

int mail_namespaces_init_location(struct mail_user *user, const char *location,
Expand Down Expand Up @@ -489,12 +492,6 @@ int mail_namespaces_init_location(struct mail_user *user, const char *location,
mail_namespace_free(ns);
return -1;
}
user->namespaces = ns;

T_BEGIN {
hook_mail_namespaces_added(ns);
hook_mail_namespaces_created(ns);
} T_END;
return 0;
}

Expand All @@ -511,7 +508,6 @@ struct mail_namespace *mail_namespaces_init_empty(struct mail_user *user)
NAMESPACE_FLAG_LIST_PREFIX | NAMESPACE_FLAG_SUBSCRIPTIONS;
ns->mail_set = mail_user_set_get_storage_set(user);
i_array_init(&ns->all_storages, 2);
user->namespaces = ns;
return ns;
}

Expand Down
1 change: 1 addition & 0 deletions src/lib-storage/mail-user.c
Expand Up @@ -288,6 +288,7 @@ void mail_user_add_namespace(struct mail_user *user,

tmp = &user->namespaces;
for (; *tmp != NULL; tmp = &(*tmp)->next) {
i_assert(*tmp != ns);
if (strlen(ns->prefix) < strlen((*tmp)->prefix))
break;
}
Expand Down

0 comments on commit fc4e528

Please sign in to comment.