mailbox-list-private.h revision 697ff56bf3cdc9e7989ea2a70accf866b14b64d1
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen#ifndef MAILBOX_LIST_PRIVATE_H
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen#define MAILBOX_LIST_PRIVATE_H
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen#include "mailbox-log.h"
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen#include "mailbox-list-notify.h"
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen#include "mail-namespace.h"
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen#include "mailbox-list.h"
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen#include "mailbox-list-iter.h"
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen#include "mail-storage-settings.h"
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen#define MAILBOX_LIST_NAME_MAILDIRPLUSPLUS "maildir++"
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen#define MAILBOX_LIST_NAME_IMAPDIR "imapdir"
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen#define MAILBOX_LIST_NAME_FS "fs"
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen#define MAILBOX_LIST_NAME_INDEX "index"
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen#define MAILBOX_LIST_NAME_NONE "none"
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen#define MAILBOX_LOG_FILE_NAME "dovecot.mailbox.log"
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen#define T_MAILBOX_LIST_ERR_NOT_FOUND(list, name) \
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen t_strdup_printf(MAIL_ERRSTR_MAILBOX_NOT_FOUND, \
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen mailbox_list_get_vname(list, name))
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainenstruct stat;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainenstruct dirent;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainenstruct fs;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainenstruct imap_match_glob;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainenstruct mailbox_tree_context;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainenstruct mailbox_list_notify;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainenstruct mailbox_list_notify_rec;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen#define MAILBOX_INFO_FLAGS_FINISHED(flags) \
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen (((flags) & (MAILBOX_SELECT | MAILBOX_NOSELECT | \
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen MAILBOX_NONEXISTENT)) != 0)
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainenstruct mailbox_list_vfuncs {
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen struct mailbox_list *(*alloc)(void);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen int (*init)(struct mailbox_list *list, const char **error_r);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen void (*deinit)(struct mailbox_list *list);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen int (*get_storage)(struct mailbox_list **list, const char *vname,
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen struct mail_storage **storage_r);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen char (*get_hierarchy_sep)(struct mailbox_list *list);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen const char *(*get_vname)(struct mailbox_list *list,
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen const char *storage_name);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen const char *(*get_storage_name)(struct mailbox_list *list,
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen const char *vname);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen int (*get_path)(struct mailbox_list *list, const char *name,
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen enum mailbox_list_path_type type, const char **path_r);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen const char *(*get_temp_prefix)(struct mailbox_list *list, bool global);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen const char *(*join_refpattern)(struct mailbox_list *list,
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen const char *ref, const char *pattern);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen struct mailbox_list_iterate_context *
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen (*iter_init)(struct mailbox_list *list,
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen const char *const *patterns,
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen enum mailbox_list_iter_flags flags);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen const struct mailbox_info *
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen (*iter_next)(struct mailbox_list_iterate_context *ctx);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen int (*iter_deinit)(struct mailbox_list_iterate_context *ctx);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen int (*get_mailbox_flags)(struct mailbox_list *list,
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen const char *dir, const char *fname,
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen enum mailbox_list_file_type type,
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen enum mailbox_info_flags *flags_r);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen /* Returns TRUE if name is mailbox's internal file/directory.
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen If it does, mailbox deletion assumes it can safely delete it. */
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen bool (*is_internal_name)(struct mailbox_list *list, const char *name);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen /* Read subscriptions from src_list, but place them into
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen dest_list->subscriptions. Set errors to dest_list. */
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen int (*subscriptions_refresh)(struct mailbox_list *src_list,
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen struct mailbox_list *dest_list);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen int (*set_subscribed)(struct mailbox_list *list,
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen const char *name, bool set);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen int (*delete_mailbox)(struct mailbox_list *list, const char *name);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen int (*delete_dir)(struct mailbox_list *list, const char *name);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen int (*delete_symlink)(struct mailbox_list *list, const char *name);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen int (*rename_mailbox)(struct mailbox_list *oldlist, const char *oldname,
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen struct mailbox_list *newlist, const char *newname);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen int (*notify_init)(struct mailbox_list *list,
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen enum mailbox_list_notify_event mask,
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen struct mailbox_list_notify **notify_r);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen int (*notify_next)(struct mailbox_list_notify *notify,
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen const struct mailbox_list_notify_rec **rec_r);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen void (*notify_deinit)(struct mailbox_list_notify *notify);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen void (*notify_wait)(struct mailbox_list_notify *notify,
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen void (*callback)(void *context), void *context);
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen};
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainenstruct mailbox_list_module_register {
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen unsigned int id;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen};
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainenunion mailbox_list_module_context {
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen struct mailbox_list_vfuncs super;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen struct mailbox_list_module_register *reg;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen};
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainenstruct mailbox_list {
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen const char *name;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen enum mailbox_list_properties props;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen size_t mailbox_name_max_length;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen struct mailbox_list_vfuncs v, *vlast;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen/* private: */
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen pool_t pool;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen struct mail_namespace *ns;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen struct mailbox_list_settings set;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen const struct mail_storage_settings *mail_set;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen enum mailbox_list_flags flags;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen /* may not be set yet, use mailbox_list_get_permissions() to access */
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen struct mailbox_permissions root_permissions;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen struct mailbox_tree_context *subscriptions;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen time_t subscriptions_mtime, subscriptions_read_time;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen struct mailbox_log *changelog;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen time_t changelog_timestamp;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen pool_t guid_cache_pool;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen HASH_TABLE(uint8_t *, struct mailbox_guid_cache_rec *) guid_cache;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen bool guid_cache_errors;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen char *error_string;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen enum mail_error error;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen bool temporary_error;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen ARRAY(union mailbox_list_module_context *) module_contexts;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen unsigned int index_root_dir_created:1;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen unsigned int guid_cache_updated:1;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen unsigned int guid_cache_invalidated:1;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen};
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainenunion mailbox_list_iterate_module_context {
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen struct mailbox_list_module_register *reg;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen};
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainenstruct mailbox_list_iterate_context {
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen struct mailbox_list *list;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen pool_t pool;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen enum mailbox_list_iter_flags flags;
bool failed;
struct imap_match_glob *glob;
struct mailbox_list_autocreate_iterate_context *autocreate_ctx;
struct mailbox_info specialuse_info;
ARRAY(union mailbox_list_iterate_module_context *) module_contexts;
};
struct mailbox_list_iter_update_context {
struct mailbox_list_iterate_context *iter_ctx;
struct mailbox_tree_context *tree_ctx;
struct imap_match_glob *glob;
enum mailbox_info_flags leaf_flags, parent_flags;
unsigned int update_only:1;
unsigned int match_parents:1;
};
/* Modules should use do "my_id = mailbox_list_module_id++" and
use objects' module_contexts[id] for their own purposes. */
extern struct mailbox_list_module_register mailbox_list_module_register;
void mailbox_lists_init(void);
void mailbox_lists_deinit(void);
int 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);
#endif