mailbox-list-subscriptions.c revision 3568ea090b5a072e498438e74db23b98103ff2de
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden/* Copyright (c) 2002-2013 Dovecot authors, see the included COPYING file */
4dc8bf8db4b0422db4c958bb68a450f04c56431aJoel Pearsonstruct subscriptions_mailbox_list_iterate_context {
4dc8bf8db4b0422db4c958bb68a450f04c56431aJoel Pearsonmailbox_list_subscription_fill_one(struct mailbox_list *list,
965c9c7794176a6815b197f53aa146a29e181b99Neil Madden const char *name)
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden struct mail_namespace *ns, *default_ns = list->ns;
4dc8bf8db4b0422db4c958bb68a450f04c56431aJoel Pearson struct mail_namespace *namespaces = default_ns->user->namespaces;
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden unsigned int len;
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden /* default_ns is whatever namespace we're currently listing.
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden if we have e.g. prefix="" and prefix=pub/ namespaces with
4dc8bf8db4b0422db4c958bb68a450f04c56431aJoel Pearson pub/ namespace having subscriptions=no, we want to:
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden 1) when listing "" namespace we want to skip over any names
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden that begin with pub/. */
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden /* we could have two-level namespace: ns/ns2/ */
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden ns_name = t_strconcat(src_list->ns->prefix, name, NULL);
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden ns = mail_namespace_find_unsubscribable(namespaces, ns_name);
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden /* prefix="" namespace=no : catching this is basically the
965c9c7794176a6815b197f53aa146a29e181b99Neil Madden same as not finding any namespace. */
965c9c7794176a6815b197f53aa146a29e181b99Neil Madden /* 2) when listing pub/ namespace, skip over entries that don't
965c9c7794176a6815b197f53aa146a29e181b99Neil Madden begin with pub/. */
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden (default_ns->flags & NAMESPACE_FLAG_SUBSCRIPTIONS) == 0)
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden /* When listing shared namespace's subscriptions, we need to
965c9c7794176a6815b197f53aa146a29e181b99Neil Madden autocreate all the visible child namespaces. their subscriptions
965c9c7794176a6815b197f53aa146a29e181b99Neil Madden are listed later. */
965c9c7794176a6815b197f53aa146a29e181b99Neil Madden if (ns != NULL && ns->type == MAIL_NAMESPACE_TYPE_SHARED &&
965c9c7794176a6815b197f53aa146a29e181b99Neil Madden (ns->flags & NAMESPACE_FLAG_AUTOCREATED) == 0) {
965c9c7794176a6815b197f53aa146a29e181b99Neil Madden /* we'll need to get the namespace autocreated.
965c9c7794176a6815b197f53aa146a29e181b99Neil Madden one easy way is to just ask to join a reference and
965c9c7794176a6815b197f53aa146a29e181b99Neil Madden (void)mailbox_list_join_refpattern(ns->list, ns_name, "");
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden /* When listing pub/ namespace, skip over the namespace
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden prefix in the name. the rest of the name is storage_name. */
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden else if (strncmp(ns_name, ns->prefix, ns->prefix_len) == 0) {
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden /* "pub" entry - this shouldn't be possible normally, because
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden it should be saved as "pub/", but handle it anyway */
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden i_assert(strncmp(ns_name, ns->prefix, ns->prefix_len-1) == 0 &&
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden if (len > 0 && name[len-1] == mail_namespace_get_sep(ns)) {
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden /* entry ends with hierarchy separator, remove it.
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden this exists mainly for backwards compatibility with old
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden Dovecot versions and non-Dovecot software that added them */
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden if (!mailbox_list_is_valid_name(list, name, &error)) {
4dc8bf8db4b0422db4c958bb68a450f04c56431aJoel Pearson /* we'll only get into trouble if we show this */
4dc8bf8db4b0422db4c958bb68a450f04c56431aJoel Pearson node = mailbox_tree_get(list->subscriptions, vname, &created);
4dc8bf8db4b0422db4c958bb68a450f04c56431aJoel Pearsonint mailbox_list_subscriptions_refresh(struct mailbox_list *src_list,
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden /* src_list is subscriptions=yes, dest_list is subscriptions=no
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden (or the same as src_list) */
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden i_assert((src_list->ns->flags & NAMESPACE_FLAG_SUBSCRIPTIONS) != 0);
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden dest_list->subscriptions = mailbox_tree_init(sep);
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden MAILBOX_LIST_PATH_TYPE_CONTROL : MAILBOX_LIST_PATH_TYPE_DIR;
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden if (!mailbox_list_get_root_path(src_list, type, &path) ||
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden /* no subscriptions (e.g. pop3c) */
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden path = t_strconcat(path, "/", src_list->set.subscription_fname, NULL);
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden /* no subscriptions */
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden mailbox_list_set_critical(dest_list, "stat(%s) failed: %m",
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden if (st.st_mtime == dest_list->subscriptions_mtime &&
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden st.st_mtime < dest_list->subscriptions_read_time-1) {
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden /* we're up to date */
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden dest_list->subscriptions_read_time = ioloop_time;
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden subsfile_ctx = subsfile_list_init(dest_list, path);
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden if (subsfile_list_fstat(subsfile_ctx, &st) == 0)
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden while ((name = subsfile_list_next(subsfile_ctx)) != NULL) T_BEGIN {
c8ab19d28fde5eda3b2daab4b1124887681fedf9Neil Madden ret = mailbox_list_subscription_fill_one(dest_list,
} T_END;
if (ret < 0) {
} T_END;
const char *vname,
bool default_nonexistent)
const char *name;
if (default_nonexistent)
struct mailbox_list_iterate_context *
const char *const *patterns,
const struct mailbox_info *
int ret;
return NULL;
MAILBOX_NOCHILDREN)) == 0) {
if (ret < 0)
else if (ret == 0)
return ret;