mailbox-list-private.h revision b31ddaad0c05e2c63cfe45eae28094829e2a5c57
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch#ifndef MAILBOX_LIST_PRIVATE_H
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen#define MAILBOX_LIST_PRIVATE_H
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen#include "mail-namespace.h"
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen#include "mailbox-list.h"
65988f5a8abed57e9894fec77105941e046d3490Timo Sirainen#include "mail-storage-settings.h"
72388282bf6718c39af34cfcf51438910f9d62daTimo Sirainen
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainenstruct dirent;
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainenstruct imap_match_glob;
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainenstruct mailbox_tree_context;
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainenstruct mailbox_list_vfuncs {
2ac5f36aa7c2e7a07ba8815d43a6d7483f62e74cTimo Sirainen struct mailbox_list *(*alloc)(void);
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen void (*deinit)(struct mailbox_list *list);
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen int (*get_storage)(struct mailbox_list *list,
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen const char **name, struct mail_storage **storage_r);
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen bool (*is_valid_pattern)(struct mailbox_list *list,
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen const char *pattern);
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen bool (*is_valid_existing_name)(struct mailbox_list *list,
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen const char *name);
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen bool (*is_valid_create_name)(struct mailbox_list *list,
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen const char *name);
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen const char *(*get_path)(struct mailbox_list *list, const char *name,
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen enum mailbox_list_path_type type);
79454ba23ef6baf56997cd3cc23123eb69ae4f4cTimo Sirainen int (*get_mailbox_name_status)(struct mailbox_list *list,
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen const char *name,
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen enum mailbox_name_status *status);
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen const char *(*get_temp_prefix)(struct mailbox_list *list, bool global);
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen const char *(*join_refpattern)(struct mailbox_list *list,
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen const char *ref, const char *pattern);
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen struct mailbox_list_iterate_context *
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen (*iter_init)(struct mailbox_list *list,
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen const char *const *patterns,
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen enum mailbox_list_iter_flags flags);
e4f1a5fdad77884e1de516521504c15dc936fa9dTimo Sirainen const struct mailbox_info *
e4f1a5fdad77884e1de516521504c15dc936fa9dTimo Sirainen (*iter_next)(struct mailbox_list_iterate_context *ctx);
e4f1a5fdad77884e1de516521504c15dc936fa9dTimo Sirainen int (*iter_deinit)(struct mailbox_list_iterate_context *ctx);
e4f1a5fdad77884e1de516521504c15dc936fa9dTimo Sirainen
e4f1a5fdad77884e1de516521504c15dc936fa9dTimo Sirainen /* Returns -1 if error, 0 if it's not a valid mailbox, 1 if it is.
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen flags may be updated (especially the children flags). */
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen int (*iter_is_mailbox)(struct mailbox_list_iterate_context *ctx,
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen const char *dir, const char *fname,
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen const char *mailbox_name,
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen enum mailbox_list_file_type type,
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen enum mailbox_info_flags *flags_r);
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen int (*set_subscribed)(struct mailbox_list *list,
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen const char *name, bool set);
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen int (*delete_mailbox)(struct mailbox_list *list, const char *name);
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen int (*rename_mailbox)(struct mailbox_list *list, const char *oldname,
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen const char *newname);
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen /* called by rename_mailbox() just before running the actual rename() */
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen int (*rename_mailbox_pre)(struct mailbox_list *list,
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen const char *oldname, const char *newname);
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen};
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen
2ac5f36aa7c2e7a07ba8815d43a6d7483f62e74cTimo Sirainenstruct mailbox_list_module_register {
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainen unsigned int id;
2ac5f36aa7c2e7a07ba8815d43a6d7483f62e74cTimo Sirainen};
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainen
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainenunion mailbox_list_module_context {
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainen struct mailbox_list_vfuncs super;
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainen struct mailbox_list_module_register *reg;
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainen};
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainen
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainenstruct mailbox_list {
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainen const char *name;
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainen char hierarchy_sep;
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen enum mailbox_list_properties props;
7c424aa51c956c628e3512055841aa2f9eef4833Timo Sirainen size_t mailbox_name_max_length;
f923659c0e5298263d80622c99f4dc4132b4675bTimo Sirainen
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen struct mailbox_list_vfuncs v;
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen
2ac5f36aa7c2e7a07ba8815d43a6d7483f62e74cTimo Sirainen/* private: */
2a3fc652e13a574ca14ff2405b5c29a59232db49Timo Sirainen pool_t pool;
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen struct mail_namespace *ns;
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen struct mailbox_list_settings set;
8bb360f9e5de1c25e4f875205bb06e8bf15dae14Timo Sirainen const struct mail_storage_settings *mail_set;
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen enum mailbox_list_flags flags;
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen /* -1 if not set yet. use mailbox_list_get_permissions() to set them */
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen mode_t file_create_mode, dir_create_mode;
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen gid_t file_create_gid;
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen char *error_string;
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainen enum mail_error error;
b014857be9961acf2d37ef7b76d941b20cc8c2d1Timo Sirainen bool temporary_error;
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen ARRAY_DEFINE(module_contexts, union mailbox_list_module_context *);
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen};
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainenstruct mailbox_list_iterate_context {
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen struct mailbox_list *list;
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen enum mailbox_list_iter_flags flags;
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen bool failed;
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen};
fab050cbfdf3da692441d2e2fb4b2a4c6ac9e0daTimo Sirainen
fab050cbfdf3da692441d2e2fb4b2a4c6ac9e0daTimo Sirainenstruct mailbox_list_iter_update_context {
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen struct mailbox_list_iterate_context *iter_ctx;
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen struct mailbox_tree_context *tree_ctx;
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen struct imap_match_glob *glob;
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen enum mailbox_info_flags leaf_flags, parent_flags;
2a3fc652e13a574ca14ff2405b5c29a59232db49Timo Sirainen
2a3fc652e13a574ca14ff2405b5c29a59232db49Timo Sirainen unsigned int update_only:1;
2a3fc652e13a574ca14ff2405b5c29a59232db49Timo Sirainen unsigned int match_parents:1;
2a3fc652e13a574ca14ff2405b5c29a59232db49Timo Sirainen};
2a3fc652e13a574ca14ff2405b5c29a59232db49Timo Sirainen
2a3fc652e13a574ca14ff2405b5c29a59232db49Timo Sirainen/* Modules should use do "my_id = mailbox_list_module_id++" and
2a3fc652e13a574ca14ff2405b5c29a59232db49Timo Sirainen use objects' module_contexts[id] for their own purposes. */
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainenextern struct mailbox_list_module_register mailbox_list_module_register;
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainenextern void (*hook_mailbox_list_created)(struct mailbox_list *list);
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainenvoid mailbox_lists_init(void);
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainenvoid mailbox_lists_deinit(void);
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainenint mailbox_list_settings_parse(const char *data,
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen struct mailbox_list_settings *set,
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen struct mail_namespace *ns,
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen const char **layout, const char **alt_dir_r,
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen const char **error_r);
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainenint mailbox_list_delete_index_control(struct mailbox_list *list,
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainen const char *name);
812ac1e2570c600a086c09b24d250224a822a97dTimo Sirainen
79454ba23ef6baf56997cd3cc23123eb69ae4f4cTimo Sirainenvoid mailbox_list_iter_update(struct mailbox_list_iter_update_context *ctx,
d65a556a5ec078cd7f1d0060adb16fc860d66b27Timo Sirainen const char *name);
d65a556a5ec078cd7f1d0060adb16fc860d66b27Timo Sirainen
d65a556a5ec078cd7f1d0060adb16fc860d66b27Timo Sirainenbool mailbox_list_name_is_too_large(const char *name, char sep);
6307d76096764e66bddc63d4a3e5a1aa19cc528fJosef 'Jeff' Sipekenum mailbox_list_file_type mailbox_list_get_file_type(const struct dirent *d);
847aeef259d42e2f14cf126699e28291e6e1fb53Timo Sirainenbool mailbox_list_try_get_absolute_path(struct mailbox_list *list,
72388282bf6718c39af34cfcf51438910f9d62daTimo Sirainen const char **name);
72388282bf6718c39af34cfcf51438910f9d62daTimo Sirainen
72388282bf6718c39af34cfcf51438910f9d62daTimo Sirainenvoid mailbox_list_clear_error(struct mailbox_list *list);
d9076f5939edf5d20a261494b1a861dcbb0d32e2Timo Sirainenvoid mailbox_list_set_error(struct mailbox_list *list,
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen enum mail_error error, const char *string);
72388282bf6718c39af34cfcf51438910f9d62daTimo Sirainenvoid mailbox_list_set_critical(struct mailbox_list *list, const char *fmt, ...)
72388282bf6718c39af34cfcf51438910f9d62daTimo Sirainen ATTR_FORMAT(2, 3);
72388282bf6718c39af34cfcf51438910f9d62daTimo Sirainenvoid mailbox_list_set_internal_error(struct mailbox_list *list);
72388282bf6718c39af34cfcf51438910f9d62daTimo Sirainenbool mailbox_list_set_error_from_errno(struct mailbox_list *list);
72388282bf6718c39af34cfcf51438910f9d62daTimo Sirainen
72388282bf6718c39af34cfcf51438910f9d62daTimo Sirainen#endif
72388282bf6718c39af34cfcf51438910f9d62daTimo Sirainen