shared-list.c revision cda217260716cfd8d8ec5e56f91708c64c140538
e59faf65ce864fe95dc00f5d52b8323cdbd0608aTimo Sirainen/* Copyright (c) 2008 Dovecot authors, see the included COPYING file */
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen#include "lib.h"
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen#include "mailbox-list-private.h"
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen#include "index-storage.h"
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen#include "shared-storage.h"
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenstruct shared_mailbox_list_iterate_context {
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen struct mailbox_list_iterate_context ctx;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen};
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
7a7d2aa11e46195e2d92d6c337d7e78052a5ce67Timo Sirainenextern struct mailbox_list shared_mailbox_list;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainenstatic struct mailbox_list *shared_list_alloc(void)
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen{
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen struct mailbox_list *list;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen pool_t pool;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen pool = pool_alloconly_create("shared list", 256);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen list = p_new(pool, struct mailbox_list, 1);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen *list = shared_mailbox_list;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen list->pool = pool;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen return list;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen}
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainenstatic void shared_list_deinit(struct mailbox_list *list)
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen{
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen pool_unref(&list->pool);
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen}
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenstatic void shared_list_copy_error(struct mailbox_list *shared_list,
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen struct mail_namespace *backend_ns)
f5a7396b31762a1f876517e13ce9065820139f7cTimo Sirainen{
f5a7396b31762a1f876517e13ce9065820139f7cTimo Sirainen const char *str;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen enum mail_error error;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen str = mailbox_list_get_last_error(backend_ns->list, &error);
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen mailbox_list_set_error(shared_list, error, str);
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen}
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainenstatic bool
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainenshared_is_valid_pattern(struct mailbox_list *list, const char *pattern)
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen{
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen struct mail_namespace *ns;
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen if (shared_storage_get_namespace(list->ns->storage, &pattern, &ns) < 0)
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen return FALSE;
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen return mailbox_list_is_valid_pattern(ns->list, pattern);
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen}
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainenstatic bool
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainenshared_is_valid_existing_name(struct mailbox_list *list, const char *name)
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen{
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen struct mail_namespace *ns;
942302b0247403645394d848b3c620ead262a2a5Timo Sirainen
942302b0247403645394d848b3c620ead262a2a5Timo Sirainen if (shared_storage_get_namespace(list->ns->storage, &name, &ns) < 0)
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen return FALSE;
942302b0247403645394d848b3c620ead262a2a5Timo Sirainen return mailbox_list_is_valid_existing_name(ns->list, name);
942302b0247403645394d848b3c620ead262a2a5Timo Sirainen}
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen
942302b0247403645394d848b3c620ead262a2a5Timo Sirainenstatic bool
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainenshared_is_valid_create_name(struct mailbox_list *list, const char *name)
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen{
942302b0247403645394d848b3c620ead262a2a5Timo Sirainen struct mail_namespace *ns;
942302b0247403645394d848b3c620ead262a2a5Timo Sirainen
942302b0247403645394d848b3c620ead262a2a5Timo Sirainen if (shared_storage_get_namespace(list->ns->storage, &name, &ns) < 0)
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen return FALSE;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen return mailbox_list_is_valid_create_name(ns->list, name);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen}
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenstatic const char *
cd8507179823de33d6e8242e10dbc15d136245b5Timo Sirainenshared_list_get_path(struct mailbox_list *list, const char *name,
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen enum mailbox_list_path_type type)
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen{
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen struct mail_namespace *ns;
c93ff0433cc3d348116f75a64f9988fedb86fd18Timo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen if (list->ns->storage == NULL || name == NULL ||
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen shared_storage_get_namespace(list->ns->storage, &name, &ns) < 0) {
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen switch (type) {
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen case MAILBOX_LIST_PATH_TYPE_DIR:
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen case MAILBOX_LIST_PATH_TYPE_MAILBOX:
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen case MAILBOX_LIST_PATH_TYPE_CONTROL:
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen break;
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen case MAILBOX_LIST_PATH_TYPE_INDEX:
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen /* we can safely say we don't use indexes */
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen return "";
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen }
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen /* we don't have a directory we can use. */
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen return NULL;
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen }
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen return mailbox_list_get_path(ns->list, name, type);
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen}
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainenstatic int
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainenshared_list_get_mailbox_name_status(struct mailbox_list *list, const char *name,
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen enum mailbox_name_status *status_r)
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen{
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen struct mail_namespace *ns;
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen int ret;
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen if (shared_storage_get_namespace(list->ns->storage, &name, &ns) < 0)
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen return -1;
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen ret = mailbox_list_get_mailbox_name_status(ns->list, name, status_r);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen if (ret < 0)
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen shared_list_copy_error(list, ns);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen return ret;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen}
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenstatic const char *
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenshared_list_get_temp_prefix(struct mailbox_list *list, bool global ATTR_UNUSED)
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen{
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen i_panic("shared mailbox list: Can't return a temp prefix for '%s'",
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen list->ns->prefix);
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen return NULL;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen}
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenstatic const char *
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenshared_list_join_refpattern(struct mailbox_list *list,
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen const char *ref, const char *pattern)
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen{
c93ff0433cc3d348116f75a64f9988fedb86fd18Timo Sirainen struct mail_namespace *ns;
c93ff0433cc3d348116f75a64f9988fedb86fd18Timo Sirainen const char *ns_ref, *prefix = list->ns->prefix;
c93ff0433cc3d348116f75a64f9988fedb86fd18Timo Sirainen unsigned int prefix_len = strlen(prefix);
c93ff0433cc3d348116f75a64f9988fedb86fd18Timo Sirainen
c93ff0433cc3d348116f75a64f9988fedb86fd18Timo Sirainen if (*ref != '\0' && strncmp(ref, prefix, prefix_len) == 0)
c93ff0433cc3d348116f75a64f9988fedb86fd18Timo Sirainen ns_ref = ref + prefix_len;
c93ff0433cc3d348116f75a64f9988fedb86fd18Timo Sirainen else if (*ref == '\0' && strncmp(pattern, prefix, prefix_len) == 0)
c93ff0433cc3d348116f75a64f9988fedb86fd18Timo Sirainen ns_ref = pattern + prefix_len;
c93ff0433cc3d348116f75a64f9988fedb86fd18Timo Sirainen else
c93ff0433cc3d348116f75a64f9988fedb86fd18Timo Sirainen ns_ref = NULL;
c93ff0433cc3d348116f75a64f9988fedb86fd18Timo Sirainen
c93ff0433cc3d348116f75a64f9988fedb86fd18Timo Sirainen if (ns_ref != NULL &&
c93ff0433cc3d348116f75a64f9988fedb86fd18Timo Sirainen shared_storage_get_namespace(list->ns->storage,
c93ff0433cc3d348116f75a64f9988fedb86fd18Timo Sirainen &ns_ref, &ns) == 0)
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen return mailbox_list_join_refpattern(ns->list, ref, pattern);
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen /* fallback to default behavior */
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen if (*ref != '\0')
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen pattern = t_strconcat(ref, pattern, NULL);
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen return pattern;
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen}
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainenstatic struct mailbox_list_iterate_context *
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainenshared_list_iter_init(struct mailbox_list *list, const char *const *patterns,
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen enum mailbox_list_iter_flags flags)
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen{
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen struct shared_mailbox_list_iterate_context *ctx;
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen ctx = i_new(struct shared_mailbox_list_iterate_context, 1);
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen ctx->ctx.list = list;
8305127d1074cf9a1e25dec9be2735276462079dTimo Sirainen ctx->ctx.flags = flags;
8305127d1074cf9a1e25dec9be2735276462079dTimo Sirainen
8305127d1074cf9a1e25dec9be2735276462079dTimo Sirainen /* FIXME */
8305127d1074cf9a1e25dec9be2735276462079dTimo Sirainen return &ctx->ctx;
8305127d1074cf9a1e25dec9be2735276462079dTimo Sirainen}
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainenstatic const struct mailbox_info *
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainenshared_list_iter_next(struct mailbox_list_iterate_context *_ctx)
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen{
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen struct shared_mailbox_list_iterate_context *ctx =
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen (struct shared_mailbox_list_iterate_context *)_ctx;
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen return NULL;
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen}
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenstatic int shared_list_iter_deinit(struct mailbox_list_iterate_context *_ctx)
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen{
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen struct shared_mailbox_list_iterate_context *ctx =
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen (struct shared_mailbox_list_iterate_context *)_ctx;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
596433ccbca59ce2328dc1d029586154cd937155Timo Sirainen i_free(ctx);
596433ccbca59ce2328dc1d029586154cd937155Timo Sirainen return 0;
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen}
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainenstatic int shared_list_set_subscribed(struct mailbox_list *list,
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen const char *name, bool set)
e5fd6dfd0a492e4708d4dbb7971d7fc5d7b8fd85Timo Sirainen{
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen struct mail_namespace *ns;
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen int ret;
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen if (shared_storage_get_namespace(list->ns->storage, &name, &ns) < 0)
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen return -1;
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen ret = mailbox_list_set_subscribed(ns->list, name, set);
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen if (ret < 0)
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen shared_list_copy_error(list, ns);
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen return ret;
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen}
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainenstatic int
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainenshared_list_delete_mailbox(struct mailbox_list *list, const char *name)
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen{
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen struct mail_namespace *ns;
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen int ret;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
7f3b826a89bcb7a72759912e99f574b28309fe1bTimo Sirainen if (shared_storage_get_namespace(list->ns->storage, &name, &ns) < 0)
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen return -1;
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen ret = mailbox_list_delete_mailbox(ns->list, name);
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen if (ret < 0)
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen shared_list_copy_error(list, ns);
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen return ret;
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen}
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainenstatic int shared_list_rename_get_ns(struct mailbox_list *list,
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen const char **oldname, const char **newname,
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen struct mail_namespace **ns_r)
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen{
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen struct mail_namespace *old_ns, *new_ns;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen if (shared_storage_get_namespace(list->ns->storage,
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen oldname, &old_ns) < 0 ||
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen shared_storage_get_namespace(list->ns->storage,
e10d8b1291090c26b9ef499637e6e632485ca5beTimo Sirainen newname, &new_ns) < 0)
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen return -1;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen if (old_ns != new_ns) {
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen mailbox_list_set_error(list, MAIL_ERROR_NOTPOSSIBLE,
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen "Can't rename mailboxes across storages");
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen return -1;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen }
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen *ns_r = old_ns;
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen return 0;
e5fd6dfd0a492e4708d4dbb7971d7fc5d7b8fd85Timo Sirainen}
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
18ccd19c244f49665fe03cda785efa066d2c38dfTimo Sirainenstatic int shared_list_rename_mailbox(struct mailbox_list *list,
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen const char *oldname, const char *newname)
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen{
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen struct mail_namespace *ns;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen int ret;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
d22301419109ed4a38351715e6760011421dadecTimo Sirainen if (shared_list_rename_get_ns(list, &oldname, &newname, &ns) < 0)
d22301419109ed4a38351715e6760011421dadecTimo Sirainen return -1;
d22301419109ed4a38351715e6760011421dadecTimo Sirainen ret = mailbox_list_rename_mailbox(ns->list, oldname, newname);
d22301419109ed4a38351715e6760011421dadecTimo Sirainen if (ret < 0)
d22301419109ed4a38351715e6760011421dadecTimo Sirainen shared_list_copy_error(list, ns);
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen return ret;
e5fd6dfd0a492e4708d4dbb7971d7fc5d7b8fd85Timo Sirainen}
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenstatic int
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenshared_list_rename_mailbox_pre(struct mailbox_list *list,
ecdce39e5ef4b62eefa9f5818f17d153fd5d710aTimo Sirainen const char *oldname, const char *newname)
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen{
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen struct mail_namespace *ns;
d22301419109ed4a38351715e6760011421dadecTimo Sirainen int ret;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen if (shared_list_rename_get_ns(list, &oldname, &newname, &ns) < 0)
d22301419109ed4a38351715e6760011421dadecTimo Sirainen return -1;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen ret = ns->list->v.rename_mailbox_pre(ns->list, oldname, newname);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen if (ret < 0)
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen shared_list_copy_error(list, ns);
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen return ret;
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen}
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainenstruct mailbox_list shared_mailbox_list = {
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen MEMBER(name) "shared",
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen MEMBER(hierarchy_sep) '/',
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen MEMBER(mailbox_name_max_length) PATH_MAX,
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen {
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen shared_list_alloc,
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen shared_list_deinit,
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen shared_is_valid_pattern,
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen shared_is_valid_existing_name,
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen shared_is_valid_create_name,
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen shared_list_get_path,
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen shared_list_get_mailbox_name_status,
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen shared_list_get_temp_prefix,
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen shared_list_join_refpattern,
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen shared_list_iter_init,
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen shared_list_iter_next,
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen shared_list_iter_deinit,
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen NULL,
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen shared_list_set_subscribed,
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen shared_list_delete_mailbox,
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen shared_list_rename_mailbox,
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen shared_list_rename_mailbox_pre
eca30f1fe8556c46abc75c94d03f59b2e89d4162Timo Sirainen }
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen};
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen