mail-namespace.c revision eae6e66545ee1847d5977a6dbebc31df84563e0c
2e37d45867d081db150ab78dad303b9077aea24fTimo Sirainen/* Copyright (c) 2005-2009 Dovecot authors, see the included COPYING file */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenvoid (*hook_mail_namespaces_created)(struct mail_namespace *namespaces);
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainenvoid mail_namespace_add_storage(struct mail_namespace *ns,
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen /* currently we support only a single storage */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenvoid mail_namespace_finish_list_init(struct mail_namespace *ns,
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen /* allow plugins to override real_sep */
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen ns->real_sep = mailbox_list_get_hierarchy_sep(list);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenstatic void mail_namespace_free(struct mail_namespace *ns)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen if (ns->owner != ns->user && ns->owner != NULL)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen struct mail_namespace **ns_p, const char **error_r)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen if (strncmp(ns_set->type, "private", 7) == 0) {
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen } else if (strncmp(ns_set->type, "shared", 6) == 0)
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen else if (strncmp(ns_set->type, "public", 6) == 0)
9e095dd6a77097356aca8216356d4d71ef1bea45Timo Sirainen *error_r = t_strdup_printf("Unknown namespace type: %s",
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen *error_r = t_strdup_printf("Invalid list setting value: %s",
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen i_info("Namespace: type=%s, prefix=%s, sep=%s, "
67c24901ac5e1521e38a91efc452faeb3e2135a1Timo Sirainen "inbox=%s, hidden=%s, list=%s, subscriptions=%s",
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen ns_set->separator == NULL ? "" : ns_set->separator,
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen if (ns->type == NAMESPACE_SHARED && strchr(ns->prefix, '%') != NULL) {
67c24901ac5e1521e38a91efc452faeb3e2135a1Timo Sirainen /* dynamic shared namespace */
67c24901ac5e1521e38a91efc452faeb3e2135a1Timo Sirainen ns->flags |= NAMESPACE_FLAG_NOQUOTA | NAMESPACE_FLAG_NOACL;
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen if (mail_storage_create(ns, driver, 0, &error) < 0) {
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen *error_r = t_strdup_printf("Namespace '%s': %s",
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainennamespace_set_alias_for(struct mail_namespace *ns,
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen const char **error_r)
b3142c8e513bc78da821fa70f479016148fa95e5Timo Sirainen ns->alias_for = mail_namespace_find_prefix(all_namespaces,
b3142c8e513bc78da821fa70f479016148fa95e5Timo Sirainen *error_r = t_strdup_printf("Invalid namespace alias_for: %s",
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen *error_r = t_strdup_printf("Chained namespace alias_for: %s",
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen ns->alias_chain_next = ns->alias_for->alias_chain_next;
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainennamespaces_check(struct mail_namespace *namespaces, const char **error_r)
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen unsigned int subscriptions_count = 0;
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen for (ns = namespaces; ns != NULL; ns = ns->next) {
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen if (namespace_set_alias_for(ns, namespaces, error_r) < 0)
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen if ((ns->flags & NAMESPACE_FLAG_INBOX) != 0) {
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen "There can be only one namespace with "
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen (ns->flags & NAMESPACE_FLAG_LIST_PREFIX) != 0 &&
7d207b1e77a7b5e3fda640e353acfc86d261fedfTimo Sirainen ns->prefix[strlen(ns->prefix)-1] != ns->sep) {
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen "namespace configuration error: "
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen "list=yes requires prefix=%s "
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen if ((ns->flags & (NAMESPACE_FLAG_LIST_PREFIX |
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen "All list=yes namespaces must use "
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen "the same separator";
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen if ((ns->flags & NAMESPACE_FLAG_SUBSCRIPTIONS) != 0)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen "inbox=yes namespace missing";
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen "no list=yes namespaces";
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen "no subscriptions=yes namespaces";
7ef5ca6fb59a318c821a852ae48a2edbb671d7ddTimo Sirainenint mail_namespaces_init(struct mail_user *user, const char **error_r)
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainen struct mail_namespace_settings *const *ns_set;
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainen struct mail_namespace *namespaces, *ns, **ns_p;
9511a40d933181045343110c8101b75887062aaeTimo Sirainen unsigned int i, count;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen mail_set = mail_user_set_get_storage_set(user->set);
count = 0;
for (i = 0; i < count; i++) {
T_BEGIN {
} T_END;
T_BEGIN {
} T_END;
return ns;
void *context)
char *ret, *p;
return name;
return name;
return ret;
const char *name)
if (len > 0) {
const char *name)
struct mail_storage *
return TRUE;
return TRUE;
return TRUE;
return FALSE;
static struct mail_namespace *
const char **mailbox,
bool inbox;
return ns;
return best;
if (best_len > 0) {
return best;
struct mail_namespace *
struct mail_namespace *
const char **mailbox)
struct mail_namespace *
const char **mailbox)
struct mail_namespace *
const char **mailbox)
struct mail_namespace *
return namespaces;
const char **mailbox)
struct mail_namespace *
const char *prefix)
return ns;
return NULL;
struct mail_namespace *
const char *prefix)
return ns;
return NULL;