Lines Matching refs:ns

33 void mail_namespace_add_storage(struct mail_namespace *ns,
36 if (ns->storage == NULL)
37 ns->storage = storage;
38 array_append(&ns->all_storages, &storage, 1);
41 storage->v.add_list(storage, ns->list);
42 hook_mail_namespace_storage_added(ns);
45 void mail_namespace_finish_list_init(struct mail_namespace *ns,
48 ns->list = list;
49 ns->prefix_len = strlen(ns->prefix);
52 static void mail_namespace_free(struct mail_namespace *ns)
56 if (array_is_created(&ns->all_storages)) {
57 array_foreach_modifiable(&ns->all_storages, storagep)
59 array_free(&ns->all_storages);
61 if (ns->list != NULL)
62 mailbox_list_destroy(&ns->list);
64 if (ns->owner != ns->user && ns->owner != NULL)
65 mail_user_unref(&ns->owner);
66 i_free(ns->prefix);
67 i_free(ns);
92 struct mail_namespace *ns;
94 ns = i_new(struct mail_namespace, 1);
95 ns->refcount = 1;
96 ns->user = user;
97 ns->prefix = i_strdup(ns_set->prefix);
98 ns->set = ns_set;
99 ns->unexpanded_set = unexpanded_set;
100 ns->user_set = user_all_settings;
101 ns->mail_set = mail_user_set_get_driver_settings(user->set_info,
102 ns->user_set, MAIL_STORAGE_SET_DRIVER_NAME);
103 i_array_init(&ns->all_storages, 2);
106 ns->owner = user;
107 ns->type = MAIL_NAMESPACE_TYPE_PRIVATE;
109 ns->type = MAIL_NAMESPACE_TYPE_SHARED;
111 ns->type = MAIL_NAMESPACE_TYPE_PUBLIC;
115 mail_namespace_free(ns);
120 ns->flags |= NAMESPACE_FLAG_LIST_CHILDREN;
122 ns->flags |= NAMESPACE_FLAG_LIST_PREFIX;
126 mail_namespace_free(ns);
131 ns->flags |= NAMESPACE_FLAG_INBOX_USER |
135 ns->flags |= NAMESPACE_FLAG_HIDDEN;
137 ns->flags |= NAMESPACE_FLAG_SUBSCRIPTIONS;
139 *ns_r = ns;
151 struct mail_namespace *ns;
172 &ns, error_r)) < 0)
177 ns->flags |= NAMESPACE_FLAG_UNUSABLE |
181 ns->special_use_mailboxes = namespace_has_special_use_mailboxes(ns_set);
183 if (ns->type == MAIL_NAMESPACE_TYPE_SHARED &&
184 (strchr(ns->prefix, '%') != NULL ||
185 strchr(ns->set->location, '%') != NULL)) {
189 ns->flags |= NAMESPACE_FLAG_NOQUOTA | NAMESPACE_FLAG_NOACL;
195 if (mail_storage_create(ns, driver, 0, &error) < 0) {
197 ns->prefix, error);
198 mail_namespace_free(ns);
202 *ns_p = ns;
206 static bool namespace_is_valid_alias_storage(struct mail_namespace *ns,
209 if (strcmp(ns->storage->name, ns->alias_for->storage->name) != 0) {
213 ns->prefix, ns->alias_for->prefix,
214 ns->storage->name, ns->alias_for->storage->name);
218 if ((ns->storage->class_flags & MAIL_STORAGE_CLASS_FLAG_UNIQUE_ROOT) != 0 &&
219 ns->storage != ns->alias_for->storage) {
223 ns->prefix, ns->alias_for->prefix);
230 namespace_set_alias_for(struct mail_namespace *ns,
234 if (ns->set->alias_for != NULL) {
235 ns->alias_for = mail_namespace_find_prefix(all_namespaces,
236 ns->set->alias_for);
237 if (ns->alias_for == NULL) {
239 ns->set->alias_for);
242 if (ns->alias_for->alias_for != NULL) {
244 ns->set->alias_for);
247 if (!namespace_is_valid_alias_storage(ns, error_r))
250 if ((ns->alias_for->flags & NAMESPACE_FLAG_INBOX_USER) != 0) {
252 ns->flags |= NAMESPACE_FLAG_INBOX_USER;
255 ns->alias_chain_next = ns->alias_for->alias_chain_next;
256 ns->alias_for->alias_chain_next = ns;
261 static bool get_listindex_path(struct mail_namespace *ns, const char **path_r)
265 if (ns->list->set.list_index_fname[0] == '\0' ||
266 !mailbox_list_get_root_path(ns->list,
271 *path_r = t_strconcat(root, "/", ns->list->set.list_index_fname, NULL);
276 namespace_has_duplicate_listindex(struct mail_namespace *ns,
283 if (!ns->mail_set->mailbox_list_index) {
288 if (!get_listindex_path(ns, &ns_list_index_path) ||
289 !mailbox_list_get_root_path(ns->list, MAILBOX_LIST_PATH_TYPE_MAILBOX,
293 for (ns2 = ns->next; ns2 != NULL; ns2 = ns2->next) {
304 ns->prefix, ns2->prefix);
314 struct mail_namespace *ns, *inbox_ns = NULL;
319 for (ns = namespaces; ns != NULL; ns = ns->next) {
320 ns_sep = mail_namespace_get_sep(ns);
321 if (mail_namespace_find_prefix(ns->next, ns->prefix) != NULL) {
324 ns->prefix);
327 if ((ns->flags & NAMESPACE_FLAG_HIDDEN) == 0)
330 if ((ns->flags & NAMESPACE_FLAG_INBOX_USER) != 0) {
336 inbox_ns = ns;
338 if (namespace_set_alias_for(ns, namespaces, error_r) < 0)
340 if (namespace_has_duplicate_listindex(ns, error_r))
343 if (*ns->prefix != '\0' &&
344 (ns->flags & (NAMESPACE_FLAG_LIST_PREFIX |
346 ns->prefix[strlen(ns->prefix)-1] != ns_sep) {
349 "to end with separator %c", ns->prefix, ns_sep);
352 if (*ns->prefix != '\0' &&
353 (ns->flags & (NAMESPACE_FLAG_LIST_PREFIX |
355 ns->prefix[0] == ns_sep) {
358 "not to start with separator", ns->prefix);
361 if ((ns->flags & (NAMESPACE_FLAG_LIST_PREFIX |
363 if ((ns->flags & NAMESPACE_FLAG_LIST_PREFIX) != 0)
373 if ((ns->flags & NAMESPACE_FLAG_SUBSCRIPTIONS) != 0)
399 struct mail_namespace *ns;
404 for (ns = namespaces; ns != NULL; ns = ns->next) {
405 if (ns->prefix_len == 0)
417 &ns, error_r) < 0)
419 ns->next = namespaces;
420 namespaces = ns;
442 ns = namespaces;
443 namespaces = ns->next;
444 mail_namespace_free(ns);
506 struct mail_namespace *ns;
560 &ns, error_r)) < 0)
563 if (mail_storage_create(ns, driver, 0, &error) < 0) {
572 mail_namespace_free(ns);
575 return mail_namespaces_init_finish(ns, error_r);
580 struct mail_namespace *ns;
582 ns = i_new(struct mail_namespace, 1);
583 ns->refcount = 1;
584 ns->user = user;
585 ns->owner = user;
586 ns->prefix = i_strdup("");
587 ns->flags = NAMESPACE_FLAG_INBOX_USER | NAMESPACE_FLAG_INBOX_ANY |
589 ns->user_set = user->set;
590 ns->mail_set = mail_user_set_get_storage_set(user);
591 i_array_init(&ns->all_storages, 2);
592 return ns;
597 struct mail_namespace *ns, *next;
603 ns = *_namespaces;
604 next = ns->next;
606 mail_namespace_free(ns);
615 struct mail_namespace *ns;
618 for (ns = namespaces; ns != NULL; ns = ns->next) {
619 array_foreach(&ns->all_storages, storagep)
624 void mail_namespace_ref(struct mail_namespace *ns)
626 i_assert(ns->refcount > 0);
628 ns->refcount++;
633 struct mail_namespace *ns = *_ns;
635 i_assert(ns->refcount > 0);
639 if (--ns->refcount > 0)
642 i_assert(ns->destroyed);
643 mail_namespace_free(ns);
646 void mail_namespace_destroy(struct mail_namespace *ns)
650 i_assert(!ns->destroyed);
653 for (nsp = &ns->user->namespaces; *nsp != NULL; nsp = &(*nsp)->next) {
654 if (*nsp == ns) {
655 *nsp = ns->next;
659 ns->destroyed = TRUE;
661 mail_namespace_unref(&ns);
665 mail_namespace_get_default_storage(struct mail_namespace *ns)
667 return ns->storage;
670 char mail_namespace_get_sep(struct mail_namespace *ns)
672 return *ns->set->separator != '\0' ? *ns->set->separator :
673 mailbox_list_get_hierarchy_sep(ns->list);
683 static bool mail_namespace_is_usable_prefix(struct mail_namespace *ns,
686 if (strncmp(ns->prefix, mailbox, ns->prefix_len) == 0) {
691 if (inbox && strncmp(ns->prefix, "INBOX", 5) == 0 &&
692 strncmp(ns->prefix+5, mailbox+5, ns->prefix_len-5) == 0) {
699 if (strncmp(ns->prefix, mailbox, ns->prefix_len-1) == 0 &&
700 mailbox[ns->prefix_len-1] == '\0' &&
701 ns->prefix[ns->prefix_len-1] == mail_namespace_get_sep(ns)) {
713 struct mail_namespace *ns = namespaces;
721 while (ns != NULL) {
722 if ((ns->flags & NAMESPACE_FLAG_INBOX_USER) != 0 &&
723 (ns->flags & mask) == flags)
724 return ns;
725 if (*ns->prefix == '\0')
726 best = ns;
727 ns = ns->next;
732 for (; ns != NULL; ns = ns->next) {
733 if (ns->prefix_len >= best_len && (ns->flags & mask) == flags &&
734 mail_namespace_is_usable_prefix(ns, box, inbox)) {
735 best = ns;
736 best_len = ns->prefix_len;
743 mail_namespace_find_shared(struct mail_namespace *ns, const char *mailbox)
745 struct mailbox_list *list = ns->list;
749 return ns;
757 struct mail_namespace *ns;
759 ns = mail_namespace_find_mask(namespaces, mailbox, 0, 0);
760 i_assert(ns != NULL);
762 if (mail_namespace_is_shared_user_root(ns)) {
764 if (strchr(mailbox, mail_namespace_get_sep(ns)) != NULL)
765 return mail_namespace_find_shared(ns, mailbox);
767 return ns;
774 struct mail_namespace *ns;
777 ns = mail_namespace_find(namespaces, *mailbox);
778 if (ns->alias_for != NULL) {
780 mailbox_list_get_storage_name(ns->list, *mailbox);
781 ns = ns->alias_for;
782 *mailbox = mailbox_list_get_vname(ns->list, storage_name);
784 return ns;
829 struct mail_namespace *ns;
832 for (ns = namespaces; ns != NULL; ns = ns->next) {
833 if (ns->prefix_len == len &&
834 strcmp(ns->prefix, prefix) == 0)
835 return ns;
844 struct mail_namespace *ns;
847 for (ns = namespaces; ns != NULL; ns = ns->next) {
848 if (ns->prefix_len == len + 1 &&
849 strncmp(ns->prefix, prefix, len) == 0 &&
850 ns->prefix[len] == mail_namespace_get_sep(ns))
851 return ns;
856 bool mail_namespace_is_shared_user_root(struct mail_namespace *ns)
860 if (ns->type != MAIL_NAMESPACE_TYPE_SHARED)
862 if ((ns->flags & NAMESPACE_FLAG_AUTOCREATED) != 0) {
867 array_foreach(&ns->all_storages, storagep) {