mailbox-list.h revision 17a951e7679ee11a926a030e359d70e7130f479d
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen /* maildir_name must always be empty */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen /* alt directories not supported */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen /* no support for \noselect directories, only mailboxes */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen /* mail root directory isn't required */
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. */
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen /* Mailboxes are files, not directories. */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen /* Namespace already has a mailbox list, don't assign this
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen mailbox list to it. */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* There are no mail files, only index and/or control files. */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen /* LAYOUT=index: Don't delete any files in delete_mailbox(). */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen /* Internally used by lib-storage, use mailbox_info.special_use
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen to actually access these: */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen /* Internally used by lib-storage: */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen /* Return directory's path (eg. ~/dbox/INBOX) */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* Return mailbox path (eg. ~/dbox/INBOX/dbox-Mails) */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* Return control directory */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* Return index directory ("" for in-memory) */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* Return the private index directory (NULL if none) */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen const char *layout; /* FIXME: shouldn't be here */
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 /* 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 If mailbox_name is empty, you have mailboxes "mail", "mail/foo" and
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen If mailbox_name is "Maildir", you have a non-selectable mailbox
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen "mail" and a selectable mailbox "mail/foo". */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* if set, store mailboxes under root_dir/mailbox_dir_name/.
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen this setting contains either "" or "dir/". */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* Encode "bad" characters in mailbox names as <escape_char><hex> */
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 /* Use UTF-8 mailbox names on filesystem instead of mUTF-7 */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen /* Don't check/create the alt-dir symlink. */
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 /* 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 /* The actual uid/gid of the mailbox */
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 /* origin (e.g. path) where the file_create_gid was got from */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen/* register all drivers */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenvoid mailbox_list_register(const struct mailbox_list *list);
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenvoid mailbox_list_unregister(const struct mailbox_list *list);
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainen/* Returns 0 if ok, -1 if driver was unknown. */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenint mailbox_list_create(const char *driver, struct mail_namespace *ns,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen struct mailbox_list **list_r, const char **error_r);
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainenvoid mailbox_list_destroy(struct mailbox_list **list);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenmailbox_list_get_driver_name(const struct mailbox_list *list) ATTR_PURE;
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainenmailbox_list_get_settings(const struct mailbox_list *list) ATTR_PURE;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenmailbox_list_get_flags(const struct mailbox_list *list) ATTR_PURE;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenmailbox_list_get_namespace(const struct mailbox_list *list) ATTR_PURE;
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 Sirainenvoid mailbox_list_get_default_storage(struct mailbox_list *list,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenchar mailbox_list_get_hierarchy_sep(struct mailbox_list *list);
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,
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,
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/* 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,
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);
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,
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/* 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,
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,
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,
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,
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/* 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,
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/* Returns the error message of last occurred error. */
b78bed724fad909bf84008a3eb0f35b5a4379c39Timo Sirainenmailbox_list_get_last_error(struct mailbox_list *list,
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen/* Wrapper for mailbox_list_get_last_error() */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenenum mail_error mailbox_list_get_last_mail_error(struct mailbox_list *list);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenmailbox_list_get_last_internal_error(struct mailbox_list *list,
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/* 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,
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen/* Return mailbox_list that was used to create the fs via
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen mailbox_list_init_fs(). */