mail-namespace.h revision a64adf62fa33f2463a86f990217b0c9078531a40
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#ifndef MAIL_NAMESPACE_H
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#define MAIL_NAMESPACE_H
c0a708fa3f7b8f4fbca32052da5faf7a0125189dTimo Sirainen
c0a708fa3f7b8f4fbca32052da5faf7a0125189dTimo Sirainen#include "mail-user.h"
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
c49a19168dab6fda80aee16ad799a8a56d3bc18fTimo Sirainenstruct mail_storage_root_settings;
c0a708fa3f7b8f4fbca32052da5faf7a0125189dTimo Sirainen
cd94aeaa294f7cc507206b4b2075852f00e14d61Timo Sirainenenum namespace_type {
cd94aeaa294f7cc507206b4b2075852f00e14d61Timo Sirainen NAMESPACE_PRIVATE,
cd94aeaa294f7cc507206b4b2075852f00e14d61Timo Sirainen NAMESPACE_SHARED,
cd94aeaa294f7cc507206b4b2075852f00e14d61Timo Sirainen NAMESPACE_PUBLIC
cd94aeaa294f7cc507206b4b2075852f00e14d61Timo Sirainen};
a75907609d7c410c9e17beedfafbf28b4439fa8aTimo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenenum namespace_flags {
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* Namespace contains the INBOX mailbox (there can be only one) */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen NAMESPACE_FLAG_INBOX = 0x01,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* Namespace is visible only by explicitly using its full prefix */
5a9e240ebf8d0daaf029973973b52e415148070bTimo Sirainen NAMESPACE_FLAG_HIDDEN = 0x02,
5a9e240ebf8d0daaf029973973b52e415148070bTimo Sirainen /* Namespace prefix is visible with LIST */
d99107ddf4d9bccb710994482daf65276a9d6321Timo Sirainen NAMESPACE_FLAG_LIST_PREFIX = 0x04,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* Namespace prefix isn't visible with LIST, but child mailboxes are */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen NAMESPACE_FLAG_LIST_CHILDREN = 0x08,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* Namespace uses its own subscriptions. */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen NAMESPACE_FLAG_SUBSCRIPTIONS = 0x10,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
cd94aeaa294f7cc507206b4b2075852f00e14d61Timo Sirainen /* Namespace is created for internal use only. */
00fa8dcbc66f56daa737487c9dec7166c37de79eTimo Sirainen NAMESPACE_FLAG_INTERNAL = 0x1000,
00fa8dcbc66f56daa737487c9dec7166c37de79eTimo Sirainen /* Namespace was created automatically (for shared mailboxes) */
00fa8dcbc66f56daa737487c9dec7166c37de79eTimo Sirainen NAMESPACE_FLAG_AUTOCREATED = 0x2000,
00fa8dcbc66f56daa737487c9dec7166c37de79eTimo Sirainen /* Namespace has at least some usable mailboxes. Autocreated namespaces
00fa8dcbc66f56daa737487c9dec7166c37de79eTimo Sirainen that don't have usable mailboxes may be removed automatically. */
00fa8dcbc66f56daa737487c9dec7166c37de79eTimo Sirainen NAMESPACE_FLAG_USABLE = 0x4000
00fa8dcbc66f56daa737487c9dec7166c37de79eTimo Sirainen};
00fa8dcbc66f56daa737487c9dec7166c37de79eTimo Sirainen
00fa8dcbc66f56daa737487c9dec7166c37de79eTimo Sirainenstruct mail_namespace {
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* Namespaces are sorted by their prefix length, "" comes first */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen struct mail_namespace *next;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen enum namespace_type type;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen char sep, real_sep, sep_str[3];
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen enum namespace_flags flags;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen char *prefix;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen size_t prefix_len;
2598b2f36365b52d9754b9348a5be29569293e46Timo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* If non-NULL, this points to a namespace with identical mail location
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen and it should be considered as the primary way to access the
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen mailboxes. This allows for example FTS plugin to avoid duplicating
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen indexes for same mailboxes when they're accessed via different
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen namespaces. */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen struct mail_namespace *alias_for;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* alias_for->alias_chain_next starts each chain. The chain goes
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen through all namespaces that have the same alias_for. */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen struct mail_namespace *alias_chain_next;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
f059a046515f4b2b15a6c2a10a6f12f6166e39a5Timo Sirainen struct mail_user *user, *owner;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen struct mailbox_list *list;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* FIXME: we should support multiple storages in one namespace */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen struct mail_storage *storage;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen const struct mail_namespace_settings *set;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen const struct mail_storage_settings *mail_set;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen};
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
46ec792dd4ccf6c34706c4774228301fafde6aa9Timo Sirainen/* Called after namespaces has been created */
a75907609d7c410c9e17beedfafbf28b4439fa8aTimo Sirainenextern void (*hook_mail_namespaces_created)(struct mail_namespace *namespaces);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenint mail_namespaces_init(struct mail_user *user, const char **error_r);
00fa8dcbc66f56daa737487c9dec7166c37de79eTimo Sirainenstruct mail_namespace *mail_namespaces_init_empty(struct mail_user *user);
00fa8dcbc66f56daa737487c9dec7166c37de79eTimo Sirainenvoid mail_namespaces_deinit(struct mail_namespace **namespaces);
c0a708fa3f7b8f4fbca32052da5faf7a0125189dTimo Sirainen
ad004e44be109684521494b5af2ad1da39b8bb27Timo Sirainen/* Destroy a single namespace and remove it from user's namespaces list. */
97db4761382024093f441e4bc78ba8b6a056504dTimo Sirainenvoid mail_namespace_destroy(struct mail_namespace *ns);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen/* Update hierarchy separators in given name to real_sep characters. */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenconst char *mail_namespace_fix_sep(struct mail_namespace *ns, const char *name);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen/* Write virtual mailbox name to dest and return it. Separators are changed to
ad004e44be109684521494b5af2ad1da39b8bb27Timo Sirainen virtual ones and namespace prefix is inserted except for INBOX. */
64e244defe74f513ce94f33d000a048ddbe2ea23Timo Sirainenconst char *mail_namespace_get_vname(struct mail_namespace *ns, string_t *dest,
c0a708fa3f7b8f4fbca32052da5faf7a0125189dTimo Sirainen const char *name);
12cf3d0e03fc70fb0c8b91bc8fd83b4e14d7cdefTimo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen/* Returns the hierarchy separator for mailboxes that are listed at root. */
97db4761382024093f441e4bc78ba8b6a056504dTimo Sirainenchar mail_namespace_get_root_sep(const struct mail_namespace *namespaces)
bf72c930996df0691932fb1143f360d260f27a06Timo Sirainen ATTR_PURE;
c0a708fa3f7b8f4fbca32052da5faf7a0125189dTimo Sirainen
cd94aeaa294f7cc507206b4b2075852f00e14d61Timo Sirainen/* Returns namespace based on the mailbox name's prefix. Updates mailbox to
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen be a valid name inside the namespace (prefix is skipped, hierarchy separator
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen is changed to real_sep). If no namespaces were found, returns NULL. */
660b99a7059824676b2b8d6f79b8e15d47df25a2Timo Sirainenstruct mail_namespace *
5a9e240ebf8d0daaf029973973b52e415148070bTimo Sirainenmail_namespace_find(struct mail_namespace *namespaces, const char **mailbox);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen/* Like above, but ignore hidden namespaces. */
bbba7d0fce1b6ce5baa2d7ef946eb1b63e2ab518Timo Sirainenstruct mail_namespace *
bbba7d0fce1b6ce5baa2d7ef946eb1b63e2ab518Timo Sirainenmail_namespace_find_visible(struct mail_namespace *namespaces,
c0a708fa3f7b8f4fbca32052da5faf7a0125189dTimo Sirainen const char **mailbox);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen/* Like above, but find only from namespaces with subscriptions flag set. */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenstruct mail_namespace *
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenmail_namespace_find_subscribable(struct mail_namespace *namespaces,
c49a19168dab6fda80aee16ad799a8a56d3bc18fTimo Sirainen const char **mailbox);
9137c55411aa39d41c1e705ddc34d5bd26c65021Timo Sirainen/* Like above, but find only from namespaces with subscriptions flag not set. */
a75907609d7c410c9e17beedfafbf28b4439fa8aTimo Sirainenstruct mail_namespace *
c49a19168dab6fda80aee16ad799a8a56d3bc18fTimo Sirainenmail_namespace_find_unsubscribable(struct mail_namespace *namespaces,
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen const char **mailbox);
c49a19168dab6fda80aee16ad799a8a56d3bc18fTimo Sirainen/* Returns the INBOX namespace */
bf72c930996df0691932fb1143f360d260f27a06Timo Sirainenstruct mail_namespace *
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenmail_namespace_find_inbox(struct mail_namespace *namespaces);
02ccba3d3be96444abd15b5254864c9151bbeb30Timo Sirainen/* Returns TRUE if the given namespace matches the mailbox's prefix.
087939d3fa9c4056419386c9d6c81f147de534cdTimo Sirainen Updates mailbox name to be a valid name inside the namespace. */
02ccba3d3be96444abd15b5254864c9151bbeb30Timo Sirainenbool mail_namespace_update_name(const struct mail_namespace *ns,
bf72c930996df0691932fb1143f360d260f27a06Timo Sirainen const char **mailbox);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen/* Find a namespace with given prefix. */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenstruct mail_namespace *
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenmail_namespace_find_prefix(struct mail_namespace *namespaces,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen const char *prefix);
c49a19168dab6fda80aee16ad799a8a56d3bc18fTimo Sirainen/* Like _find_prefix(), but ignore trailing separator */
c49a19168dab6fda80aee16ad799a8a56d3bc18fTimo Sirainenstruct mail_namespace *
89795c6bbbc52bb382e88bc8617d22092223e9a5Timo Sirainenmail_namespace_find_prefix_nosep(struct mail_namespace *namespaces,
c49a19168dab6fda80aee16ad799a8a56d3bc18fTimo Sirainen const char *prefix);
02ccba3d3be96444abd15b5254864c9151bbeb30Timo Sirainen
3ffb7fd86484c474b42f3f1e981ab0f7168b5df9Timo Sirainen/* Called internally by mail_storage_create(). */
3ffb7fd86484c474b42f3f1e981ab0f7168b5df9Timo Sirainenvoid mail_namespace_init_storage(struct mail_namespace *ns);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
c0a708fa3f7b8f4fbca32052da5faf7a0125189dTimo Sirainen#endif
c0a708fa3f7b8f4fbca32052da5faf7a0125189dTimo Sirainen