2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina/* Copyright (c) 2008-2018 Dovecot authors, see the included COPYING file */
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březinastatic bool acl_ns_prefix_exists(struct mail_namespace *ns)
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina if (ns->list->mail_set->mail_shared_explicit_inbox)
d38ffc9c92daeb62de7d28c409bdaeff98f82775Pavel Březina vname = t_strndup(ns->prefix, ns->prefix_len-1);
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina ret = mailbox_exists(box, FALSE, &existence) == 0 &&
710472d946f6c337a095699dfd79134fa8b9eab9Pavel Březinaacl_shared_namespace_add(struct mail_namespace *ns,
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina struct mail_storage *storage, const char *userdomain)
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina struct shared_storage *sstorage = (struct shared_storage *)storage;
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina if (strcmp(ns->user->username, userdomain) == 0) {
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina /* skip ourself */
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina { 'n', t_strcut(userdomain, '@'), "username" },
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina { 'd', i_strchr_to_next(userdomain, '@'), "domain" },
710472d946f6c337a095699dfd79134fa8b9eab9Pavel Březina if (var_expand(str, sstorage->ns_prefix_pattern, tab, &error) <= 0) {
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina i_error("Failed to expand namespace prefix %s: %s",
1b3144586978c47506eaa39db505e6231e3b0c0aJakub Hrozek if (shared_storage_get_namespace(&new_ns, &mailbox) < 0)
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina /* check if there are any mailboxes really visible to us */
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina iter = mailbox_list_iter_init(new_ns->list, "*",
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina while ((info = mailbox_list_iter_next(iter)) != NULL)
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina if (info == NULL && !acl_ns_prefix_exists(new_ns)) {
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina /* no visible mailboxes, remove the namespace */
710472d946f6c337a095699dfd79134fa8b9eab9Pavel Březinaint acl_shared_namespaces_add(struct mail_namespace *ns)
710472d946f6c337a095699dfd79134fa8b9eab9Pavel Březina struct acl_user *auser = ACL_USER_CONTEXT(ns->user);
710472d946f6c337a095699dfd79134fa8b9eab9Pavel Březina struct acl_mailbox_list *alist = ACL_LIST_CONTEXT(ns->list);
710472d946f6c337a095699dfd79134fa8b9eab9Pavel Březina struct mail_storage *storage = mail_namespace_get_default_storage(ns);
573e86dc3156e481ce53d39ac901da2e99cfa0caJakub Hrozek i_assert(ns->type == MAIL_NAMESPACE_TYPE_SHARED);
710472d946f6c337a095699dfd79134fa8b9eab9Pavel Březina i_assert(strcmp(storage->name, MAIL_SHARED_STORAGE_NAME) == 0);
710472d946f6c337a095699dfd79134fa8b9eab9Pavel Březina if (ioloop_time < alist->last_shared_add_check + SHARED_NS_RETRY_SECS) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov /* already added, don't bother rechecking */
710472d946f6c337a095699dfd79134fa8b9eab9Pavel Březina iter = acl_lookup_dict_iterate_visible_init(auser->acl_lookup_dict);
710472d946f6c337a095699dfd79134fa8b9eab9Pavel Březina while ((name = acl_lookup_dict_iterate_visible_next(iter)) != NULL) {