shared-list.c revision cda217260716cfd8d8ec5e56f91708c64c140538
e59faf65ce864fe95dc00f5d52b8323cdbd0608aTimo Sirainen/* Copyright (c) 2008 Dovecot authors, see the included COPYING file */
7a7d2aa11e46195e2d92d6c337d7e78052a5ce67Timo Sirainenextern struct mailbox_list shared_mailbox_list;
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainenstatic struct mailbox_list *shared_list_alloc(void)
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen pool = pool_alloconly_create("shared list", 256);
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainenstatic void shared_list_deinit(struct mailbox_list *list)
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenstatic void shared_list_copy_error(struct mailbox_list *shared_list,
f5a7396b31762a1f876517e13ce9065820139f7cTimo Sirainen const char *str;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen str = mailbox_list_get_last_error(backend_ns->list, &error);
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen mailbox_list_set_error(shared_list, error, str);
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainenshared_is_valid_pattern(struct mailbox_list *list, const char *pattern)
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen if (shared_storage_get_namespace(list->ns->storage, &pattern, &ns) < 0)
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen return mailbox_list_is_valid_pattern(ns->list, pattern);
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainenshared_is_valid_existing_name(struct mailbox_list *list, const char *name)
942302b0247403645394d848b3c620ead262a2a5Timo Sirainen if (shared_storage_get_namespace(list->ns->storage, &name, &ns) < 0)
942302b0247403645394d848b3c620ead262a2a5Timo Sirainen return mailbox_list_is_valid_existing_name(ns->list, name);
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainenshared_is_valid_create_name(struct mailbox_list *list, const char *name)
942302b0247403645394d848b3c620ead262a2a5Timo Sirainen if (shared_storage_get_namespace(list->ns->storage, &name, &ns) < 0)
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen return mailbox_list_is_valid_create_name(ns->list, name);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenstatic const char *
cd8507179823de33d6e8242e10dbc15d136245b5Timo Sirainenshared_list_get_path(struct mailbox_list *list, const char *name,
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen if (list->ns->storage == NULL || name == NULL ||
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen shared_storage_get_namespace(list->ns->storage, &name, &ns) < 0) {
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen /* we can safely say we don't use indexes */
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen /* we don't have a directory we can use. */
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen return mailbox_list_get_path(ns->list, name, type);
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainenshared_list_get_mailbox_name_status(struct mailbox_list *list, const char *name,
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen if (shared_storage_get_namespace(list->ns->storage, &name, &ns) < 0)
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen ret = mailbox_list_get_mailbox_name_status(ns->list, name, status_r);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenstatic const char *
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenshared_list_get_temp_prefix(struct mailbox_list *list, bool global ATTR_UNUSED)
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen i_panic("shared mailbox list: Can't return a temp prefix for '%s'",
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenstatic const char *
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenshared_list_join_refpattern(struct mailbox_list *list,
c93ff0433cc3d348116f75a64f9988fedb86fd18Timo Sirainen const char *ns_ref, *prefix = list->ns->prefix;
c93ff0433cc3d348116f75a64f9988fedb86fd18Timo Sirainen if (*ref != '\0' && strncmp(ref, prefix, prefix_len) == 0)
c93ff0433cc3d348116f75a64f9988fedb86fd18Timo Sirainen else if (*ref == '\0' && strncmp(pattern, prefix, prefix_len) == 0)
c93ff0433cc3d348116f75a64f9988fedb86fd18Timo Sirainen shared_storage_get_namespace(list->ns->storage,
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen return mailbox_list_join_refpattern(ns->list, ref, pattern);
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen /* fallback to default behavior */
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainenshared_list_iter_init(struct mailbox_list *list, const char *const *patterns,
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen struct shared_mailbox_list_iterate_context *ctx;
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen ctx = i_new(struct shared_mailbox_list_iterate_context, 1);
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainenstatic const struct mailbox_info *
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainenshared_list_iter_next(struct mailbox_list_iterate_context *_ctx)
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen struct shared_mailbox_list_iterate_context *ctx =
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen (struct shared_mailbox_list_iterate_context *)_ctx;
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenstatic int shared_list_iter_deinit(struct mailbox_list_iterate_context *_ctx)
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen struct shared_mailbox_list_iterate_context *ctx =
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen (struct shared_mailbox_list_iterate_context *)_ctx;
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainenstatic int shared_list_set_subscribed(struct mailbox_list *list,
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen if (shared_storage_get_namespace(list->ns->storage, &name, &ns) < 0)
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen ret = mailbox_list_set_subscribed(ns->list, name, set);
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainenshared_list_delete_mailbox(struct mailbox_list *list, const char *name)
7f3b826a89bcb7a72759912e99f574b28309fe1bTimo Sirainen if (shared_storage_get_namespace(list->ns->storage, &name, &ns) < 0)
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainen ret = mailbox_list_delete_mailbox(ns->list, name);
6b399f555c9c5c722d4cd5eab8faa02b2a4731d3Timo Sirainenstatic int shared_list_rename_get_ns(struct mailbox_list *list,
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen if (shared_storage_get_namespace(list->ns->storage,
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen shared_storage_get_namespace(list->ns->storage,
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen mailbox_list_set_error(list, MAIL_ERROR_NOTPOSSIBLE,
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen "Can't rename mailboxes across storages");
18ccd19c244f49665fe03cda785efa066d2c38dfTimo Sirainenstatic int shared_list_rename_mailbox(struct mailbox_list *list,
d22301419109ed4a38351715e6760011421dadecTimo Sirainen if (shared_list_rename_get_ns(list, &oldname, &newname, &ns) < 0)
d22301419109ed4a38351715e6760011421dadecTimo Sirainen ret = mailbox_list_rename_mailbox(ns->list, oldname, newname);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenshared_list_rename_mailbox_pre(struct mailbox_list *list,
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen if (shared_list_rename_get_ns(list, &oldname, &newname, &ns) < 0)