mailbox-list.h revision 17a951e7679ee11a926a030e359d70e7130f479d
7cb128dc4cae2a03a742f63ba7afee23c78e3af0Phil Carmody#ifndef MAILBOX_LIST_H
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen#define MAILBOX_LIST_H
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen#include "mail-error.h"
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen#ifdef PATH_MAX
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen# define MAILBOX_LIST_NAME_MAX_LENGTH PATH_MAX
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen#else
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen# define MAILBOX_LIST_NAME_MAX_LENGTH 4096
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen#endif
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen
a1607f6001a9949e1cf9d49eb0aa936dbb4c77ffTimo Sirainenstruct fs;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenstruct mail_namespace;
00d58fcfe8191d6ce7efa801d289a5c0fe88d1aeTimo Sirainenstruct mail_storage;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenstruct mailbox_list;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainenenum mailbox_list_properties {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen /* maildir_name must always be empty */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen MAILBOX_LIST_PROP_NO_MAILDIR_NAME = 0x01,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen /* alt directories not supported */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen MAILBOX_LIST_PROP_NO_ALT_DIR = 0x02,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen /* no support for \noselect directories, only mailboxes */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen MAILBOX_LIST_PROP_NO_NOSELECT = 0x04,
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen /* mail root directory isn't required */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen MAILBOX_LIST_PROP_NO_ROOT = 0x08,
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen /* Automatically create mailbox directories when needed. Normally it's
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen assumed that if a mailbox directory doesn't exist, the mailbox
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen doesn't exist either. */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen MAILBOX_LIST_PROP_AUTOCREATE_DIRS = 0x10
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen};
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenenum mailbox_list_flags {
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen /* Mailboxes are files, not directories. */
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen MAILBOX_LIST_FLAG_MAILBOX_FILES = 0x01,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen /* Namespace already has a mailbox list, don't assign this
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen mailbox list to it. */
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen MAILBOX_LIST_FLAG_SECONDARY = 0x02,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* There are no mail files, only index and/or control files. */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen MAILBOX_LIST_FLAG_NO_MAIL_FILES = 0x04,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen /* LAYOUT=index: Don't delete any files in delete_mailbox(). */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen MAILBOX_LIST_FLAG_NO_DELETES = 0x08
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen};
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenenum mailbox_info_flags {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen MAILBOX_NOSELECT = 0x001,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen MAILBOX_NONEXISTENT = 0x002,
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen MAILBOX_CHILDREN = 0x004,
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen MAILBOX_NOCHILDREN = 0x008,
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen MAILBOX_NOINFERIORS = 0x010,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen MAILBOX_MARKED = 0x020,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen MAILBOX_UNMARKED = 0x040,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen MAILBOX_SUBSCRIBED = 0x080,
bd63b5b860658b01b1f46f26d406e1e4a9dc019aTimo Sirainen MAILBOX_CHILD_SUBSCRIBED = 0x100,
f6c1297c26b355c4aec2a08978f51ec3efecb351Timo Sirainen MAILBOX_CHILD_SPECIALUSE = 0x200,
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen /* Internally used by lib-storage, use mailbox_info.special_use
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen to actually access these: */
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen MAILBOX_SPECIALUSE_ALL = 0x00010000,
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen MAILBOX_SPECIALUSE_ARCHIVE = 0x00020000,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen MAILBOX_SPECIALUSE_DRAFTS = 0x00040000,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen MAILBOX_SPECIALUSE_FLAGGED = 0x00080000,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen MAILBOX_SPECIALUSE_JUNK = 0x00100000,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen MAILBOX_SPECIALUSE_SENT = 0x00200000,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen MAILBOX_SPECIALUSE_TRASH = 0x00400000,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen MAILBOX_SPECIALUSE_IMPORTANT = 0x00800000,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen#define MAILBOX_SPECIALUSE_MASK 0x00ff0000
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen /* Internally used by lib-storage: */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen MAILBOX_SELECT = 0x20000000,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen MAILBOX_MATCHED = 0x40000000
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen};
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenenum mailbox_list_path_type {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen /* Return directory's path (eg. ~/dbox/INBOX) */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen MAILBOX_LIST_PATH_TYPE_DIR,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen MAILBOX_LIST_PATH_TYPE_ALT_DIR,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* Return mailbox path (eg. ~/dbox/INBOX/dbox-Mails) */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen MAILBOX_LIST_PATH_TYPE_MAILBOX,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* Return control directory */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen MAILBOX_LIST_PATH_TYPE_CONTROL,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* Return index directory ("" for in-memory) */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen MAILBOX_LIST_PATH_TYPE_INDEX,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* Return the private index directory (NULL if none) */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen MAILBOX_LIST_PATH_TYPE_INDEX_PRIVATE
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen};
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenenum mailbox_list_file_type {
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen MAILBOX_LIST_FILE_TYPE_UNKNOWN = 0,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen MAILBOX_LIST_FILE_TYPE_FILE,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen MAILBOX_LIST_FILE_TYPE_DIR,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen MAILBOX_LIST_FILE_TYPE_SYMLINK,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen MAILBOX_LIST_FILE_TYPE_OTHER
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen};
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenstruct mailbox_list_settings {
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen const char *layout; /* FIXME: shouldn't be here */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen const char *root_dir;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen const char *index_dir;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen const char *index_pvt_dir;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen const char *control_dir;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen const char *alt_dir; /* FIXME: dbox-specific.. */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* Backend-local directory where volatile data, such as lock files,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen can be temporarily created. This setting allows specifying a
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen separate directory for them to reduce disk I/O on the real storage.
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen The volatile_dir can point to an in-memory filesystem. */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen const char *volatile_dir;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen const char *inbox_path;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen const char *subscription_fname;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen const char *list_index_fname;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* If non-empty, it means that mails exist in a maildir_name
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen subdirectory. eg. if you have a directory containing directories:
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen mail/
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen mail/foo/
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen mail/foo/Maildir
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen If mailbox_name is empty, you have mailboxes "mail", "mail/foo" and
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen "mail/foo/Maildir".
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen If mailbox_name is "Maildir", you have a non-selectable mailbox
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen "mail" and a selectable mailbox "mail/foo". */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen const char *maildir_name;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* if set, store mailboxes under root_dir/mailbox_dir_name/.
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen this setting contains either "" or "dir/". */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen const char *mailbox_dir_name;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* Encode "bad" characters in mailbox names as <escape_char><hex> */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen char escape_char;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* If mailbox name can't be changed reversibly to UTF-8 and back,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen encode the problematic parts using <broken_char><hex> in the
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen user-visible UTF-8 name. The broken_char itself also has to be
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen encoded the same way. */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen char broken_char;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* Use UTF-8 mailbox names on filesystem instead of mUTF-7 */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen bool utf8;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* Don't check/create the alt-dir symlink. */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen bool alt_dir_nocheck;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* Use maildir_name also for index/control directories. This should
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen have been the default since the beginning, but for backwards
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen compatibility it had to be made an option. */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen bool index_control_use_maildir_name;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* Perform mailbox iteration using the index directory instead of the
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen mail root directory. This can be helpful if the indexes are on a
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen faster storage. This could perhaps be made the default at some point,
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen but for now since it's less tested it's optional. */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen bool iter_from_index_dir;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen};
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenstruct mailbox_permissions {
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* The actual uid/gid of the mailbox */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen uid_t file_uid;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen gid_t file_gid;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* mode and GID to use for newly created files/dirs.
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen (gid_t)-1 is used if the default GID can be used. */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen mode_t file_create_mode, dir_create_mode;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen gid_t file_create_gid;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* origin (e.g. path) where the file_create_gid was got from */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen const char *file_create_gid_origin;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen bool gid_origin_is_mailbox_path;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen bool mail_index_permissions_set;
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen};
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen/* register all drivers */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenvoid mailbox_list_register_all(void);
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenvoid mailbox_list_register(const struct mailbox_list *list);
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenvoid mailbox_list_unregister(const struct mailbox_list *list);
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenconst struct mailbox_list *
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenmailbox_list_find_class(const char *driver);
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen/* Returns 0 if ok, -1 if driver was unknown. */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenint mailbox_list_create(const char *driver, struct mail_namespace *ns,
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen const struct mailbox_list_settings *set,
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen enum mailbox_list_flags flags,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen struct mailbox_list **list_r, const char **error_r);
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainenvoid mailbox_list_destroy(struct mailbox_list **list);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainenconst char *
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenmailbox_list_get_driver_name(const struct mailbox_list *list) ATTR_PURE;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenconst struct mailbox_list_settings *
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainenmailbox_list_get_settings(const struct mailbox_list *list) ATTR_PURE;
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainenenum mailbox_list_flags
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenmailbox_list_get_flags(const struct mailbox_list *list) ATTR_PURE;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenstruct mail_namespace *
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenmailbox_list_get_namespace(const struct mailbox_list *list) ATTR_PURE;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenstruct mail_user *
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainenmailbox_list_get_user(const struct mailbox_list *list) ATTR_PURE;
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainenint mailbox_list_get_storage(struct mailbox_list **list, const char *vname,
e07bf3772a2bc075de4915ad0961beb8d083c22dTimo Sirainen struct mail_storage **storage_r);
e07bf3772a2bc075de4915ad0961beb8d083c22dTimo Sirainenvoid mailbox_list_get_default_storage(struct mailbox_list *list,
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen struct mail_storage **storage);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenchar mailbox_list_get_hierarchy_sep(struct mailbox_list *list);
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen/* Returns the mode and GID that should be used when creating new files and
e07bf3772a2bc075de4915ad0961beb8d083c22dTimo Sirainen directories to the specified mailbox. (gid_t)-1 is returned if it's not
e07bf3772a2bc075de4915ad0961beb8d083c22dTimo Sirainen necessary to change the default gid. */
e07bf3772a2bc075de4915ad0961beb8d083c22dTimo Sirainenvoid mailbox_list_get_permissions(struct mailbox_list *list, const char *name,
e07bf3772a2bc075de4915ad0961beb8d083c22dTimo Sirainen struct mailbox_permissions *permissions_r);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen/* Like mailbox_list_get_permissions(), but for creating files/dirs to the
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen mail root directory (or even the root dir itself). */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenvoid mailbox_list_get_root_permissions(struct mailbox_list *list,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen struct mailbox_permissions *permissions_r);
96308127e006bb3b1108093bcf4cc1fd9481cb7aTimo Sirainen/* mkdir() a root directory of given type with proper permissions. The path can
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen be either the root itself or point to a directory under the root. */
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainenint mailbox_list_mkdir_root(struct mailbox_list *list, const char *path,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen enum mailbox_list_path_type type);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen/* Like mailbox_list_mkdir_root(), but don't log an error if it fails. */
d66be2bebfa96e7d3d20e2153f60e6e25dcc9a18Timo Sirainenint mailbox_list_try_mkdir_root(struct mailbox_list *list, const char *path,
e376e08040b5f21ff79a15ae728d2532a34207f6Timo Sirainen enum mailbox_list_path_type type,
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen const char **error_r);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen/* Call mailbox_list_mkdir_root() for index, unless the index root is the
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen same as mailbox root. Returns 1 if ok, 0 if there are no indexes, -1 if
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen error. Calling this multiple times does the check only once. */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenint mailbox_list_mkdir_missing_index_root(struct mailbox_list *list);
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen
fd35227c47190afc832579ca5c76524792701bf7Timo Sirainen/* Returns TRUE if name is ok, FALSE if it can't be safely passed to
fd35227c47190afc832579ca5c76524792701bf7Timo Sirainen mailbox_list_*() functions */
fd35227c47190afc832579ca5c76524792701bf7Timo Sirainenbool mailbox_list_is_valid_name(struct mailbox_list *list,
fd35227c47190afc832579ca5c76524792701bf7Timo Sirainen const char *name, const char **error_r);
fd35227c47190afc832579ca5c76524792701bf7Timo Sirainen
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainenconst char *mailbox_list_get_storage_name(struct mailbox_list *list,
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainen const char *vname);
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainenconst char *mailbox_list_get_vname(struct mailbox_list *list, const char *name);
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainen
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainen/* Get path to specified type of files in mailbox. Returns -1 if an error
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen occurred (e.g. mailbox no longer exists), 0 if there are no files of this
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen type (in-memory index, no alt dir, storage with no files), 1 if path was
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen returned successfully. The path is set to NULL when returning -1/0. */
96308127e006bb3b1108093bcf4cc1fd9481cb7aTimo Sirainenint mailbox_list_get_path(struct mailbox_list *list, const char *name,
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen enum mailbox_list_path_type type,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen const char **path_r);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen/* Get path to the root directory for files of specified type. Returns TRUE
d66be2bebfa96e7d3d20e2153f60e6e25dcc9a18Timo Sirainen if path was returned, FALSE if there are no files of this type. */
d66be2bebfa96e7d3d20e2153f60e6e25dcc9a18Timo Sirainenbool mailbox_list_get_root_path(struct mailbox_list *list,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen enum mailbox_list_path_type type,
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen const char **path_r);
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen/* Like mailbox_list_get_root_path(), but assume that the root directory
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen exists (assert crash if not) */
783278c012551bc2f25f065a8d3ec1a3cfc0d296Timo Sirainenconst char *mailbox_list_get_root_forced(struct mailbox_list *list,
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen enum mailbox_list_path_type type);
5d49cbcf87354f0ddf3b71bc5f0cefdc02b14f68Timo Sirainen/* Returns mailbox's change log, or NULL if it doesn't have one. */
ce3faaaaab3e2d45b023396287e02f88e5c76e74Timo Sirainenstruct mailbox_log *mailbox_list_get_changelog(struct mailbox_list *list);
fd35227c47190afc832579ca5c76524792701bf7Timo Sirainen/* Specify timestamp to use when writing mailbox changes to changelog.
ce3faaaaab3e2d45b023396287e02f88e5c76e74Timo Sirainen The same timestamp is used until stamp is set to (time_t)-1, after which
ce3faaaaab3e2d45b023396287e02f88e5c76e74Timo Sirainen current time is used */
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainenvoid mailbox_list_set_changelog_timestamp(struct mailbox_list *list,
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen time_t stamp);
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen
3e7565a7b39694bcdf448d8eb2a7f0774733297bTimo Sirainen/* Returns a prefix that temporary files should use without conflicting
3e7565a7b39694bcdf448d8eb2a7f0774733297bTimo Sirainen with the namespace. */
3e7565a7b39694bcdf448d8eb2a7f0774733297bTimo Sirainenconst char *mailbox_list_get_temp_prefix(struct mailbox_list *list);
3e7565a7b39694bcdf448d8eb2a7f0774733297bTimo Sirainen/* Returns prefix that's common to all get_temp_prefix() calls.
3e7565a7b39694bcdf448d8eb2a7f0774733297bTimo Sirainen Typically this returns either "temp." or ".temp.". */
3e7565a7b39694bcdf448d8eb2a7f0774733297bTimo Sirainenconst char *mailbox_list_get_global_temp_prefix(struct mailbox_list *list);
3e7565a7b39694bcdf448d8eb2a7f0774733297bTimo Sirainen
3e7565a7b39694bcdf448d8eb2a7f0774733297bTimo Sirainen/* Subscribe/unsubscribe mailbox. There should be no error when
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen subscribing to already subscribed mailbox. Subscribing to
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen unexisting mailboxes is optional. */
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainenint mailbox_list_set_subscribed(struct mailbox_list *list,
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen const char *name, bool set);
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainen
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainen/* Delete a non-selectable mailbox. Fail if the mailbox is selectable. */
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainenint mailbox_list_delete_dir(struct mailbox_list *list, const char *name);
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainen/* Delete a symlinked mailbox. Fail if the mailbox isn't a symlink. */
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainenint mailbox_list_delete_symlink(struct mailbox_list *list, const char *name);
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen/* Returns the error message of last occurred error. */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenconst char * ATTR_NOWARN_UNUSED_RESULT
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenmailbox_list_get_last_error(struct mailbox_list *list,
19e8adccba16ff419f5675b1575358c2956dce83Timo Sirainen enum mail_error *error_r);
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen/* Wrapper for mailbox_list_get_last_error() */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenenum mail_error mailbox_list_get_last_mail_error(struct mailbox_list *list);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenconst char * ATTR_NOWARN_UNUSED_RESULT
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenmailbox_list_get_last_internal_error(struct mailbox_list *list,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen enum mail_error *error_r);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen/* Save the last error until it's popped. This is useful for cases where the
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen list operation has already failed, but the cleanup code path changes the
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen error to something else unwanted. */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenvoid mailbox_list_last_error_push(struct mailbox_list *list);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenvoid mailbox_list_last_error_pop(struct mailbox_list *list);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen/* Create a fs based on the settings in the given mailbox_list. */
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainenint mailbox_list_init_fs(struct mailbox_list *list, const char *driver,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen const char *args, const char *root_dir,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen struct fs **fs_r, const char **error_r);
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen/* Return mailbox_list that was used to create the fs via
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen mailbox_list_init_fs(). */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenstruct mailbox_list *mailbox_list_fs_get_list(struct fs *fs);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen#endif
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen