mail-namespace.h revision eb64c3586d854cddd693f0b811d897399076a441
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch#ifndef MAIL_NAMESPACE_H
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen#define MAIL_NAMESPACE_H
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen#include "mail-user.h"
0536ccb51d41e3078c3a9fa33e509fb4b2420f95Timo Sirainen
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainenstruct mail_storage_callbacks;
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainenenum namespace_type {
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen NAMESPACE_PRIVATE = 0x01,
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen NAMESPACE_SHARED = 0x02,
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen NAMESPACE_PUBLIC = 0x04
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen};
16b5dc27e7db42849510403d37e3629aba14de21Timo Sirainen
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainenenum namespace_flags {
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen /* Namespace contains the user's INBOX mailbox (there can be only
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainen one) */
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen NAMESPACE_FLAG_INBOX_USER = 0x01,
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen /* Namespace contains someone's INBOX. This is set for both user's
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainen INBOX namespace and also for any other users' shared namespaces. */
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainen NAMESPACE_FLAG_INBOX_ANY = 0x02,
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen /* Namespace is visible only by explicitly using its full prefix */
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen NAMESPACE_FLAG_HIDDEN = 0x04,
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen /* Namespace prefix is visible with LIST */
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen NAMESPACE_FLAG_LIST_PREFIX = 0x08,
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen /* Namespace prefix isn't visible with LIST, but child mailboxes are */
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen NAMESPACE_FLAG_LIST_CHILDREN = 0x10,
948b838c8e9896132e3a2d802fb5dad37e8dc716Timo Sirainen /* Namespace uses its own subscriptions. */
948b838c8e9896132e3a2d802fb5dad37e8dc716Timo Sirainen NAMESPACE_FLAG_SUBSCRIPTIONS = 0x20,
948b838c8e9896132e3a2d802fb5dad37e8dc716Timo Sirainen
948b838c8e9896132e3a2d802fb5dad37e8dc716Timo Sirainen /* Namespace was created automatically (for shared mailboxes) */
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainen NAMESPACE_FLAG_AUTOCREATED = 0x1000,
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen /* Namespace has at least some usable mailboxes. Autocreated namespaces
16b5dc27e7db42849510403d37e3629aba14de21Timo Sirainen that don't have usable mailboxes may be removed automatically. */
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen NAMESPACE_FLAG_USABLE = 0x2000,
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen /* Automatically created namespace for a user that doesn't exist. */
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen NAMESPACE_FLAG_UNUSABLE = 0x4000,
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen /* Don't track quota for this namespace */
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen NAMESPACE_FLAG_NOQUOTA = 0x8000,
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen /* Don't enforce ACLs for this namespace */
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen NAMESPACE_FLAG_NOACL = 0x10000
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen};
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen
16b5dc27e7db42849510403d37e3629aba14de21Timo Sirainenstruct mail_namespace {
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen /* Namespaces are sorted by their prefix length, "" comes first */
5a0ac2e5ef482016e00575a7dce83f52c1704732Timo Sirainen struct mail_namespace *next;
5a0ac2e5ef482016e00575a7dce83f52c1704732Timo Sirainen
7823ef73e51bb81a17dcb306aff89016d4ce258fTimo Sirainen enum namespace_type type;
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen char sep, real_sep, sep_str[3];
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen enum namespace_flags flags;
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen char *prefix;
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen size_t prefix_len;
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen /* If non-NULL, this points to a namespace with identical mail location
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen and it should be considered as the primary way to access the
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen mailboxes. This allows for example FTS plugin to avoid duplicating
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen indexes for same mailboxes when they're accessed via different
16b5dc27e7db42849510403d37e3629aba14de21Timo Sirainen namespaces. */
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen struct mail_namespace *alias_for;
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen /* alias_for->alias_chain_next starts each chain. The chain goes
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen through all namespaces that have the same alias_for. */
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen struct mail_namespace *alias_chain_next;
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainen struct mail_user *user, *owner;
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen struct mailbox_list *list;
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen /* FIXME: we should support multiple storages in one namespace */
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen struct mail_storage *storage;
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen const struct mail_namespace_settings *set, *unexpanded_set;
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainen const struct mail_storage_settings *mail_set;
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainen};
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainen
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainenint mail_namespaces_init(struct mail_user *user, const char **error_r);
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainenstruct mail_namespace *mail_namespaces_init_empty(struct mail_user *user);
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainen/* Deinitialize all namespaces. mail_user_deinit() calls this automatically
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen for user's namespaces. */
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainenvoid mail_namespaces_deinit(struct mail_namespace **namespaces);
4ce6338bf945cccfff9e4ce7cc6aa2246851b84aTimo Sirainen
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen/* Set storage callback functions to use in all namespaces. */
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainenvoid mail_namespaces_set_storage_callbacks(struct mail_namespace *namespaces,
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainen struct mail_storage_callbacks *callbacks,
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainen void *context);
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainen
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainen/* Add a new storage to namespace. */
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainenvoid mail_namespace_add_storage(struct mail_namespace *ns,
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen struct mail_storage *storage);
4ce6338bf945cccfff9e4ce7cc6aa2246851b84aTimo Sirainen/* Destroy a single namespace and remove it from user's namespaces list. */
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainenvoid mail_namespace_destroy(struct mail_namespace *ns);
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen/* Update hierarchy separators in given name to real_sep characters. */
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainenconst char *mail_namespace_fix_sep(struct mail_namespace *ns, const char *name);
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainen/* Skip namespace prefix and change hierarchy separators. */
64055bc6d2ed9e25b3b1db3b5b90d0bdb77cd715Timo Sirainenconst char *mail_namespace_get_storage_name(struct mail_namespace *ns,
dd2df6a67f10792ce31a3666197c0b6885893a3aTimo Sirainen const char *name);
64055bc6d2ed9e25b3b1db3b5b90d0bdb77cd715Timo Sirainen/* Write virtual mailbox name to dest and return it. Separators are changed to
64055bc6d2ed9e25b3b1db3b5b90d0bdb77cd715Timo Sirainen virtual ones and namespace prefix is inserted except for INBOX. */
64055bc6d2ed9e25b3b1db3b5b90d0bdb77cd715Timo Sirainenconst char *mail_namespace_get_vname(struct mail_namespace *ns, string_t *dest,
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen const char *name);
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainen/* Returns the default storage to use for newly created mailboxes. */
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainenstruct mail_storage *
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainenmail_namespace_get_default_storage(struct mail_namespace *ns);
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainen
4ce6338bf945cccfff9e4ce7cc6aa2246851b84aTimo Sirainen/* Returns the hierarchy separator for mailboxes that are listed at root. */
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainenchar mail_namespaces_get_root_sep(const struct mail_namespace *namespaces)
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen ATTR_PURE;
0c3ec2538c366bb5583f0b4ca2ce60804756b51cTimo Sirainen
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen/* Returns namespace based on the mailbox name's prefix. Updates mailbox to
0c3ec2538c366bb5583f0b4ca2ce60804756b51cTimo Sirainen be a valid name inside the namespace (prefix is skipped, hierarchy separator
0c3ec2538c366bb5583f0b4ca2ce60804756b51cTimo Sirainen is changed to real_sep). If no namespaces were found, returns NULL. */
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainenstruct mail_namespace *
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainenmail_namespace_find(struct mail_namespace *namespaces, const char **mailbox);
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainen/* Like above, but ignore hidden namespaces. */
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainenstruct mail_namespace *
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainenmail_namespace_find_visible(struct mail_namespace *namespaces,
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainen const char **mailbox);
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainen/* Like above, but find only from namespaces with subscriptions flag set. */
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainenstruct mail_namespace *
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainenmail_namespace_find_subscribable(struct mail_namespace *namespaces,
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainen const char **mailbox);
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainen/* Like above, but find only from namespaces with subscriptions flag not set. */
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainenstruct mail_namespace *
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainenmail_namespace_find_unsubscribable(struct mail_namespace *namespaces,
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainen const char **mailbox);
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainen/* Returns the INBOX namespace */
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainenstruct mail_namespace *
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainenmail_namespace_find_inbox(struct mail_namespace *namespaces);
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainen/* Returns TRUE if the given namespace matches the mailbox's prefix.
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainen Updates mailbox name to be a valid name inside the namespace. */
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainenbool mail_namespace_update_name(const struct mail_namespace *ns,
4afd5082f38342fd688acb5796912329f57dd02cTimo Sirainen const char **mailbox);
4afd5082f38342fd688acb5796912329f57dd02cTimo Sirainen
4afd5082f38342fd688acb5796912329f57dd02cTimo Sirainen/* Find a namespace with given prefix. */
0c3ec2538c366bb5583f0b4ca2ce60804756b51cTimo Sirainenstruct mail_namespace *
0c3ec2538c366bb5583f0b4ca2ce60804756b51cTimo Sirainenmail_namespace_find_prefix(struct mail_namespace *namespaces,
0c3ec2538c366bb5583f0b4ca2ce60804756b51cTimo Sirainen const char *prefix);
0c3ec2538c366bb5583f0b4ca2ce60804756b51cTimo Sirainen/* Like _find_prefix(), but ignore trailing separator */
0c3ec2538c366bb5583f0b4ca2ce60804756b51cTimo Sirainenstruct mail_namespace *
0c3ec2538c366bb5583f0b4ca2ce60804756b51cTimo Sirainenmail_namespace_find_prefix_nosep(struct mail_namespace *namespaces,
0c3ec2538c366bb5583f0b4ca2ce60804756b51cTimo Sirainen const char *prefix);
0c3ec2538c366bb5583f0b4ca2ce60804756b51cTimo Sirainen
0c3ec2538c366bb5583f0b4ca2ce60804756b51cTimo Sirainen/* Called internally by mailbox_list_create(). */
0c3ec2538c366bb5583f0b4ca2ce60804756b51cTimo Sirainenvoid mail_namespace_finish_list_init(struct mail_namespace *ns,
0c3ec2538c366bb5583f0b4ca2ce60804756b51cTimo Sirainen struct mailbox_list *list);
65d8efa66dca27db85f74ee2574188b51569a4c2Timo Sirainen
0c3ec2538c366bb5583f0b4ca2ce60804756b51cTimo Sirainen#endif
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen