mail-storage-private.h revision 421d30619384e72a27e2a5d13ff6525aff4d17fe
ef50336eefcb9ba99f73c6af37420eaf8857a39bTimo Sirainen/* Block size when read()ing message header. */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen/* Block size when read()ing message (header and) body. */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen#define MAIL_READ_FULL_BLOCK_SIZE IO_BLOCK_SIZE
5694eeb99b69dea8033ca77ad69743c6b4871370Timo Sirainen unsigned int id;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen unsigned int id;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen const struct setting_parser_info *(*get_setting_parser_info)(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 void (*get_list_settings)(const struct mail_namespace *ns,
220e21750948941dc6e33b8f11b552fa21d7f81eTimo Sirainen bool (*autodetect)(const struct mail_namespace *ns,
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen struct mailbox *(*mailbox_alloc)(struct mail_storage *storage,
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 /* mailbox_open_stream() is supported */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* never use quota for this storage (e.g. virtual mailboxes) */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Storage doesn't need a mail root directory */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Storage uses one file per message */
8a0ad174adb1eb5108511b90e97f4e5f9089b0eeTimo Sirainen/* private: */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* counting number of times mail_storage_create() has returned this
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen same storage. */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* counting number of objects (e.g. mailbox) that have a pointer
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen to this storage. */
2dd39e478269d6fb0bb26d12b394aa30ee965e38Timo Sirainen /* Module-specific contexts. See mail_storage_module_id. */
2dd39e478269d6fb0bb26d12b394aa30ee965e38Timo Sirainen ARRAY_DEFINE(module_contexts, union mail_storage_module_context *);
1701e3f91107051b1704721bf1dc1e32491faaf9Timo Sirainen const char *content_type, *content_disposition;
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen int (*enable)(struct mailbox *box, enum mailbox_feature features);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen int (*exists)(struct mailbox *box, bool auto_boxes,
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen int (*create)(struct mailbox *box, const struct mailbox_update *update,
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen int (*update)(struct mailbox *box, const struct mailbox_update *update);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen int (*rename)(struct mailbox *src, struct mailbox *dest,
96f2533c48ce5def0004931606a2fdf275578880Timo Sirainen int (*get_status)(struct mailbox *box, enum mailbox_status_items items,
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,
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen /* Update the sync extension record. */
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen void (*list_index_update_sync)(struct mailbox *box,
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen bool (*sync_next)(struct mailbox_sync_context *ctx,
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen int (*sync_deinit)(struct mailbox_sync_context *ctx,
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,
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);
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen enum mail_flags (*get_private_flags_mask)(struct mailbox *box);
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen (*mail_alloc)(struct mailbox_transaction_context *t,
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen struct mailbox_header_lookup_ctx *wanted_headers);
5494a6bc149da8f02fd25c0434a9d612ac33f659Timo Sirainen (*search_init)(struct mailbox_transaction_context *t,
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 /* Internal search function which updates ctx->seq */
02e61e13a8360a9d3ec92c5fa5ae60c0f0181b71Timo Sirainen bool (*search_next_update_seq)(struct mail_search_context *ctx);
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 /* Called during transaction commit/rollback if saving was done */
a1d8f53f21be1b5755836fe3ff9faa08e3d08843Timo Sirainen int (*transaction_save_commit_pre)(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);
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen /* mailbox's virtual name (from mail_namespace_get_vname()) */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen/* private: */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* these won't be set until mailbox is opened: */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Filled lazily by mailbox_get_permissions() */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Filled lazily by mailbox_get_path() */
bbd0a870f8639767e4e4011d2aedadac08d5c66fTimo Sirainen /* default vfuncs for new struct mails. */
c42286c1274b0fd02a1ba636106a2977a94b55efTimo Sirainen /* If non-zero, fail mailbox_open() with this error. mailbox_alloc()
c42286c1274b0fd02a1ba636106a2977a94b55efTimo Sirainen can set this to force open to fail. */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Mailbox notification settings: */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Increased by one for each new struct mailbox. */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Saved search results */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen ARRAY_DEFINE(search_results, struct mail_search_result *);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Module-specific contexts. See mail_storage_module_id. */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen ARRAY_DEFINE(module_contexts, union mailbox_module_context *);
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 /* Mailbox was deleted while we had it open. */
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen /* Mailbox is being created */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Mailbox is being deleted */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Mailbox was already marked as deleted within this allocation. */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* TRUE if this is an INBOX for this user */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* TRUE if this is an INBOX for this namespace (user or shared) */
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 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);
68a4946b12583b88fa802e52ebee45cd96056772Timo Sirainen enum mail_flags (*get_flags)(struct mail *mail);
68a4946b12583b88fa802e52ebee45cd96056772Timo Sirainen const char *const *(*get_keywords)(struct mail *mail);
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 int (*get_first_header)(struct mail *mail, const char *field,
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen int (*get_headers)(struct mail *mail, const char *field,
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen bool decode_to_utf8, const char *const **value_r);
b82d6d7f02734007c129fa25bc876049c8d9bddeTimo Sirainen int (*get_stream)(struct mail *mail, struct message_size *hdr_size,
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 void (*update_flags)(struct mail *mail, enum modify_type modify_type,
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen void (*update_keywords)(struct mail *mail, enum modify_type modify_type,
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 (*set_cache_corrupted)(struct mail *mail,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen int (*istream_opened)(struct mail *mail, struct istream **input);
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen struct mailbox_header_lookup_ctx *wanted_headers;
6dd77763f5451269ace733579cf58f2f3b18bca4Timo Sirainen ARRAY_DEFINE(module_contexts, union mail_module_context *);
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen /* number of files we've opened and read */
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 */
d02d34e138e32b4266f5a403d6c51d7803bf322fTimo Sirainen union mail_index_transaction_module_context module_ctx;
fea7b8b3fc182e415b1875d79587c0aa1adb09d7Timo Sirainen /* view contains all changes done within this transaction */
b82d6d7f02734007c129fa25bc876049c8d9bddeTimo Sirainen struct mail_cache_transaction_ctx *cache_trans;
fea7b8b3fc182e415b1875d79587c0aa1adb09d7Timo Sirainen struct mail_transaction_commit_changes *changes;
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* these statistics are never reset by mail-storage API: */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* Set to TRUE to update stats_* fields */
e28fa207d1a097fa6e4a867f74ee0761472ef1ceTimo Sirainen struct mailbox_transaction_context *transaction;
e28fa207d1a097fa6e4a867f74ee0761472ef1ceTimo Sirainen struct mail_search_sort_program *sort_program;
e28fa207d1a097fa6e4a867f74ee0761472ef1ceTimo Sirainen struct mailbox_header_lookup_ctx *wanted_headers;
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 /* add matches to these search results */
5160580b0ec3f3288a320987abdf12a990f09df5Timo Sirainen ARRAY_DEFINE(results, struct mail_search_result *);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen ARRAY_DEFINE(module_contexts, union mail_search_module_context *);
c040ee67d0ac0fb7375bb543965bf67dcae6affaTimo Sirainen struct mailbox_transaction_context *transaction;
5fb3bff645380804c9db2510940c41db6b8fdb01Timo Sirainen /* returns TRUE if message part is an attachment. */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen bool (*part_is_attachment)(struct mail_save_context *ctx,
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* we came here from mailbox_copy() */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen unsigned int count;
d92f33f13830ba23d814342bf3ea8db721a15bb1Timo Sirainen const char *const *name;
d92f33f13830ba23d814342bf3ea8db721a15bb1Timo Sirainen unsigned int *idx;
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/* Storage's module_id for mail_index. */
d92f33f13830ba23d814342bf3ea8db721a15bb1Timo Sirainenextern struct mail_module_register mail_module_register;
d92f33f13830ba23d814342bf3ea8db721a15bb1Timo Sirainen MODULE_CONTEXT(obj, mail_storage_mail_index_module)
d92f33f13830ba23d814342bf3ea8db721a15bb1Timo Sirainenextern MODULE_CONTEXT_DEFINE(mail_storage_mail_index_module,
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainenvoid mail_storage_obj_ref(struct mail_storage *storage);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainenvoid mail_storage_obj_unref(struct mail_storage *storage);
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 Sirainenvoid mail_storage_set_critical(struct mail_storage *storage,
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,
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen/* Returns TRUE if everything should already be in memory after this call. */
de486b59018016977015ef42e6071155b60e82e1Timo Sirainenvoid mail_set_seq_saving(struct mail *mail, uint32_t seq);
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/* 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 Sirainenunsigned int mail_storage_get_lock_timeout(struct mail_storage *storage,
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen unsigned int secs);