bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2008-2018 Dovecot authors, see the included COPYING file */
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Boschextern struct mailbox_list shared_mailbox_list;
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Boschstatic struct mailbox_list *shared_list_alloc(void)
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch pool = pool_alloconly_create("shared list", 2048);
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Boschstatic void shared_list_deinit(struct mailbox_list *list)
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Boschstatic void shared_list_copy_error(struct mailbox_list *shared_list,
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch str = mailbox_list_get_last_error(backend_ns->list, &error);
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch mailbox_list_set_error(shared_list, error, str);
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Boschshared_get_storage(struct mailbox_list **list, const char *vname,
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch name = mailbox_list_get_storage_name(*list, vname);
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch if (*name == '\0' && (ns->flags & NAMESPACE_FLAG_AUTOCREATED) == 0) {
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch /* trying to access the shared/ prefix itself */
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch if (shared_storage_get_namespace(&ns, &name) < 0)
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch return mailbox_list_get_storage(list, vname, storage_r);
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Boschstatic char shared_list_get_hierarchy_sep(struct mailbox_list *list ATTR_UNUSED)
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Boschshared_list_get_path(struct mailbox_list *list, const char *name,
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch enum mailbox_list_path_type type, const char **path_r)
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch if (mail_namespace_get_default_storage(list->ns) == NULL ||
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch shared_storage_get_namespace(&ns, &name) < 0) {
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch /* we don't have a directory we can use. */
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch return mailbox_list_get_path(ns->list, name, type, path_r);
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Boschstatic const char *
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Boschshared_list_get_temp_prefix(struct mailbox_list *list, bool global ATTR_UNUSED)
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch i_panic("shared mailbox list: Can't return a temp prefix for '%s'",
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Boschstatic const char *
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Boschshared_list_join_refpattern(struct mailbox_list *list,
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch const char *ns_ref, *prefix = list->ns->prefix;
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch if (*ref != '\0' && strncmp(ref, prefix, prefix_len) == 0)
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch shared_storage_get_namespace(&ns, &ns_ref) == 0)
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch return mailbox_list_join_refpattern(ns->list, ref, pattern);
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch /* fallback to default behavior */
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Boschshared_list_create_missing_namespaces(struct mailbox_list *list,
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch const char *const *patterns)
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch unsigned int i;
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch /* we'll require that the pattern begins with the list's
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch namespace prefix. we could also handle other patterns
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch (e.g. %/user/%), but it's more of a theoretical problem. */
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch list_pat = patterns[i] + list->ns->prefix_len;
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch (void)shared_storage_get_namespace(&ns, &name);
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Boschshared_list_iter_init(struct mailbox_list *list, const char *const *patterns,
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch pool = pool_alloconly_create("mailbox list shared iter", 1024);
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch ctx = p_new(pool, struct mailbox_list_iterate_context, 1);
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch ctx->glob = imap_match_init_multiple(pool, patterns, FALSE, sep);
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch array_create(&ctx->module_contexts, pool, sizeof(void *), 5);
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch if ((flags & MAILBOX_LIST_ITER_SELECT_SUBSCRIBED) == 0 &&
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch (list->ns->flags & NAMESPACE_FLAG_AUTOCREATED) == 0) T_BEGIN {
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch shared_list_create_missing_namespaces(list, patterns);
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Boschstatic const struct mailbox_info *
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Boschshared_list_iter_next(struct mailbox_list_iterate_context *ctx ATTR_UNUSED)
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Boschstatic int shared_list_iter_deinit(struct mailbox_list_iterate_context *ctx)
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Boschshared_list_subscriptions_refresh(struct mailbox_list *src_list,
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch dest_list->subscriptions = mailbox_tree_init(sep);
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Boschstatic int shared_list_set_subscribed(struct mailbox_list *list,
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch if (shared_storage_get_namespace(&ns, &name) < 0)
30116399ebac74cf4ea0daefb65c9fba742e0773Stephan Bosch ret = mailbox_list_set_subscribed(ns->list, name, set);
if (ret < 0)
return ret;
if (ret < 0)
return ret;
if (ret < 0)
return ret;
const char **oldname,
const char **newname,
if (ret < 0)
return ret;
.props = 0,