mailbox-list.h revision 61e84692827b6a64912343f515c984853021483a
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch#ifndef __MAILBOX_LIST_H
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi#define __MAILBOX_LIST_H
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi#include "mail-error.h"
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomistruct mail_namespace;
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomistruct mailbox_list;
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomistruct mailbox_list_iterate_context;
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomienum mailbox_list_flags {
a371ea8bd48d45548cd7aa16d4f5aeb38ba48c91Aki Tuomi /* Print debugging information while initializing the driver */
a371ea8bd48d45548cd7aa16d4f5aeb38ba48c91Aki Tuomi MAILBOX_LIST_FLAG_DEBUG = 0x01,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi /* Allow full filesystem access with absolute or relative paths. */
4fbe0d10901a80b27aacc9d9e6848e30e5fe727dAki Tuomi MAILBOX_LIST_FLAG_FULL_FS_ACCESS = 0x04,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi /* Rely on O_EXCL when creating dotlocks */
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi MAILBOX_LIST_FLAG_DOTLOCK_USE_EXCL = 0x08
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi};
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomienum mailbox_info_flags {
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi MAILBOX_NOSELECT = 0x001,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi MAILBOX_NONEXISTENT = 0x002,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi MAILBOX_CHILDREN = 0x004,
98bc2ecdbfd4f2f20c3a5e96ae445072fbe22223Aki Tuomi MAILBOX_NOCHILDREN = 0x008,
1be27c35ea17fccd83c54e2acc66eb8c44d1a8feAki Tuomi MAILBOX_NOINFERIORS = 0x010,
1be27c35ea17fccd83c54e2acc66eb8c44d1a8feAki Tuomi MAILBOX_MARKED = 0x020,
98bc2ecdbfd4f2f20c3a5e96ae445072fbe22223Aki Tuomi MAILBOX_UNMARKED = 0x040
f207fb0f2fd3113aa9a9f7911fb12d94dce19dffAki Tuomi};
f207fb0f2fd3113aa9a9f7911fb12d94dce19dffAki Tuomi
98bc2ecdbfd4f2f20c3a5e96ae445072fbe22223Aki Tuomienum mailbox_name_status {
98bc2ecdbfd4f2f20c3a5e96ae445072fbe22223Aki Tuomi MAILBOX_NAME_EXISTS,
98bc2ecdbfd4f2f20c3a5e96ae445072fbe22223Aki Tuomi MAILBOX_NAME_VALID,
98bc2ecdbfd4f2f20c3a5e96ae445072fbe22223Aki Tuomi MAILBOX_NAME_INVALID,
98bc2ecdbfd4f2f20c3a5e96ae445072fbe22223Aki Tuomi MAILBOX_NAME_NOINFERIORS
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi};
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomienum mailbox_list_iter_flags {
03c6532fe7aa3ddae23c99ff6bec78d8dd2e8165Aki Tuomi /* List only subscribed mailboxes */
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi MAILBOX_LIST_ITER_SUBSCRIBED = 0x01,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi /* Don't return any flags unless it can be done without cost */
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi MAILBOX_LIST_ITER_FAST_FLAGS = 0x02,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi /* Return children flags */
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi MAILBOX_LIST_ITER_CHILDREN = 0x04,
03c6532fe7aa3ddae23c99ff6bec78d8dd2e8165Aki Tuomi /* Ignore index file and ACLs (used by ACL plugin internally) */
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi MAILBOX_LIST_ITER_RAW_LIST = 0x08
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi};
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomienum mailbox_list_path_type {
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi /* Return directory's path (eg. ~/dbox/INBOX) */
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi MAILBOX_LIST_PATH_TYPE_DIR,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi /* Return mailbox path (eg. ~/dbox/INBOX/dbox-Mails) */
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi MAILBOX_LIST_PATH_TYPE_MAILBOX,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi /* Return control directory */
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi MAILBOX_LIST_PATH_TYPE_CONTROL,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi /* Return index file directory */
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi MAILBOX_LIST_PATH_TYPE_INDEX
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi};
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomienum mailbox_list_file_type {
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi MAILBOX_LIST_FILE_TYPE_UNKNOWN = 0,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi MAILBOX_LIST_FILE_TYPE_FILE,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi MAILBOX_LIST_FILE_TYPE_DIR,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi MAILBOX_LIST_FILE_TYPE_SYMLINK,
17541ea25593c656060199715051db2c1eef221dAki Tuomi MAILBOX_LIST_FILE_TYPE_OTHER
17541ea25593c656060199715051db2c1eef221dAki Tuomi};
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomistruct mailbox_list_settings {
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi const char *root_dir;
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi const char *index_dir;
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi const char *control_dir;
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
17541ea25593c656060199715051db2c1eef221dAki Tuomi const char *inbox_path;
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi const char *subscription_fname;
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi /* If non-empty, it means that mails exist in a maildir_name
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi subdirectory. eg. if you have a directory containing directories:
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi mail/
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi mail/foo/
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi mail/foo/Maildir
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
03c6532fe7aa3ddae23c99ff6bec78d8dd2e8165Aki Tuomi If mailbox_name is empty, you have mailboxes "mail", "mail/foo" and
03c6532fe7aa3ddae23c99ff6bec78d8dd2e8165Aki Tuomi "mail/foo/Maildir".
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi If mailbox_name is "Maildir", you have a non-selectable mailbox
7c9ae3d919ba59af5be3193a80ece4871a0d700cAki Tuomi "mail" and a selectable mailbox "mail/foo". */
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi const char *maildir_name;
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi /* If mailbox index is used, use these settings for it
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi (pointers, so they're set to NULL after init is finished): */
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi const enum mail_storage_flags *mail_storage_flags;
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi const enum file_lock_method *lock_method;
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi};
be5773cb4d6edae8a5d9f300c3c7375cdd33826eJosef 'Jeff' Sipek
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomistruct mailbox_info {
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi const char *name;
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi enum mailbox_info_flags flags;
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi};
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi/* register all drivers */
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomivoid mailbox_list_register_all(void);
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomivoid mailbox_list_register(const struct mailbox_list *list);
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomivoid mailbox_list_unregister(const struct mailbox_list *list);
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi/* Returns 0 if ok, -1 if initialization failed. */
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomiint mailbox_list_init(struct mail_namespace *ns, const char *driver,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi const struct mailbox_list_settings *set,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi enum mailbox_list_flags flags,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi struct mailbox_list **list_r, const char **error_r);
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomivoid mailbox_list_deinit(struct mailbox_list *list);
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
204ee6ed414f5e4eeb6f6c10763b55daf56f11acJosef 'Jeff' Sipekconst char *mailbox_list_get_driver_name(struct mailbox_list *list);
5f1d689131a75c39f064cbd4202373e7edf78f18Josef 'Jeff' Sipekchar mailbox_list_get_hierarchy_sep(struct mailbox_list *list);
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomienum mailbox_list_flags mailbox_list_get_flags(struct mailbox_list *list);
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomistruct mail_namespace *mailbox_list_get_namespace(struct mailbox_list *list);
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi/* Returns TRUE if the name doesn't contain any invalid characters.
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi The create name check can be more strict. */
097dbdf543bc5d1689c5570f5faaec1e864e3a87Aki Tuomibool mailbox_list_is_valid_mask(struct mailbox_list *list, const char *mask);
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomibool mailbox_list_is_valid_existing_name(struct mailbox_list *list,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi const char *name);
a371ea8bd48d45548cd7aa16d4f5aeb38ba48c91Aki Tuomibool mailbox_list_is_valid_create_name(struct mailbox_list *list,
a371ea8bd48d45548cd7aa16d4f5aeb38ba48c91Aki Tuomi const char *name);
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi/* Return full path for the given mailbox name. The name must be a valid
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi existing mailbox name, or NULL to get the root directory.
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi For INDEX=MEMORY it returns "" as the path. */
be5773cb4d6edae8a5d9f300c3c7375cdd33826eJosef 'Jeff' Sipekconst char *mailbox_list_get_path(struct mailbox_list *list, const char *name,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi enum mailbox_list_path_type type);
5f1d689131a75c39f064cbd4202373e7edf78f18Josef 'Jeff' Sipek/* Returns the mode, UID and GID that should be used when creating new files
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi to the given mailbox. (uid_t)-1 and (gid_t)-1 is returned if it's not
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi necessary to change the default UID or GID. The name must be a valid
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi existing mailbox name, or NULL to get global permissions.
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi Returns -1 if error, 0 if mailbox not found, 1 if ok. */
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomiint mailbox_list_get_permissions(struct mailbox_list *list, const char *name,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi mode_t *mode_r, uid_t *uid_r, gid_t *gid_r);
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi/* Returns mailbox name status */
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomiint mailbox_list_get_mailbox_name_status(struct mailbox_list *list,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi const char *name,
097dbdf543bc5d1689c5570f5faaec1e864e3a87Aki Tuomi enum mailbox_name_status *status);
097dbdf543bc5d1689c5570f5faaec1e864e3a87Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi/* Returns a prefix that temporary files should use without conflicting
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi with the namespace. */
98bc2ecdbfd4f2f20c3a5e96ae445072fbe22223Aki Tuomiconst char *mailbox_list_get_temp_prefix(struct mailbox_list *list);
98bc2ecdbfd4f2f20c3a5e96ae445072fbe22223Aki Tuomi
98bc2ecdbfd4f2f20c3a5e96ae445072fbe22223Aki Tuomi/* Returns a single mask from given reference and mask. */
98bc2ecdbfd4f2f20c3a5e96ae445072fbe22223Aki Tuomiconst char *mailbox_list_join_refmask(struct mailbox_list *list,
98bc2ecdbfd4f2f20c3a5e96ae445072fbe22223Aki Tuomi const char *ref, const char *mask);
98bc2ecdbfd4f2f20c3a5e96ae445072fbe22223Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi/* Initialize new mailbox list request. mask may contain '%' and '*'
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi wildcards as defined by RFC-3501. */
097dbdf543bc5d1689c5570f5faaec1e864e3a87Aki Tuomistruct mailbox_list_iterate_context *
097dbdf543bc5d1689c5570f5faaec1e864e3a87Aki Tuomimailbox_list_iter_init(struct mailbox_list *list, const char *mask,
097dbdf543bc5d1689c5570f5faaec1e864e3a87Aki Tuomi enum mailbox_list_iter_flags flags);
097dbdf543bc5d1689c5570f5faaec1e864e3a87Aki Tuomi/* Get next mailbox. Returns the mailbox name */
097dbdf543bc5d1689c5570f5faaec1e864e3a87Aki Tuomiconst struct mailbox_info *
097dbdf543bc5d1689c5570f5faaec1e864e3a87Aki Tuomimailbox_list_iter_next(struct mailbox_list_iterate_context *ctx);
097dbdf543bc5d1689c5570f5faaec1e864e3a87Aki Tuomi/* Deinitialize mailbox list request. Returns FALSE if some error
097dbdf543bc5d1689c5570f5faaec1e864e3a87Aki Tuomi occurred while listing. */
097dbdf543bc5d1689c5570f5faaec1e864e3a87Aki Tuomiint mailbox_list_iter_deinit(struct mailbox_list_iterate_context **ctx);
0d1b8b6bec79746c5d89d57dd8c1688946bd9237Josef 'Jeff' Sipek
5f1d689131a75c39f064cbd4202373e7edf78f18Josef 'Jeff' Sipek/* Subscribe/unsubscribe mailbox. There should be no error when
097dbdf543bc5d1689c5570f5faaec1e864e3a87Aki Tuomi subscribing to already subscribed mailbox. Subscribing to
097dbdf543bc5d1689c5570f5faaec1e864e3a87Aki Tuomi unexisting mailboxes is optional. */
097dbdf543bc5d1689c5570f5faaec1e864e3a87Aki Tuomiint mailbox_list_set_subscribed(struct mailbox_list *list,
097dbdf543bc5d1689c5570f5faaec1e864e3a87Aki Tuomi const char *name, bool set);
097dbdf543bc5d1689c5570f5faaec1e864e3a87Aki Tuomi
097dbdf543bc5d1689c5570f5faaec1e864e3a87Aki Tuomi/* Delete the given mailbox. If it has children, they aren't deleted. */
097dbdf543bc5d1689c5570f5faaec1e864e3a87Aki Tuomiint mailbox_list_delete_mailbox(struct mailbox_list *list, const char *name);
097dbdf543bc5d1689c5570f5faaec1e864e3a87Aki Tuomi/* If the name has inferior hierarchical names, then the inferior
097dbdf543bc5d1689c5570f5faaec1e864e3a87Aki Tuomi hierarchical names MUST also be renamed (ie. foo -> bar renames
1be27c35ea17fccd83c54e2acc66eb8c44d1a8feAki Tuomi also foo/bar -> bar/bar). newname may contain multiple new
1be27c35ea17fccd83c54e2acc66eb8c44d1a8feAki Tuomi hierarchies.
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi If oldname is case-insensitively "INBOX", the mails are moved
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi into new mailbox but the INBOX mailbox must not be deleted. */
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomiint mailbox_list_rename_mailbox(struct mailbox_list *list,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi const char *oldname, const char *newname);
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi/* Returns the error message of last occurred error. */
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomiconst char *mailbox_list_get_last_error(struct mailbox_list *list,
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi enum mail_error *error_r);
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi#endif
4036c1ca99d2c517f68a5b67a419ae7fdfd45300Aki Tuomi