mail-storage-private.h revision 421d30619384e72a27e2a5d13ff6525aff4d17fe
45312f52ff3a3d4c137447be4c7556500c2f8bf2Timo Sirainen#ifndef MAIL_STORAGE_PRIVATE_H
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen#define MAIL_STORAGE_PRIVATE_H
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen#include "module-context.h"
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen#include "file-lock.h"
e28fa207d1a097fa6e4a867f74ee0761472ef1ceTimo Sirainen#include "mail-storage.h"
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen#include "mail-storage-hooks.h"
b039dabf4c53f72454e795930e7643b6e0e625f9Timo Sirainen#include "mail-storage-settings.h"
ef50336eefcb9ba99f73c6af37420eaf8857a39bTimo Sirainen#include "mail-index-private.h"
e28fa207d1a097fa6e4a867f74ee0761472ef1ceTimo Sirainen
ef50336eefcb9ba99f73c6af37420eaf8857a39bTimo Sirainen/* Block size when read()ing message header. */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen#define MAIL_READ_HDR_BLOCK_SIZE (1024*4)
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen/* Block size when read()ing message (header and) body. */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen#define MAIL_READ_FULL_BLOCK_SIZE IO_BLOCK_SIZE
5694eeb99b69dea8033ca77ad69743c6b4871370Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainenstruct mail_storage_module_register {
5694eeb99b69dea8033ca77ad69743c6b4871370Timo Sirainen unsigned int id;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen};
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainenstruct mail_module_register {
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen unsigned int id;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen};
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainenstruct mail_storage_vfuncs {
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen const struct setting_parser_info *(*get_setting_parser_info)(void);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen struct mail_storage *(*alloc)(void);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen int (*create)(struct mail_storage *storage, struct mail_namespace *ns,
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen const char **error_r);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen void (*destroy)(struct mail_storage *storage);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen void (*add_list)(struct mail_storage *storage,
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen struct mailbox_list *list);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen void (*get_list_settings)(const struct mail_namespace *ns,
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen struct mailbox_list_settings *set);
220e21750948941dc6e33b8f11b552fa21d7f81eTimo Sirainen bool (*autodetect)(const struct mail_namespace *ns,
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen struct mailbox_list_settings *set);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen struct mailbox *(*mailbox_alloc)(struct mail_storage *storage,
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen struct mailbox_list *list,
8a0ad174adb1eb5108511b90e97f4e5f9089b0eeTimo Sirainen const char *vname,
8a0ad174adb1eb5108511b90e97f4e5f9089b0eeTimo Sirainen enum mailbox_flags flags);
8a0ad174adb1eb5108511b90e97f4e5f9089b0eeTimo Sirainen int (*purge)(struct mail_storage *storage);
8a0ad174adb1eb5108511b90e97f4e5f9089b0eeTimo Sirainen};
8a0ad174adb1eb5108511b90e97f4e5f9089b0eeTimo Sirainen
8a0ad174adb1eb5108511b90e97f4e5f9089b0eeTimo Sirainenunion mail_storage_module_context {
8a0ad174adb1eb5108511b90e97f4e5f9089b0eeTimo Sirainen struct mail_storage_vfuncs super;
8a0ad174adb1eb5108511b90e97f4e5f9089b0eeTimo Sirainen struct mail_storage_module_register *reg;
8a0ad174adb1eb5108511b90e97f4e5f9089b0eeTimo Sirainen};
8a0ad174adb1eb5108511b90e97f4e5f9089b0eeTimo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainenenum mail_storage_class_flags {
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* mailboxes are files, not directories */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen MAIL_STORAGE_CLASS_FLAG_MAILBOX_IS_FILE = 0x01,
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* root_dir points to a unique directory */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen MAIL_STORAGE_CLASS_FLAG_UNIQUE_ROOT = 0x02,
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* mailbox_open_stream() is supported */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen MAIL_STORAGE_CLASS_FLAG_OPEN_STREAMS = 0x04,
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* never use quota for this storage (e.g. virtual mailboxes) */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen MAIL_STORAGE_CLASS_FLAG_NOQUOTA = 0x08,
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Storage doesn't need a mail root directory */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen MAIL_STORAGE_CLASS_FLAG_NO_ROOT = 0x10,
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Storage uses one file per message */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen MAIL_STORAGE_CLASS_FLAG_FILE_PER_MSG = 0x20
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen};
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainenstruct mail_storage {
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen const char *name;
8a0ad174adb1eb5108511b90e97f4e5f9089b0eeTimo Sirainen enum mail_storage_class_flags class_flags;
8a0ad174adb1eb5108511b90e97f4e5f9089b0eeTimo Sirainen
8a0ad174adb1eb5108511b90e97f4e5f9089b0eeTimo Sirainen struct mail_storage_vfuncs v, *vlast;
8a0ad174adb1eb5108511b90e97f4e5f9089b0eeTimo Sirainen
8a0ad174adb1eb5108511b90e97f4e5f9089b0eeTimo Sirainen/* private: */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen pool_t pool;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen struct mail_storage *prev, *next;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* counting number of times mail_storage_create() has returned this
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen same storage. */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen int refcount;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* counting number of objects (e.g. mailbox) that have a pointer
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen to this storage. */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen int obj_refcount;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen const char *unique_root_dir;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen char *error_string;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen enum mail_error error;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen const struct mail_storage *storage_class;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen struct mail_user *user;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen const char *temp_path_prefix;
1701e3f91107051b1704721bf1dc1e32491faaf9Timo Sirainen const struct mail_storage_settings *set;
1701e3f91107051b1704721bf1dc1e32491faaf9Timo Sirainen uint32_t list_sync_ext_id;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen enum mail_storage_flags flags;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen struct mail_storage_callbacks callbacks;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen void *callback_context;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
2dd39e478269d6fb0bb26d12b394aa30ee965e38Timo Sirainen /* Module-specific contexts. See mail_storage_module_id. */
2dd39e478269d6fb0bb26d12b394aa30ee965e38Timo Sirainen ARRAY_DEFINE(module_contexts, union mail_storage_module_context *);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen};
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainenstruct mail_attachment_part {
1701e3f91107051b1704721bf1dc1e32491faaf9Timo Sirainen struct message_part *part;
1701e3f91107051b1704721bf1dc1e32491faaf9Timo Sirainen const char *content_type, *content_disposition;
1701e3f91107051b1704721bf1dc1e32491faaf9Timo Sirainen};
1701e3f91107051b1704721bf1dc1e32491faaf9Timo Sirainen
1701e3f91107051b1704721bf1dc1e32491faaf9Timo Sirainenstruct mailbox_vfuncs {
1701e3f91107051b1704721bf1dc1e32491faaf9Timo Sirainen bool (*is_readonly)(struct mailbox *box);
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen int (*enable)(struct mailbox *box, enum mailbox_feature features);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen int (*exists)(struct mailbox *box, bool auto_boxes,
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen enum mailbox_existence *existence_r);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen int (*open)(struct mailbox *box);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen void (*close)(struct mailbox *box);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen void (*free)(struct mailbox *box);
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen int (*create)(struct mailbox *box, const struct mailbox_update *update,
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen bool directory);
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen int (*update)(struct mailbox *box, const struct mailbox_update *update);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen int (*delete)(struct mailbox *box);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen int (*rename)(struct mailbox *src, struct mailbox *dest,
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen bool rename_children);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen
96f2533c48ce5def0004931606a2fdf275578880Timo Sirainen int (*get_status)(struct mailbox *box, enum mailbox_status_items items,
4645cc6c911a95991d7af43b40f88e99506ea5e9Timo Sirainen struct mailbox_status *status_r);
4645cc6c911a95991d7af43b40f88e99506ea5e9Timo Sirainen int (*get_metadata)(struct mailbox *box,
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen enum mailbox_metadata_items items,
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen struct mailbox_metadata *metadata_r);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen /* Lookup sync extension record and figure out if it mailbox has
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen changed since. Returns 1 = yes, 0 = no, -1 = error. */
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen int (*list_index_has_changed)(struct mailbox *box,
4645cc6c911a95991d7af43b40f88e99506ea5e9Timo Sirainen struct mail_index_view *list_view,
4645cc6c911a95991d7af43b40f88e99506ea5e9Timo Sirainen uint32_t seq);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen /* Update the sync extension record. */
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen void (*list_index_update_sync)(struct mailbox *box,
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen struct mail_index_transaction *trans,
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen uint32_t seq);
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen struct mailbox_sync_context *
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen (*sync_init)(struct mailbox *box,
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen enum mailbox_sync_flags flags);
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen bool (*sync_next)(struct mailbox_sync_context *ctx,
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen struct mailbox_sync_rec *sync_rec_r);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen int (*sync_deinit)(struct mailbox_sync_context *ctx,
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen struct mailbox_sync_status *status_r);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen /* Called once for each expunge. Called one or more times for
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen flag/keyword changes. Once the sync is finished, called with
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen uid=0 and sync_type=0. */
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen void (*sync_notify)(struct mailbox *box, uint32_t uid,
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen enum mailbox_sync_type sync_type);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen void (*notify_changes)(struct mailbox *box);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen struct mailbox_transaction_context *
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen (*transaction_begin)(struct mailbox *box,
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen enum mailbox_transaction_flags flags);
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen int (*transaction_commit)(struct mailbox_transaction_context *t,
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen struct mail_transaction_commit_changes *changes_r);
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen void (*transaction_rollback)(struct mailbox_transaction_context *t);
4645cc6c911a95991d7af43b40f88e99506ea5e9Timo Sirainen
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen enum mail_flags (*get_private_flags_mask)(struct mailbox *box);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen struct mail *
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen (*mail_alloc)(struct mailbox_transaction_context *t,
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen enum mail_fetch_field wanted_fields,
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen struct mailbox_header_lookup_ctx *wanted_headers);
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen
5494a6bc149da8f02fd25c0434a9d612ac33f659Timo Sirainen struct mail_search_context *
5494a6bc149da8f02fd25c0434a9d612ac33f659Timo Sirainen (*search_init)(struct mailbox_transaction_context *t,
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen struct mail_search_args *args,
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen const enum mail_sort_type *sort_program,
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen enum mail_fetch_field wanted_fields,
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers);
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen int (*search_deinit)(struct mail_search_context *ctx);
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen bool (*search_next_nonblock)(struct mail_search_context *ctx,
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen struct mail **mail_r, bool *tryagain_r);
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen /* Internal search function which updates ctx->seq */
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen bool (*search_next_update_seq)(struct mail_search_context *ctx);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen struct mail_save_context *
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen (*save_alloc)(struct mailbox_transaction_context *t);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen int (*save_begin)(struct mail_save_context *ctx, struct istream *input);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen int (*save_continue)(struct mail_save_context *ctx);
a1d8f53f21be1b5755836fe3ff9faa08e3d08843Timo Sirainen int (*save_finish)(struct mail_save_context *ctx);
a1d8f53f21be1b5755836fe3ff9faa08e3d08843Timo Sirainen void (*save_cancel)(struct mail_save_context *ctx);
a1d8f53f21be1b5755836fe3ff9faa08e3d08843Timo Sirainen int (*copy)(struct mail_save_context *ctx, struct mail *mail);
a1d8f53f21be1b5755836fe3ff9faa08e3d08843Timo Sirainen
a1d8f53f21be1b5755836fe3ff9faa08e3d08843Timo Sirainen /* Called during transaction commit/rollback if saving was done */
a1d8f53f21be1b5755836fe3ff9faa08e3d08843Timo Sirainen int (*transaction_save_commit_pre)(struct mail_save_context *save_ctx);
a1d8f53f21be1b5755836fe3ff9faa08e3d08843Timo Sirainen void (*transaction_save_commit_post)
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen (struct mail_save_context *save_ctx,
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen struct mail_index_transaction_commit_result *result_r);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen void (*transaction_save_rollback)(struct mail_save_context *save_ctx);
1701e3f91107051b1704721bf1dc1e32491faaf9Timo Sirainen
1701e3f91107051b1704721bf1dc1e32491faaf9Timo Sirainen bool (*is_inconsistent)(struct mailbox *box);
1701e3f91107051b1704721bf1dc1e32491faaf9Timo Sirainen};
1701e3f91107051b1704721bf1dc1e32491faaf9Timo Sirainen
740dfc753f1f087f0c41082e4c551053129e875dTimo Sirainenunion mailbox_module_context {
740dfc753f1f087f0c41082e4c551053129e875dTimo Sirainen struct mailbox_vfuncs super;
740dfc753f1f087f0c41082e4c551053129e875dTimo Sirainen struct mail_storage_module_register *reg;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen};
c58906589cafc32df4c04ffbef933baadd3f2276Timo Sirainen
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenstruct mailbox {
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen const char *name;
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen /* mailbox's virtual name (from mail_namespace_get_vname()) */
106b804c819443791f1324f8bbe34429eeea6a13Timo Sirainen const char *vname;
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen struct mail_storage *storage;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen struct mailbox_list *list;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen struct mailbox_vfuncs v, *vlast;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen/* private: */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen pool_t pool;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* these won't be set until mailbox is opened: */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen struct mail_index *index;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen struct mail_index_view *view;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen struct mail_cache *cache;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Filled lazily by mailbox_get_permissions() */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen struct mailbox_permissions _perm;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Filled lazily by mailbox_get_path() */
bbd0a870f8639767e4e4011d2aedadac08d5c66fTimo Sirainen const char *_path;
bbd0a870f8639767e4e4011d2aedadac08d5c66fTimo Sirainen
bbd0a870f8639767e4e4011d2aedadac08d5c66fTimo Sirainen /* default vfuncs for new struct mails. */
a1d8f53f21be1b5755836fe3ff9faa08e3d08843Timo Sirainen const struct mail_vfuncs *mail_vfuncs;
a1d8f53f21be1b5755836fe3ff9faa08e3d08843Timo Sirainen
c42286c1274b0fd02a1ba636106a2977a94b55efTimo Sirainen /* If non-zero, fail mailbox_open() with this error. mailbox_alloc()
c42286c1274b0fd02a1ba636106a2977a94b55efTimo Sirainen can set this to force open to fail. */
c42286c1274b0fd02a1ba636106a2977a94b55efTimo Sirainen enum mail_error open_error;
c42286c1274b0fd02a1ba636106a2977a94b55efTimo Sirainen
c42286c1274b0fd02a1ba636106a2977a94b55efTimo Sirainen struct istream *input;
c42286c1274b0fd02a1ba636106a2977a94b55efTimo Sirainen const char *index_prefix;
c42286c1274b0fd02a1ba636106a2977a94b55efTimo Sirainen enum mailbox_flags flags;
c42286c1274b0fd02a1ba636106a2977a94b55efTimo Sirainen unsigned int transaction_count;
c42286c1274b0fd02a1ba636106a2977a94b55efTimo Sirainen enum mailbox_feature enabled_features;
c42286c1274b0fd02a1ba636106a2977a94b55efTimo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Mailbox notification settings: */
5fb3bff645380804c9db2510940c41db6b8fdb01Timo Sirainen unsigned int notify_min_interval;
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen mailbox_notify_callback_t *notify_callback;
5fb3bff645380804c9db2510940c41db6b8fdb01Timo Sirainen void *notify_context;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Increased by one for each new struct mailbox. */
06f2599faace2943684f7b3d0de2bda6c60457c8Timo Sirainen unsigned int generation_sequence;
06f2599faace2943684f7b3d0de2bda6c60457c8Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Saved search results */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen ARRAY_DEFINE(search_results, struct mail_search_result *);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Module-specific contexts. See mail_storage_module_id. */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen ARRAY_DEFINE(module_contexts, union mailbox_module_context *);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* When FAST open flag is used, the mailbox isn't actually opened until
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen it's synced for the first time. */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen unsigned int opened:1;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Mailbox was deleted while we had it open. */
5fb3bff645380804c9db2510940c41db6b8fdb01Timo Sirainen unsigned int mailbox_deleted:1;
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen /* Mailbox is being created */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen unsigned int creating:1;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Mailbox is being deleted */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen unsigned int deleting:1;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Mailbox was already marked as deleted within this allocation. */
ff7056842f14fd3b30a2d327dfab165b9d15dd30Timo Sirainen unsigned int marked_deleted:1;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* TRUE if this is an INBOX for this user */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen unsigned int inbox_user:1;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* TRUE if this is an INBOX for this namespace (user or shared) */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen unsigned int inbox_any:1;
68a4946b12583b88fa802e52ebee45cd96056772Timo Sirainen /* When copying to this mailbox, require that mailbox_copy() uses
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen mailbox_save_*() to actually save a new physical copy rather than
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen simply incrementing a reference count (e.g. via hard link) */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen unsigned int disable_reflink_copy_to:1;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen};
68a4946b12583b88fa802e52ebee45cd96056772Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainenstruct mail_vfuncs {
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen void (*close)(struct mail *mail);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen void (*free)(struct mail *mail);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen void (*set_seq)(struct mail *mail, uint32_t seq, bool saving);
68a4946b12583b88fa802e52ebee45cd96056772Timo Sirainen bool (*set_uid)(struct mail *mail, uint32_t uid);
c58906589cafc32df4c04ffbef933baadd3f2276Timo Sirainen void (*set_uid_cache_updates)(struct mail *mail, bool set);
c58906589cafc32df4c04ffbef933baadd3f2276Timo Sirainen bool (*prefetch)(struct mail *mail);
c58906589cafc32df4c04ffbef933baadd3f2276Timo Sirainen void (*precache)(struct mail *mail);
c58906589cafc32df4c04ffbef933baadd3f2276Timo Sirainen
68a4946b12583b88fa802e52ebee45cd96056772Timo Sirainen enum mail_flags (*get_flags)(struct mail *mail);
68a4946b12583b88fa802e52ebee45cd96056772Timo Sirainen const char *const *(*get_keywords)(struct mail *mail);
c58906589cafc32df4c04ffbef933baadd3f2276Timo Sirainen const ARRAY_TYPE(keyword_indexes) *
c58906589cafc32df4c04ffbef933baadd3f2276Timo Sirainen (*get_keyword_indexes)(struct mail *mail);
c58906589cafc32df4c04ffbef933baadd3f2276Timo Sirainen uint64_t (*get_modseq)(struct mail *mail);
c58906589cafc32df4c04ffbef933baadd3f2276Timo Sirainen
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainen int (*get_parts)(struct mail *mail,
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainen struct message_part **parts_r);
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainen int (*get_date)(struct mail *mail, time_t *date_r, int *timezone_r);
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainen int (*get_received_date)(struct mail *mail, time_t *date_r);
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainen int (*get_save_date)(struct mail *mail, time_t *date_r);
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainen int (*get_virtual_size)(struct mail *mail, uoff_t *size_r);
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainen int (*get_physical_size)(struct mail *mail, uoff_t *size_r);
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainen
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainen int (*get_first_header)(struct mail *mail, const char *field,
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen bool decode_to_utf8, const char **value_r);
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen int (*get_headers)(struct mail *mail, const char *field,
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen bool decode_to_utf8, const char *const **value_r);
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen int (*get_header_stream)(struct mail *mail,
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen struct mailbox_header_lookup_ctx *headers,
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen struct istream **stream_r);
b82d6d7f02734007c129fa25bc876049c8d9bddeTimo Sirainen int (*get_stream)(struct mail *mail, struct message_size *hdr_size,
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen struct message_size *body_size,
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen struct istream **stream_r);
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen int (*get_special)(struct mail *mail, enum mail_fetch_field field,
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen const char **value_r);
b82d6d7f02734007c129fa25bc876049c8d9bddeTimo Sirainen struct mail *(*get_real_mail)(struct mail *mail);
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen void (*update_flags)(struct mail *mail, enum modify_type modify_type,
bc564f1d3d953cf724828322b11ae89e0f59ffc9Timo Sirainen enum mail_flags flags);
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen void (*update_keywords)(struct mail *mail, enum modify_type modify_type,
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen struct mail_keywords *keywords);
b82d6d7f02734007c129fa25bc876049c8d9bddeTimo Sirainen void (*update_modseq)(struct mail *mail, uint64_t min_modseq);
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen void (*update_pop3_uidl)(struct mail *mail, const char *uidl);
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen void (*expunge)(struct mail *mail);
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen void (*set_cache_corrupted)(struct mail *mail,
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen enum mail_fetch_field field);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen int (*istream_opened)(struct mail *mail, struct istream **input);
c78e7a94528078728cc639b26a1c83e11b4d7e1bTimo Sirainen};
c78e7a94528078728cc639b26a1c83e11b4d7e1bTimo Sirainen
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainenunion mail_module_context {
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen struct mail_vfuncs super;
e91543761d0b7b97a1dc28e036e44d76405545c2Timo Sirainen struct mail_module_register *reg;
e91543761d0b7b97a1dc28e036e44d76405545c2Timo Sirainen};
e91543761d0b7b97a1dc28e036e44d76405545c2Timo Sirainen
e91543761d0b7b97a1dc28e036e44d76405545c2Timo Sirainenstruct mail_private {
e91543761d0b7b97a1dc28e036e44d76405545c2Timo Sirainen struct mail mail;
e91543761d0b7b97a1dc28e036e44d76405545c2Timo Sirainen struct mail_vfuncs v, *vlast;
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen enum mail_fetch_field wanted_fields;
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen struct mailbox_header_lookup_ctx *wanted_headers;
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen
106b804c819443791f1324f8bbe34429eeea6a13Timo Sirainen pool_t pool;
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainen ARRAY_DEFINE(module_contexts, union mail_module_context *);
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainen};
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainen
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainenstruct mailbox_list_context {
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainen struct mail_storage *storage;
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainen enum mailbox_list_flags flags;
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen bool failed;
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen};
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen
106b804c819443791f1324f8bbe34429eeea6a13Timo Sirainenunion mailbox_transaction_module_context {
509daf558a54d7d1c8006c54ef799cb99e31662eTimo Sirainen struct mail_storage_module_register *reg;
509daf558a54d7d1c8006c54ef799cb99e31662eTimo Sirainen};
509daf558a54d7d1c8006c54ef799cb99e31662eTimo Sirainen
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainenstruct mailbox_transaction_stats {
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen unsigned long open_lookup_count;
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen unsigned long stat_lookup_count;
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen unsigned long fstat_lookup_count;
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen /* number of files we've opened and read */
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen unsigned long files_read_count;
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen /* number of bytes we've had to read from files */
fe813f74aaccb12f38e1bd9cd338c6a37fa646e5Timo Sirainen unsigned long long files_read_bytes;
c78e7a94528078728cc639b26a1c83e11b4d7e1bTimo Sirainen /* number of cache lookup hits */
c78e7a94528078728cc639b26a1c83e11b4d7e1bTimo Sirainen unsigned long cache_hit_count;
106b804c819443791f1324f8bbe34429eeea6a13Timo Sirainen};
c78e7a94528078728cc639b26a1c83e11b4d7e1bTimo Sirainen
c78e7a94528078728cc639b26a1c83e11b4d7e1bTimo Sirainenstruct mailbox_transaction_context {
c78e7a94528078728cc639b26a1c83e11b4d7e1bTimo Sirainen struct mailbox *box;
c78e7a94528078728cc639b26a1c83e11b4d7e1bTimo Sirainen enum mailbox_transaction_flags flags;
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen union mail_index_transaction_module_context module_ctx;
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen struct mail_index_transaction_vfuncs super;
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen int mail_ref_count;
fea7b8b3fc182e415b1875d79587c0aa1adb09d7Timo Sirainen
b82d6d7f02734007c129fa25bc876049c8d9bddeTimo Sirainen struct mail_index_transaction *itrans;
fea7b8b3fc182e415b1875d79587c0aa1adb09d7Timo Sirainen /* view contains all changes done within this transaction */
fea7b8b3fc182e415b1875d79587c0aa1adb09d7Timo Sirainen struct mail_index_view *view;
fea7b8b3fc182e415b1875d79587c0aa1adb09d7Timo Sirainen
fea7b8b3fc182e415b1875d79587c0aa1adb09d7Timo Sirainen struct mail_cache_view *cache_view;
b82d6d7f02734007c129fa25bc876049c8d9bddeTimo Sirainen struct mail_cache_transaction_ctx *cache_trans;
106b804c819443791f1324f8bbe34429eeea6a13Timo Sirainen
fea7b8b3fc182e415b1875d79587c0aa1adb09d7Timo Sirainen struct mail_transaction_commit_changes *changes;
fea7b8b3fc182e415b1875d79587c0aa1adb09d7Timo Sirainen ARRAY_DEFINE(module_contexts,
533bfba437e4120aa29dd45bca2aa87e30ee28a2Timo Sirainen union mailbox_transaction_module_context *);
533bfba437e4120aa29dd45bca2aa87e30ee28a2Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen struct mail_save_context *save_ctx;
533bfba437e4120aa29dd45bca2aa87e30ee28a2Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* these statistics are never reset by mail-storage API: */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen struct mailbox_transaction_stats stats;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Set to TRUE to update stats_* fields */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen unsigned int stats_track:1;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen};
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainenunion mail_search_module_context {
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen struct mail_storage_module_register *reg;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen};
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainenstruct mail_search_context {
e28fa207d1a097fa6e4a867f74ee0761472ef1ceTimo Sirainen struct mailbox_transaction_context *transaction;
e28fa207d1a097fa6e4a867f74ee0761472ef1ceTimo Sirainen
e28fa207d1a097fa6e4a867f74ee0761472ef1ceTimo Sirainen struct mail_search_args *args;
e28fa207d1a097fa6e4a867f74ee0761472ef1ceTimo Sirainen struct mail_search_sort_program *sort_program;
e28fa207d1a097fa6e4a867f74ee0761472ef1ceTimo Sirainen enum mail_fetch_field wanted_fields;
e28fa207d1a097fa6e4a867f74ee0761472ef1ceTimo Sirainen struct mailbox_header_lookup_ctx *wanted_headers;
e28fa207d1a097fa6e4a867f74ee0761472ef1ceTimo Sirainen
e28fa207d1a097fa6e4a867f74ee0761472ef1ceTimo Sirainen /* if non-NULL, specifies that a search resulting is being updated.
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen this can be used as a search optimization: if searched message
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen already exists in search result, it's not necessary to check if
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen static data matches. */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen struct mail_search_result *update_result;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* add matches to these search results */
5160580b0ec3f3288a320987abdf12a990f09df5Timo Sirainen ARRAY_DEFINE(results, struct mail_search_result *);
5160580b0ec3f3288a320987abdf12a990f09df5Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen uint32_t seq;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen uint32_t progress_cur, progress_max;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen ARRAY_DEFINE(module_contexts, union mail_search_module_context *);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
c040ee67d0ac0fb7375bb543965bf67dcae6affaTimo Sirainen unsigned int seen_lost_data:1;
c040ee67d0ac0fb7375bb543965bf67dcae6affaTimo Sirainen unsigned int progress_hidden:1;
c040ee67d0ac0fb7375bb543965bf67dcae6affaTimo Sirainen};
c040ee67d0ac0fb7375bb543965bf67dcae6affaTimo Sirainen
c040ee67d0ac0fb7375bb543965bf67dcae6affaTimo Sirainenstruct mail_save_context {
c040ee67d0ac0fb7375bb543965bf67dcae6affaTimo Sirainen struct mailbox_transaction_context *transaction;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen struct mail *dest_mail;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
533bfba437e4120aa29dd45bca2aa87e30ee28a2Timo Sirainen enum mail_flags flags;
533bfba437e4120aa29dd45bca2aa87e30ee28a2Timo Sirainen struct mail_keywords *keywords;
5fb3bff645380804c9db2510940c41db6b8fdb01Timo Sirainen uint64_t min_modseq;
533bfba437e4120aa29dd45bca2aa87e30ee28a2Timo Sirainen
533bfba437e4120aa29dd45bca2aa87e30ee28a2Timo Sirainen time_t received_date, save_date;
5160580b0ec3f3288a320987abdf12a990f09df5Timo Sirainen int received_tz_offset;
5160580b0ec3f3288a320987abdf12a990f09df5Timo Sirainen
5160580b0ec3f3288a320987abdf12a990f09df5Timo Sirainen uint32_t uid;
533bfba437e4120aa29dd45bca2aa87e30ee28a2Timo Sirainen char *guid, *pop3_uidl, *from_envelope;
533bfba437e4120aa29dd45bca2aa87e30ee28a2Timo Sirainen struct ostream *output;
5160580b0ec3f3288a320987abdf12a990f09df5Timo Sirainen
533bfba437e4120aa29dd45bca2aa87e30ee28a2Timo Sirainen struct mail_save_attachment *attach;
5fb3bff645380804c9db2510940c41db6b8fdb01Timo Sirainen
5fb3bff645380804c9db2510940c41db6b8fdb01Timo Sirainen /* returns TRUE if message part is an attachment. */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen bool (*part_is_attachment)(struct mail_save_context *ctx,
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen const struct mail_attachment_part *part);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* we came here from mailbox_copy() */
5160580b0ec3f3288a320987abdf12a990f09df5Timo Sirainen unsigned int copying:1;
5160580b0ec3f3288a320987abdf12a990f09df5Timo Sirainen};
5160580b0ec3f3288a320987abdf12a990f09df5Timo Sirainen
5160580b0ec3f3288a320987abdf12a990f09df5Timo Sirainenstruct mailbox_sync_context {
5160580b0ec3f3288a320987abdf12a990f09df5Timo Sirainen struct mailbox *box;
5160580b0ec3f3288a320987abdf12a990f09df5Timo Sirainen enum mailbox_sync_flags flags;
5160580b0ec3f3288a320987abdf12a990f09df5Timo Sirainen};
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainenstruct mailbox_header_lookup_ctx {
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen struct mailbox *box;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen pool_t pool;
533bfba437e4120aa29dd45bca2aa87e30ee28a2Timo Sirainen int refcount;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen unsigned int count;
d92f33f13830ba23d814342bf3ea8db721a15bb1Timo Sirainen const char *const *name;
d92f33f13830ba23d814342bf3ea8db721a15bb1Timo Sirainen unsigned int *idx;
d92f33f13830ba23d814342bf3ea8db721a15bb1Timo Sirainen};
d92f33f13830ba23d814342bf3ea8db721a15bb1Timo Sirainen
d92f33f13830ba23d814342bf3ea8db721a15bb1Timo Sirainen/* Modules should use do "my_id = mail_storage_module_id++" and
d92f33f13830ba23d814342bf3ea8db721a15bb1Timo Sirainen use objects' module_contexts[id] for their own purposes. */
f97cacf16251b42f530c6a28686cc8c9aa7df3a2Timo Sirainenextern struct mail_storage_module_register mail_storage_module_register;
d92f33f13830ba23d814342bf3ea8db721a15bb1Timo Sirainen
d92f33f13830ba23d814342bf3ea8db721a15bb1Timo Sirainen/* Storage's module_id for mail_index. */
d92f33f13830ba23d814342bf3ea8db721a15bb1Timo Sirainenextern struct mail_module_register mail_module_register;
d92f33f13830ba23d814342bf3ea8db721a15bb1Timo Sirainen
d92f33f13830ba23d814342bf3ea8db721a15bb1Timo Sirainen#define MAIL_STORAGE_CONTEXT(obj) \
d92f33f13830ba23d814342bf3ea8db721a15bb1Timo Sirainen MODULE_CONTEXT(obj, mail_storage_mail_index_module)
d92f33f13830ba23d814342bf3ea8db721a15bb1Timo Sirainenextern MODULE_CONTEXT_DEFINE(mail_storage_mail_index_module,
d92f33f13830ba23d814342bf3ea8db721a15bb1Timo Sirainen &mail_index_module_register);
d92f33f13830ba23d814342bf3ea8db721a15bb1Timo Sirainen
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainenvoid mail_storage_obj_ref(struct mail_storage *storage);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainenvoid mail_storage_obj_unref(struct mail_storage *storage);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen/* Set error message in storage. Critical errors are logged with i_error(),
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen but user sees only "internal error" message. */
de486b59018016977015ef42e6071155b60e82e1Timo Sirainenvoid mail_storage_clear_error(struct mail_storage *storage);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainenvoid mail_storage_set_error(struct mail_storage *storage,
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen enum mail_error error, const char *string);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainenvoid mail_storage_set_critical(struct mail_storage *storage,
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen const char *fmt, ...) ATTR_FORMAT(2, 3);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainenvoid mail_storage_set_internal_error(struct mail_storage *storage);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainenvoid mail_storage_set_index_error(struct mailbox *box);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainenbool mail_storage_set_error_from_errno(struct mail_storage *storage);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainenvoid mail_storage_copy_list_error(struct mail_storage *storage,
407453d06e5622ac3bf099cc76bfcbfb5860b444Timo Sirainen struct mailbox_list *list);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen/* Returns TRUE if everything should already be in memory after this call. */
de486b59018016977015ef42e6071155b60e82e1Timo Sirainenbool mail_prefetch(struct mail *mail);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainenint mail_set_aborted(struct mail *mail);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainenvoid mail_set_expunged(struct mail *mail);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainenvoid mail_set_seq_saving(struct mail *mail, uint32_t seq);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainenvoid mailbox_set_deleted(struct mailbox *box);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainenint mailbox_mark_index_deleted(struct mailbox *box, bool del);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen/* Easy wrapper for getting mailbox's MAILBOX_LIST_PATH_TYPE_MAILBOX */
de486b59018016977015ef42e6071155b60e82e1Timo Sirainenconst char *mailbox_get_path(struct mailbox *box) ATTR_PURE;
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen/* Get mailbox permissions. */
de486b59018016977015ef42e6071155b60e82e1Timo Sirainenconst struct mailbox_permissions *mailbox_get_permissions(struct mailbox *box);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen/* Force permissions to be refreshed on next lookup */
de486b59018016977015ef42e6071155b60e82e1Timo Sirainenvoid mailbox_refresh_permissions(struct mailbox *box);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen/* Returns -1 if error, 0 if failed with EEXIST, 1 if ok */
de486b59018016977015ef42e6071155b60e82e1Timo Sirainenint mailbox_create_fd(struct mailbox *box, const char *path, int flags,
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen int *fd_r);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainenunsigned int mail_storage_get_lock_timeout(struct mail_storage *storage,
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen unsigned int secs);
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen#endif
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen