mail-namespace.h revision c8cf8a605e0ddea7cb36fe04551aeca5090e684b
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen#ifndef MAIL_NAMESPACE_H
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen#define MAIL_NAMESPACE_H
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen
46552a931924c2d743f045e95b08c3ce6beda91aTimo Sirainen#include "mail-user.h"
c5f932968281763df360b9c97cef60f5f80d5e3dTimo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenenum namespace_type {
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen NAMESPACE_PRIVATE,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen NAMESPACE_SHARED,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen NAMESPACE_PUBLIC
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen};
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenenum namespace_flags {
de754cb78f75e8b3b994cddafe41c9ed1467c33dTimo Sirainen /* Namespace contains the INBOX mailbox (there can be only one) */
f29756821a4c6b12b73e4a2a3e1c230117a43773Timo Sirainen NAMESPACE_FLAG_INBOX = 0x01,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* Namespace is visible only by explicitly using its full prefix */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen NAMESPACE_FLAG_HIDDEN = 0x02,
53dfcefa9440a49d703e49193819a79be99c9ba6Timo Sirainen /* Namespace is visible with LIST */
f0d93763f210ecdb85a115fdd0210a16cfc5ff5cTimo Sirainen NAMESPACE_FLAG_LIST = 0x04,
53dfcefa9440a49d703e49193819a79be99c9ba6Timo Sirainen /* Namespace uses its own subscriptions. */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen NAMESPACE_FLAG_SUBSCRIPTIONS = 0x10,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* Namespace is created for internal use only. */
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen NAMESPACE_FLAG_INTERNAL = 0x1000,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* Namespace was created automatically (for shared mailboxes) */
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen NAMESPACE_FLAG_AUTOCREATED = 0x2000
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen};
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
2e78f05b11df23ec2731afaf8f19d5b5240cb29fTimo Sirainenstruct mail_namespace {
2e78f05b11df23ec2731afaf8f19d5b5240cb29fTimo Sirainen /* Namespaces are sorted by their prefix length, "" comes first */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen struct mail_namespace *next;
d1e7425048c61d71f41f737ba947687198842dc2Timo 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;
660b99a7059824676b2b8d6f79b8e15d47df25a2Timo Sirainen size_t prefix_len;
660b99a7059824676b2b8d6f79b8e15d47df25a2Timo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen struct mail_user *user;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen struct mailbox_list *list;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* FIXME: we should support multiple storages in one namespace */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen struct mail_storage *storage;
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen};
b9c76fe9d9ca194816606342da1ddbd9be6bc8abTimo Sirainen
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen/* Called after namespaces has been created */
b9c76fe9d9ca194816606342da1ddbd9be6bc8abTimo Sirainenextern void (*hook_mail_namespaces_created)(struct mail_namespace *namespaces);
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainenint mail_namespaces_init(struct mail_user *user);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenstruct mail_namespace *mail_namespaces_init_empty(struct mail_user *user);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenvoid mail_namespaces_deinit(struct mail_namespace **namespaces);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen/* Destroy a single namespace and remove it from user's namespaces list. */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenvoid mail_namespace_destroy(struct mail_namespace *ns);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen/* Update hierarchy separators in given name to real_sep characters. */
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainenconst char *mail_namespace_fix_sep(struct mail_namespace *ns, const char *name);
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen/* Write virtual mailbox name to dest and return it. Separators are changed to
b9c76fe9d9ca194816606342da1ddbd9be6bc8abTimo Sirainen virtual ones and namespace prefix is inserted except for INBOX. */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenconst char *mail_namespace_get_vname(struct mail_namespace *ns, string_t *dest,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen const char *name);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen/* Returns the hierarchy separator for mailboxes that are listed at root. */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenchar mail_namespace_get_root_sep(const struct mail_namespace *namespaces)
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen ATTR_PURE;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen
e248fe370c4047cee921a91b48edc37944ab0526Timo 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. */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenstruct mail_namespace *
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenmail_namespace_find(struct mail_namespace *namespaces, const char **mailbox);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen/* Like above, but ignore hidden namespaces. */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenstruct mail_namespace *
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenmail_namespace_find_visible(struct mail_namespace *namespaces,
e248fe370c4047cee921a91b48edc37944ab0526Timo 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,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen const char **mailbox);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen/* Like above, but find only from namespaces with subscriptions flag not set. */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenstruct mail_namespace *
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenmail_namespace_find_unsubscribable(struct mail_namespace *namespaces,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen const char **mailbox);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen/* Returns the INBOX namespace */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenstruct mail_namespace *
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenmail_namespace_find_inbox(struct mail_namespace *namespaces);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen/* Returns TRUE if the given namespace matches the mailbox's prefix.
ca843e046e98b12f4730f4b87ee2e1a659c26e78Timo Sirainen Updates mailbox name to be a valid name inside the namespace. */
ca843e046e98b12f4730f4b87ee2e1a659c26e78Timo Sirainenbool mail_namespace_update_name(const struct mail_namespace *ns,
ca843e046e98b12f4730f4b87ee2e1a659c26e78Timo Sirainen const char **mailbox);
ca843e046e98b12f4730f4b87ee2e1a659c26e78Timo 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);
e7dd5065d21c569e5e6ddd713bd345dadd1cf51dTimo Sirainen/* Like _find_prefix(), but ignore trailing separator */
e7dd5065d21c569e5e6ddd713bd345dadd1cf51dTimo Sirainenstruct mail_namespace *
d694a52bce62c52080c3f87a56dcf77030fd2712Timo Sirainenmail_namespace_find_prefix_nosep(struct mail_namespace *namespaces,
d694a52bce62c52080c3f87a56dcf77030fd2712Timo Sirainen const char *prefix);
009217abb57a24a4076092e8e4e165545747839eStephan Bosch
009217abb57a24a4076092e8e4e165545747839eStephan Bosch/* Called internally by mail_storage_create(). */
009217abb57a24a4076092e8e4e165545747839eStephan Boschvoid mail_namespace_init_storage(struct mail_namespace *ns);
009217abb57a24a4076092e8e4e165545747839eStephan Bosch
009217abb57a24a4076092e8e4e165545747839eStephan Bosch#endif
009217abb57a24a4076092e8e4e165545747839eStephan Bosch