mail-namespace.h revision 2b95b7a9f4f06e7640ef431d9e6efc2423cacf1a
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen#ifndef __MAIL_NAMESPACE_H
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen#define __MAIL_NAMESPACE_H
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainenenum namespace_type {
16f816d3f3c32ae3351834253f52ddd0212bcbf3Timo Sirainen NAMESPACE_PRIVATE,
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen NAMESPACE_SHARED,
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen NAMESPACE_PUBLIC
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen};
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainenstruct mail_namespace {
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen /* Namespaces are sorted by their prefix length, "" comes first */
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen struct mail_namespace *next;
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen enum namespace_type type;
a942db367328a91e3a0b6c810bb8abbcb7663707Timo Sirainen char sep, real_sep, sep_str[3];
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen const char *prefix;
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen size_t prefix_len;
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen
0d0451206a91e9f96e522075dce28a89adc2325dTimo Sirainen bool inbox, hidden, list_prefix, subscriptions;
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen struct mailbox_list *list;
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen /* FIXME: we should support multiple storages in one namespace */
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen struct mail_storage *storage;
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen};
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainenint mail_namespaces_init(pool_t pool, const char *user,
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen struct mail_namespace **namespaces_r);
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainenstruct mail_namespace *mail_namespaces_init_empty(pool_t pool);
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainenvoid mail_namespaces_deinit(struct mail_namespace **namespaces);
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen/* Update hierarchy separators in given name to real_sep characters. */
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainenconst char *mail_namespace_fix_sep(struct mail_namespace *ns, const char *name);
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen/* Returns the hierarchy separator for mailboxes that are listed at root. */
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainenchar mail_namespace_get_root_sep(struct mail_namespace *namespaces);
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen/* Returns namespace based on the mailbox name's prefix. Updates mailbox to
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen be a valid name inside the namespace (prefix is skipped, hierarchy separator
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen is changed to real_sep). If no namespaces were found, returns NULL. */
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainenstruct mail_namespace *
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainenmail_namespace_find(struct mail_namespace *namespaces, const char **mailbox);
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen/* Like above, but ignore hidden namespaces. */
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainenstruct mail_namespace *
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainenmail_namespace_find_visible(struct mail_namespace *namespaces,
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen const char **mailbox);
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen/* Returns TRUE if the given namespace matches the mailbox's prefix.
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen Updates mailbox name to be a valid name inside the namespace. */
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainenbool mail_namespace_update_name(struct mail_namespace *ns,
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen const char **mailbox);
0d0451206a91e9f96e522075dce28a89adc2325dTimo Sirainen
0d0451206a91e9f96e522075dce28a89adc2325dTimo Sirainen/* Find a namespace with given prefix. */
0d0451206a91e9f96e522075dce28a89adc2325dTimo Sirainenstruct mail_namespace *
0d0451206a91e9f96e522075dce28a89adc2325dTimo Sirainenmail_namespace_find_prefix(struct mail_namespace *namespaces,
0d0451206a91e9f96e522075dce28a89adc2325dTimo Sirainen const char *prefix);
0d0451206a91e9f96e522075dce28a89adc2325dTimo Sirainen
0d0451206a91e9f96e522075dce28a89adc2325dTimo Sirainen#endif
0d0451206a91e9f96e522075dce28a89adc2325dTimo Sirainen