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