mailbox-list-private.h revision 3fe67ec75ccae1230bb9eb9f16affc48377f6441
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch#ifndef MAILBOX_LIST_PRIVATE_H
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define MAILBOX_LIST_PRIVATE_H
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "mail-namespace.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "mailbox-list.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"
c68f28e2cf5f9621511bece0414335e551dc82c6Timo Sirainen#define MAILBOX_LIST_NAME_FS "fs"
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define MAILBOX_LOG_FILE_NAME "dovecot.mailbox.log"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenenum mailbox_log_record_type;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstruct dirent;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstruct imap_match_glob;
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainenstruct mailbox_tree_context;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstruct mailbox_list_vfuncs {
e42e27fcc497c7b4a5cc0b6ff304abca5ccfcb4fTimo Sirainen struct mailbox_list *(*alloc)(void);
e42e27fcc497c7b4a5cc0b6ff304abca5ccfcb4fTimo Sirainen void (*deinit)(struct mailbox_list *list);
e42e27fcc497c7b4a5cc0b6ff304abca5ccfcb4fTimo Sirainen
e42e27fcc497c7b4a5cc0b6ff304abca5ccfcb4fTimo Sirainen int (*get_storage)(struct mailbox_list **list, const char **name,
e42e27fcc497c7b4a5cc0b6ff304abca5ccfcb4fTimo Sirainen struct mail_storage **storage_r);
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen bool (*is_valid_pattern)(struct mailbox_list *list,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char *pattern);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen bool (*is_valid_existing_name)(struct mailbox_list *list,
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen const char *name);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen bool (*is_valid_create_name)(struct mailbox_list *list,
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen const char *name);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen const char *(*get_path)(struct mailbox_list *list, const char *name,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen enum mailbox_list_path_type type);
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen int (*get_mailbox_name_status)(struct mailbox_list *list,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char *name,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen enum mailbox_name_status *status);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char *(*get_temp_prefix)(struct mailbox_list *list, bool global);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char *(*join_refpattern)(struct mailbox_list *list,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char *ref, const char *pattern);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen
804fa3f03bd9170272168a5ad214053bbe3160c7Josef 'Jeff' Sipek struct mailbox_list_iterate_context *
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen (*iter_init)(struct mailbox_list *list,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char *const *patterns,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen enum mailbox_list_iter_flags flags);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const struct mailbox_info *
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen (*iter_next)(struct mailbox_list_iterate_context *ctx);
7631f16156aca373004953fe6b01a7f343fb47e0Timo Sirainen int (*iter_deinit)(struct mailbox_list_iterate_context *ctx);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* Returns -1 if error, 0 if it's not a valid mailbox, 1 if it is.
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen flags may be updated (especially the children flags). */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen int (*iter_is_mailbox)(struct mailbox_list_iterate_context *ctx,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char *dir, const char *fname,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char *mailbox_name,
efe78d3ba24fc866af1c79b9223dc0809ba26cadStephan Bosch enum mailbox_list_file_type type,
e6440616c02bb1404dc35debf45d9741260c7831Timo Sirainen enum mailbox_info_flags *flags_r);
e6440616c02bb1404dc35debf45d9741260c7831Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen int (*set_subscribed)(struct mailbox_list *list,
d4002fe1f64d25a792f76fb102ef7dc519cd4e24Martti Rannanjärvi const char *name, bool set);
d4002fe1f64d25a792f76fb102ef7dc519cd4e24Martti Rannanjärvi int (*delete_mailbox)(struct mailbox_list *list, const char *name);
d4002fe1f64d25a792f76fb102ef7dc519cd4e24Martti Rannanjärvi int (*rename_mailbox)(struct mailbox_list *oldlist, const char *oldname,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct mailbox_list *newlist, const char *newname,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen bool rename_children);
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen /* called by rename_mailbox() just before running the actual rename() */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen int (*rename_mailbox_pre)(struct mailbox_list *oldlist,
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen const char *oldname,
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen struct mailbox_list *newlist,
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen const char *newname);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen int (*get_guid)(struct mailbox_list *list, const char *name,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen uint8_t mailbox_guid[MAIL_GUID_128_SIZE]);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen};
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
804fa3f03bd9170272168a5ad214053bbe3160c7Josef 'Jeff' Sipekstruct mailbox_list_module_register {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen unsigned int id;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen};
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenunion mailbox_list_module_context {
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen struct mailbox_list_vfuncs super;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen struct mailbox_list_module_register *reg;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen};
c68f28e2cf5f9621511bece0414335e551dc82c6Timo Sirainen
c68f28e2cf5f9621511bece0414335e551dc82c6Timo Sirainenstruct mailbox_list {
c68f28e2cf5f9621511bece0414335e551dc82c6Timo Sirainen const char *name;
c68f28e2cf5f9621511bece0414335e551dc82c6Timo Sirainen char hierarchy_sep;
c68f28e2cf5f9621511bece0414335e551dc82c6Timo Sirainen enum mailbox_list_properties props;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen size_t mailbox_name_max_length;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct mailbox_list_vfuncs v;
e6440616c02bb1404dc35debf45d9741260c7831Timo Sirainen
e6440616c02bb1404dc35debf45d9741260c7831Timo Sirainen/* private: */
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen pool_t pool;
e6440616c02bb1404dc35debf45d9741260c7831Timo Sirainen struct mail_namespace *ns;
ad9afb64630511d5e25bc5bc11c5304986156928Timo Sirainen struct mailbox_list_settings set;
e6440616c02bb1404dc35debf45d9741260c7831Timo Sirainen const struct mail_storage_settings *mail_set;
48325adac125d7ff275ec69b05b7a92be9637630Timo Sirainen enum mailbox_list_flags flags;
48325adac125d7ff275ec69b05b7a92be9637630Timo Sirainen
1b6c4fdd2bb4234b5711874b3845547f49649744Timo Sirainen /* -1 if not set yet. use mailbox_list_get_permissions() to set them */
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen mode_t file_create_mode, dir_create_mode;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen gid_t file_create_gid;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen /* origin (e.g. path) where the file_create_gid was got from */
ad9afb64630511d5e25bc5bc11c5304986156928Timo Sirainen const char *file_create_gid_origin;
ad9afb64630511d5e25bc5bc11c5304986156928Timo Sirainen
ad9afb64630511d5e25bc5bc11c5304986156928Timo Sirainen struct mailbox_log *changelog;
ad9afb64630511d5e25bc5bc11c5304986156928Timo Sirainen time_t changelog_timestamp;
ad9afb64630511d5e25bc5bc11c5304986156928Timo Sirainen
ad9afb64630511d5e25bc5bc11c5304986156928Timo Sirainen char *error_string;
d1ba8ecbb936ace90179d2292952546708d68f71Timo Sirainen enum mail_error error;
ad9afb64630511d5e25bc5bc11c5304986156928Timo Sirainen bool temporary_error;
ad9afb64630511d5e25bc5bc11c5304986156928Timo Sirainen
d4002fe1f64d25a792f76fb102ef7dc519cd4e24Martti Rannanjärvi ARRAY_DEFINE(module_contexts, union mailbox_list_module_context *);
d4002fe1f64d25a792f76fb102ef7dc519cd4e24Martti Rannanjärvi};
d4002fe1f64d25a792f76fb102ef7dc519cd4e24Martti Rannanjärvi
d4002fe1f64d25a792f76fb102ef7dc519cd4e24Martti Rannanjärvistruct mailbox_list_iterate_context {
efb83f10b2a557d7427c311da52d768fb91e1b47Timo Sirainen struct mailbox_list *list;
efb83f10b2a557d7427c311da52d768fb91e1b47Timo Sirainen enum mailbox_list_iter_flags flags;
c25dfa96bc32e8841c9a8cf5ba02fffba4290160Timo Sirainen bool failed;
3177b410680f3915549719f84a4acbffd4f9c561Timo Sirainen};
3177b410680f3915549719f84a4acbffd4f9c561Timo Sirainen
3177b410680f3915549719f84a4acbffd4f9c561Timo Sirainenstruct mailbox_list_iter_update_context {
c3d9da3955043aef88c17b71f2081e894186aa6bTimo Sirainen struct mailbox_list_iterate_context *iter_ctx;
c3d9da3955043aef88c17b71f2081e894186aa6bTimo Sirainen struct mailbox_tree_context *tree_ctx;
c25dfa96bc32e8841c9a8cf5ba02fffba4290160Timo Sirainen
c25dfa96bc32e8841c9a8cf5ba02fffba4290160Timo Sirainen struct imap_match_glob *glob;
e6440616c02bb1404dc35debf45d9741260c7831Timo Sirainen enum mailbox_info_flags leaf_flags, parent_flags;
e6440616c02bb1404dc35debf45d9741260c7831Timo Sirainen
1f19649986397419d014febd1337c6eb7b530f26Timo Sirainen unsigned int update_only:1;
1f19649986397419d014febd1337c6eb7b530f26Timo Sirainen unsigned int match_parents:1;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen};
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen/* Modules should use do "my_id = mailbox_list_module_id++" and
804fa3f03bd9170272168a5ad214053bbe3160c7Josef 'Jeff' Sipek use objects' module_contexts[id] for their own purposes. */
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainenextern struct mailbox_list_module_register mailbox_list_module_register;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenvoid mailbox_lists_init(void);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenvoid mailbox_lists_deinit(void);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenint mailbox_list_settings_parse(const char *data,
efe78d3ba24fc866af1c79b9223dc0809ba26cadStephan Bosch struct mailbox_list_settings *set,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct mail_namespace *ns,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char **error_r);
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenint mailbox_list_delete_index_control(struct mailbox_list *list,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char *name);
1f19649986397419d014febd1337c6eb7b530f26Timo Sirainen
1f19649986397419d014febd1337c6eb7b530f26Timo Sirainenvoid mailbox_list_iter_update(struct mailbox_list_iter_update_context *ctx,
1f19649986397419d014febd1337c6eb7b530f26Timo Sirainen const char *name);
1f19649986397419d014febd1337c6eb7b530f26Timo Sirainen
1f19649986397419d014febd1337c6eb7b530f26Timo Sirainenbool mailbox_list_name_is_too_large(const char *name, char sep);
b58aafbd21b365117538f73f306d22f75acd91f1Timo Sirainenenum mailbox_list_file_type mailbox_list_get_file_type(const struct dirent *d);
1f19649986397419d014febd1337c6eb7b530f26Timo Sirainenbool mailbox_list_try_get_absolute_path(struct mailbox_list *list,
b58aafbd21b365117538f73f306d22f75acd91f1Timo Sirainen const char **name);
f89eb8f2cda0bd6d40a9f96db1c92517f0593871Martti Rannanjärvi
f89eb8f2cda0bd6d40a9f96db1c92517f0593871Martti Rannanjärvivoid mailbox_list_add_change(struct mailbox_list *list,
1f19649986397419d014febd1337c6eb7b530f26Timo Sirainen enum mailbox_log_record_type type,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const uint8_t mailbox_guid[MAIL_GUID_128_SIZE]);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenint mailbox_list_get_guid_path(struct mailbox_list *list, const char *path,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen uint8_t mailbox_guid[MAIL_GUID_128_SIZE]);
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainenvoid mailbox_list_clear_error(struct mailbox_list *list);
a8bc64d2ec8babb5109fa23aa3c90383de61cd69Timo Sirainenvoid mailbox_list_set_error(struct mailbox_list *list,
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen enum mail_error error, const char *string);
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainenvoid mailbox_list_set_critical(struct mailbox_list *list, const char *fmt, ...)
2b9dbb270ad82e58d5f3581436e6f143176d5819Timo Sirainen ATTR_FORMAT(2, 3);
2b9dbb270ad82e58d5f3581436e6f143176d5819Timo Sirainenvoid mailbox_list_set_internal_error(struct mailbox_list *list);
a8bc64d2ec8babb5109fa23aa3c90383de61cd69Timo Sirainenbool mailbox_list_set_error_from_errno(struct mailbox_list *list);
147a788fea2a88f7125b27226451271d55cf5b01Timo Sirainen
147a788fea2a88f7125b27226451271d55cf5b01Timo Sirainen#endif
147a788fea2a88f7125b27226451271d55cf5b01Timo Sirainen