mail-storage-private.h revision 194603b35061fea1ee8d171a7104b6985c610966
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch#ifndef MAIL_STORAGE_PRIVATE_H
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch#define MAIL_STORAGE_PRIVATE_H
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch#include "module-context.h"
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch#include "file-lock.h"
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch#include "mail-storage.h"
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch#include "mail-index-private.h"
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch/* Called after mail storage has been created */
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschextern void (*hook_mail_storage_created)(struct mail_storage *storage);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch/* Called after mailbox has been opened */
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschextern void (*hook_mailbox_opened)(struct mailbox *box);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschstruct mail_storage_module_register {
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch unsigned int id;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch};
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschstruct mail_module_register {
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch unsigned int id;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch};
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschstruct mail_storage_vfuncs {
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch void (*class_init)(void);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch void (*class_deinit)(void);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_storage *(*alloc)(void);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*create)(struct mail_storage *storage, const char *data,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch const char **error_r);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch void (*destroy)(struct mail_storage *storage);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch bool (*autodetect)(const char *data, enum mail_storage_flags flags);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mailbox *(*mailbox_open)(struct mail_storage *storage,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch const char *name,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct istream *input,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch enum mailbox_open_flags flags);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*mailbox_create)(struct mail_storage *storage, const char *name,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch bool directory);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch};
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschunion mail_storage_module_context {
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_storage_vfuncs super;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_storage_module_register *reg;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch};
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschstruct mail_storage {
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch const char *name;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch bool mailbox_is_file;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_storage_vfuncs v;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch/* private: */
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch pool_t pool;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch char *error_string;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch enum mail_error error;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_namespace *ns;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mailbox_list *list;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch const char *user; /* name of user accessing the storage */
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch enum mail_storage_flags flags;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch enum file_lock_method lock_method;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch unsigned int keyword_max_len;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_storage_callbacks *callbacks;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch void *callback_context;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch /* Module-specific contexts. See mail_storage_module_id. */
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch ARRAY_DEFINE(module_contexts, union mail_storage_module_context *);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch};
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschstruct mailbox_vfuncs {
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch bool (*is_readonly)(struct mailbox *box);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch bool (*allow_new_keywords)(struct mailbox *box);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*close)(struct mailbox *box);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch void (*get_status)(struct mailbox *box, enum mailbox_status_items items,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mailbox_status *status_r);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch /* Lookup sync extension record and figure out if it mailbox has
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch changed since. Returns 1 = yes, 0 = no, -1 = error. */
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*list_index_has_changed)(struct mailbox *box,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_index_view *list_view,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch uint32_t seq);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch /* Update the sync extension record. Returns 0 = ok, -1 = error. */
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*list_index_update_sync)(struct mailbox *box,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_index_transaction *trans,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch uint32_t seq);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mailbox_sync_context *
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch (*sync_init)(struct mailbox *box,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch enum mailbox_sync_flags flags);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch bool (*sync_next)(struct mailbox_sync_context *ctx,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mailbox_sync_rec *sync_rec_r);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*sync_deinit)(struct mailbox_sync_context *ctx,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch enum mailbox_status_items status_items,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mailbox_status *status_r);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch /* Called once for each expunge. Called one or more times for
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch flag/keyword changes. Once the sync is finished, called with
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch uid=0 and sync_type=0. */
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch void (*sync_notify)(struct mailbox *box, uint32_t uid,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch enum mailbox_sync_type sync_type);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch void (*notify_changes)(struct mailbox *box);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mailbox_transaction_context *
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch (*transaction_begin)(struct mailbox *box,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch enum mailbox_transaction_flags flags);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*transaction_commit)(struct mailbox_transaction_context *t,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch uint32_t *uid_validity_r,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch uint32_t *first_saved_uid_r,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch uint32_t *last_saved_uid_r);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch void (*transaction_rollback)(struct mailbox_transaction_context *t);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*keywords_create)(struct mailbox *box,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch const char *const keywords[],
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_keywords **keywords_r,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch bool skip_invalid);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch void (*keywords_free)(struct mail_keywords *keywords);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch void (*get_uids)(struct mailbox *box, uint32_t uid1, uint32_t uid2,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch uint32_t *seq1_r, uint32_t *seq2_r);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail *
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch (*mail_alloc)(struct mailbox_transaction_context *t,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch enum mail_fetch_field wanted_fields,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mailbox_header_lookup_ctx *wanted_headers);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mailbox_header_lookup_ctx *
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch (*header_lookup_init)(struct mailbox *box,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch const char *const headers[]);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch void (*header_lookup_deinit)(struct mailbox_header_lookup_ctx *ctx);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_search_context *
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch (*search_init)(struct mailbox_transaction_context *t,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch const char *charset, struct mail_search_arg *args,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch const enum mail_sort_type *sort_program);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*search_deinit)(struct mail_search_context *ctx);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*search_next_nonblock)(struct mail_search_context *ctx,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail *mail, bool *tryagain_r);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch /* Internal search function which updates ctx->seq */
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*search_next_update_seq)(struct mail_search_context *ctx);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*save_init)(struct mailbox_transaction_context *t,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch enum mail_flags flags,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_keywords *keywords,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch time_t received_date, int timezone_offset,
f091dd12d19df22e5403855f93dedee437bd7d87Stephan Bosch const char *from_envelope, struct istream *input,
912e87d5be9dd8895e8cb7c6cb51d8a752edbe8cStephan Bosch struct mail *dest_mail,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_save_context **ctx_r);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*save_continue)(struct mail_save_context *ctx);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*save_finish)(struct mail_save_context *ctx);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch void (*save_cancel)(struct mail_save_context *ctx);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*copy)(struct mailbox_transaction_context *t, struct mail *mail,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch enum mail_flags flags, struct mail_keywords *keywords,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail *dest_mail);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch bool (*is_inconsistent)(struct mailbox *box);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch};
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschunion mailbox_module_context {
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mailbox_vfuncs super;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_storage_module_register *reg;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch};
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschstruct mailbox {
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch char *name;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_storage *storage;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mailbox_vfuncs v;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch/* private: */
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch pool_t pool;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch unsigned int transaction_count;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch /* User's private flags if this is a shared mailbox */
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch enum mail_flags private_flags_mask;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch /* mode and GID to use for newly created files/dirs */
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch mode_t file_create_mode, dir_create_mode;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch gid_t file_create_gid;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch /* Mailbox notification settings: */
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch unsigned int notify_min_interval;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch mailbox_notify_callback_t *notify_callback;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch void *notify_context;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch /* Module-specific contexts. See mail_storage_module_id. */
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch ARRAY_DEFINE(module_contexts, union mailbox_module_context *);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch /* When FAST open flag is used, the mailbox isn't actually opened until
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch it's synced for the first time. */
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch unsigned int opened:1;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch /* Mailbox was deleted while we had it open. */
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch unsigned int mailbox_deleted:1;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch};
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschstruct mail_vfuncs {
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch void (*close)(struct mail *mail);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch void (*free)(struct mail *mail);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch void (*set_seq)(struct mail *mail, uint32_t seq);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch bool (*set_uid)(struct mail *mail, uint32_t uid);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch enum mail_flags (*get_flags)(struct mail *mail);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch const char *const *(*get_keywords)(struct mail *mail);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch const ARRAY_TYPE(keyword_indexes) *
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch (*get_keyword_indexes)(struct mail *mail);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*get_parts)(struct mail *mail,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch const struct message_part **parts_r);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*get_date)(struct mail *mail, time_t *date_r, int *timezone_r);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*get_received_date)(struct mail *mail, time_t *date_r);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*get_save_date)(struct mail *mail, time_t *date_r);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*get_virtual_size)(struct mail *mail, uoff_t *size_r);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*get_physical_size)(struct mail *mail, uoff_t *size_r);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*get_first_header)(struct mail *mail, const char *field,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch bool decode_to_utf8, const char **value_r);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*get_headers)(struct mail *mail, const char *field,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch bool decode_to_utf8, const char *const **value_r);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*get_header_stream)(struct mail *mail,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mailbox_header_lookup_ctx *headers,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct istream **stream_r);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*get_stream)(struct mail *mail, struct message_size *hdr_size,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct message_size *body_size,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct istream **stream_r);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch int (*get_special)(struct mail *mail, enum mail_fetch_field field,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch const char **value_r);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch void (*update_flags)(struct mail *mail, enum modify_type modify_type,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch enum mail_flags flags);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch void (*update_keywords)(struct mail *mail, enum modify_type modify_type,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_keywords *keywords);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch void (*expunge)(struct mail *mail);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch void (*set_cache_corrupted)(struct mail *mail,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch enum mail_fetch_field field);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch};
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschunion mail_module_context {
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_vfuncs super;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_module_register *reg;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch};
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschstruct mail_private {
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail mail;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_vfuncs v;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch pool_t pool;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch ARRAY_DEFINE(module_contexts, union mail_module_context *);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch};
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschstruct mailbox_list_context {
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_storage *storage;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch enum mailbox_list_flags flags;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch bool failed;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch};
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschunion mailbox_transaction_module_context {
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_storage_module_register *reg;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch};
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschstruct mailbox_transaction_context {
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mailbox *box;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch enum mailbox_transaction_flags flags;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch ARRAY_DEFINE(module_contexts,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch union mailbox_transaction_module_context *);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch};
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschunion mail_search_module_context {
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_storage_module_register *reg;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch};
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschstruct mail_search_context {
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mailbox_transaction_context *transaction;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch char *charset;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_search_arg *args;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail_search_sort_program *sort_program;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch uint32_t seq;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch ARRAY_DEFINE(module_contexts, union mail_search_module_context *);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch};
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschstruct mail_save_context {
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mailbox_transaction_context *transaction;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mail *dest_mail;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch};
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschstruct mailbox_sync_context {
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mailbox *box;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch};
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschstruct mailbox_header_lookup_ctx {
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch struct mailbox *box;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch};
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch/* Modules should use do "my_id = mail_storage_module_id++" and
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch use objects' module_contexts[id] for their own purposes. */
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschextern struct mail_storage_module_register mail_storage_module_register;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch/* Storage's module_id for mail_index. */
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschextern struct mail_module_register mail_module_register;
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch#define MAIL_STORAGE_CONTEXT(obj) \
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch MODULE_CONTEXT(obj, mail_storage_mail_index_module)
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschextern MODULE_CONTEXT_DEFINE(mail_storage_mail_index_module,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch &mail_index_module_register);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch/* Set error message in storage. Critical errors are logged with i_error(),
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch but user sees only "internal error" message. */
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschvoid mail_storage_clear_error(struct mail_storage *storage);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschvoid mail_storage_set_error(struct mail_storage *storage,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch enum mail_error error, const char *string);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschvoid mail_storage_set_critical(struct mail_storage *storage,
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch const char *fmt, ...) ATTR_FORMAT(2, 3);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschvoid mail_storage_set_internal_error(struct mail_storage *storage);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschbool mail_storage_set_error_from_errno(struct mail_storage *storage);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschvoid mail_set_expunged(struct mail *mail);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschvoid mailbox_set_deleted(struct mailbox *box);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschconst char *mail_storage_eacces_msg(const char *func, const char *path);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschenum mailbox_list_flags
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Boschmail_storage_get_list_flags(enum mail_storage_flags storage_flags);
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch#endif
56dd928c164ec5c0d1158a1760154b58c5f1f6e7Stephan Bosch