mailbox-list-private.h revision d6499957ea59e6d9729d3350d9ac5eae992635f6
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch#ifndef MAILBOX_LIST_PRIVATE_H
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define MAILBOX_LIST_PRIVATE_H
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "mailbox-log.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "mailbox-list-notify.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "mail-namespace.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "mailbox-list.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "mailbox-list-iter.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "mail-storage-settings.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define MAILBOX_LIST_NAME_MAILDIRPLUSPLUS "maildir++"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define MAILBOX_LIST_NAME_IMAPDIR "imapdir"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define MAILBOX_LIST_NAME_FS "fs"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define MAILBOX_LIST_NAME_INDEX "index"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define MAILBOX_LIST_NAME_NONE "none"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define MAILBOX_LOG_FILE_NAME "dovecot.mailbox.log"
b66d803de86bfb411165b3465b0d9ef64ecfe2a1Timo Sirainen
0a7b04ec6441fdcf083392888b2e30844fc3e86dTimo Sirainen#define T_MAILBOX_LIST_ERR_NOT_FOUND(list, name) \
0a7b04ec6441fdcf083392888b2e30844fc3e86dTimo Sirainen t_strdup_printf(MAIL_ERRSTR_MAILBOX_NOT_FOUND, \
0a7b04ec6441fdcf083392888b2e30844fc3e86dTimo Sirainen mailbox_list_get_vname(list, name))
0a7b04ec6441fdcf083392888b2e30844fc3e86dTimo Sirainen
0a7b04ec6441fdcf083392888b2e30844fc3e86dTimo Sirainenstruct stat;
0a7b04ec6441fdcf083392888b2e30844fc3e86dTimo Sirainenstruct dirent;
0a7b04ec6441fdcf083392888b2e30844fc3e86dTimo Sirainenstruct fs;
3df398a463e931b63586726adb3309c9692208c1Timo Sirainenstruct imap_match_glob;
0a7b04ec6441fdcf083392888b2e30844fc3e86dTimo Sirainenstruct mailbox_tree_context;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstruct mailbox_list_notify;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstruct mailbox_list_notify_rec;
0fcfa7698e7beb78019ac89a869eef1b41e56a62Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define MAILBOX_INFO_FLAGS_FINISHED(flags) \
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen (((flags) & (MAILBOX_SELECT | MAILBOX_NOSELECT | \
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen MAILBOX_NONEXISTENT)) != 0)
d665e2948cb6fe8016706752a9e4940d64f4a61dTimo Sirainen
d665e2948cb6fe8016706752a9e4940d64f4a61dTimo Sirainenstruct mailbox_list_vfuncs {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct mailbox_list *(*alloc)(void);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen int (*init)(struct mailbox_list *list, const char **error_r);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen void (*deinit)(struct mailbox_list *list);
0fcfa7698e7beb78019ac89a869eef1b41e56a62Timo Sirainen
fc40a9a002458e372ff4b9f6f4e15239520c0bcdTimo Sirainen int (*get_storage)(struct mailbox_list **list, const char *vname,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct mail_storage **storage_r);
0fcfa7698e7beb78019ac89a869eef1b41e56a62Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen char (*get_hierarchy_sep)(struct mailbox_list *list);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char *(*get_vname)(struct mailbox_list *list,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char *storage_name);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char *(*get_storage_name)(struct mailbox_list *list,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char *vname);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen int (*get_path)(struct mailbox_list *list, const char *name,
d665e2948cb6fe8016706752a9e4940d64f4a61dTimo Sirainen enum mailbox_list_path_type type, const char **path_r);
d665e2948cb6fe8016706752a9e4940d64f4a61dTimo Sirainen
4ca83616715c3bd417e34ced2c1d61852513e427Timo Sirainen const char *(*get_temp_prefix)(struct mailbox_list *list, bool global);
0fcfa7698e7beb78019ac89a869eef1b41e56a62Timo Sirainen const char *(*join_refpattern)(struct mailbox_list *list,
0fcfa7698e7beb78019ac89a869eef1b41e56a62Timo Sirainen const char *ref, const char *pattern);
0fcfa7698e7beb78019ac89a869eef1b41e56a62Timo Sirainen
64d3d21a70fbf66b8bce53ae0b1af24901fec976Timo Sirainen struct mailbox_list_iterate_context *
0fcfa7698e7beb78019ac89a869eef1b41e56a62Timo Sirainen (*iter_init)(struct mailbox_list *list,
0fcfa7698e7beb78019ac89a869eef1b41e56a62Timo Sirainen const char *const *patterns,
0fcfa7698e7beb78019ac89a869eef1b41e56a62Timo Sirainen enum mailbox_list_iter_flags flags);
0fcfa7698e7beb78019ac89a869eef1b41e56a62Timo Sirainen const struct mailbox_info *
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen (*iter_next)(struct mailbox_list_iterate_context *ctx);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen int (*iter_deinit)(struct mailbox_list_iterate_context *ctx);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen int (*get_mailbox_flags)(struct mailbox_list *list,
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen const char *dir, const char *fname,
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen enum mailbox_list_file_type type,
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen enum mailbox_info_flags *flags_r);
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen /* Returns TRUE if name is mailbox's internal file/directory.
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen If it does, mailbox deletion assumes it can safely delete it. */
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen bool (*is_internal_name)(struct mailbox_list *list, const char *name);
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen /* Read subscriptions from src_list, but place them into
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen dest_list->subscriptions. Set errors to dest_list. */
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen int (*subscriptions_refresh)(struct mailbox_list *src_list,
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen struct mailbox_list *dest_list);
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen int (*set_subscribed)(struct mailbox_list *list,
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen const char *name, bool set);
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen int (*delete_mailbox)(struct mailbox_list *list, const char *name);
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen int (*delete_dir)(struct mailbox_list *list, const char *name);
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen int (*delete_symlink)(struct mailbox_list *list, const char *name);
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen int (*rename_mailbox)(struct mailbox_list *oldlist, const char *oldname,
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen struct mailbox_list *newlist, const char *newname);
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen int (*notify_init)(struct mailbox_list *list,
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen enum mailbox_list_notify_event mask,
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen struct mailbox_list_notify **notify_r);
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen int (*notify_next)(struct mailbox_list_notify *notify,
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen const struct mailbox_list_notify_rec **rec_r);
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen void (*notify_deinit)(struct mailbox_list_notify *notify);
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen void (*notify_wait)(struct mailbox_list_notify *notify,
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen void (*callback)(void *context), void *context);
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen};
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainenstruct mailbox_list_module_register {
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen unsigned int id;
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen};
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainenunion mailbox_list_module_context {
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen struct mailbox_list_vfuncs super;
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen struct mailbox_list_module_register *reg;
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen};
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainenstruct mailbox_list {
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen const char *name;
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen enum mailbox_list_properties props;
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen size_t mailbox_name_max_length;
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct mailbox_list_vfuncs v, *vlast;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen/* private: */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen pool_t pool;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct mail_namespace *ns;
0fcfa7698e7beb78019ac89a869eef1b41e56a62Timo Sirainen struct mailbox_list_settings set;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const struct mail_storage_settings *mail_set;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen enum mailbox_list_flags flags;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* may not be set yet, use mailbox_list_get_permissions() to access */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct mailbox_permissions root_permissions;
7204b8112e005ff81dcf628f7880ef1feed1effeTimo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct mailbox_tree_context *subscriptions;
0fcfa7698e7beb78019ac89a869eef1b41e56a62Timo Sirainen time_t subscriptions_mtime, subscriptions_read_time;
0fcfa7698e7beb78019ac89a869eef1b41e56a62Timo Sirainen
0fcfa7698e7beb78019ac89a869eef1b41e56a62Timo Sirainen struct mailbox_log *changelog;
0fcfa7698e7beb78019ac89a869eef1b41e56a62Timo Sirainen time_t changelog_timestamp;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen time_t guid_cache_last_update;
4ca83616715c3bd417e34ced2c1d61852513e427Timo Sirainen pool_t guid_cache_pool;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen HASH_TABLE(uint8_t *, struct mailbox_guid_cache_rec *) guid_cache;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen bool guid_cache_errors;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen char *error_string;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen enum mail_error error;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen bool temporary_error;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ARRAY(union mailbox_list_module_context *) module_contexts;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen unsigned int index_root_dir_created:1;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen unsigned int guid_cache_invalidated:1;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen};
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenunion mailbox_list_iterate_module_context {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct mailbox_list_module_register *reg;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen};
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstruct mailbox_list_iterate_context {
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen struct mailbox_list *list;
421d30619384e72a27e2a5d13ff6525aff4d17feTimo Sirainen pool_t pool;
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainen enum mailbox_list_iter_flags flags;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen bool failed;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct imap_match_glob *glob;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct mailbox_list_autocreate_iterate_context *autocreate_ctx;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct mailbox_info specialuse_info;
f46885a5b78b15a8d2419f6e5d13b643bd85e41fTimo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen ARRAY(union mailbox_list_iterate_module_context *) module_contexts;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen};
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstruct mailbox_list_iter_update_context {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct mailbox_list_iterate_context *iter_ctx;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct mailbox_tree_context *tree_ctx;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct imap_match_glob *glob;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen enum mailbox_info_flags leaf_flags, parent_flags;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen unsigned int update_only:1;
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen unsigned int match_parents:1;
21aaa6affb9f134112b75b5db737309fc35ef1cfMartti Rannanjärvi};
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen/* Modules should use do "my_id = mailbox_list_module_id++" and
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen use objects' module_contexts[id] for their own purposes. */
f46885a5b78b15a8d2419f6e5d13b643bd85e41fTimo Sirainenextern struct mailbox_list_module_register mailbox_list_module_register;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenvoid mailbox_lists_init(void);
6564208826b0f46a00f010d1b5711d85944c3c88Timo Sirainenvoid mailbox_lists_deinit(void);
6de6ec228a41275ddda972d4a554699ea75cd06dTimo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenint mailbox_list_settings_parse(struct mail_user *user, const char *data,
struct mailbox_list_settings *set_r,
const char **error_r);
const char *mailbox_list_default_get_storage_name(struct mailbox_list *list,
const char *vname);
const char *mailbox_list_default_get_vname(struct mailbox_list *list,
const char *storage_name);
const char *mailbox_list_get_unexpanded_path(struct mailbox_list *list,
enum mailbox_list_path_type type);
bool mailbox_list_set_get_root_path(const struct mailbox_list_settings *set,
enum mailbox_list_path_type type,
const char **path_r);
int mailbox_list_delete_index_control(struct mailbox_list *list,
const char *name);
void mailbox_list_iter_update(struct mailbox_list_iter_update_context *ctx,
const char *name);
int mailbox_list_iter_subscriptions_refresh(struct mailbox_list *list);
bool mailbox_list_name_is_too_large(const char *name, char sep);
enum mailbox_list_file_type mailbox_list_get_file_type(const struct dirent *d);
int mailbox_list_dirent_is_alias_symlink(struct mailbox_list *list,
const char *dir_path,
const struct dirent *d);
bool mailbox_list_try_get_absolute_path(struct mailbox_list *list,
const char **name);
void mailbox_list_add_change(struct mailbox_list *list,
enum mailbox_log_record_type type,
const guid_128_t guid_128);
void mailbox_name_get_sha128(const char *name, guid_128_t guid_128_r);
void mailbox_list_clear_error(struct mailbox_list *list);
void mailbox_list_set_error(struct mailbox_list *list,
enum mail_error error, const char *string);
void mailbox_list_set_critical(struct mailbox_list *list, const char *fmt, ...)
ATTR_FORMAT(2, 3);
void mailbox_list_set_internal_error(struct mailbox_list *list);
bool mailbox_list_set_error_from_errno(struct mailbox_list *list);
int mailbox_list_init_fs(struct mailbox_list *list, const char *driver,
const char *args, const char *root_dir,
struct fs **fs_r, const char **error_r);
#endif