mail-storage-private.h revision 4e3b79ac7787b1a867514a6ac3d1b623b72a26c6
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen/* Default prefix for indexes */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen/* Block size when read()ing message header. */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen/* Block size when read()ing message (header and) body. */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen#define MAIL_READ_FULL_BLOCK_SIZE IO_BLOCK_SIZE
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen unsigned int id;
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen unsigned int id;
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen const struct setting_parser_info *(*get_setting_parser_info)(void);
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen int (*create)(struct mail_storage *storage, struct mail_namespace *ns,
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen const char **error_r);
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen void (*destroy)(struct mail_storage *storage);
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen void (*add_list)(struct mail_storage *storage,
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen void (*get_list_settings)(const struct mail_namespace *ns,
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen bool (*autodetect)(const struct mail_namespace *ns,
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen struct mailbox *(*mailbox_alloc)(struct mail_storage *storage,
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* Called when mailbox list index corruption has been detected.
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen The callback should add any missing mailboxes to the list index.
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen Returns 0 on success, -1 on temporary failure that didn't properly
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen fix the index. */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen int (*list_index_corrupted)(struct mail_storage *storage);
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* mailboxes are files, not directories */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen MAIL_STORAGE_CLASS_FLAG_MAILBOX_IS_FILE = 0x01,
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* root_dir points to a unique directory */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* mailbox_open_stream() is supported */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* never use quota for this storage (e.g. virtual mailboxes) */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* Storage doesn't need a mail root directory */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* Storage uses one file per message */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* Messages have GUIDs (always set mailbox_status.have_guids=TRUE) */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen MAIL_STORAGE_CLASS_FLAG_HAVE_MAIL_GUIDS = 0x40,
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* mailbox_save_set_guid() works (always set
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen mailbox_status.have_save_guids=TRUE) */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen MAIL_STORAGE_CLASS_FLAG_HAVE_MAIL_SAVE_GUIDS = 0x80,
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* message content can be unstructured binary data
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen (e.g. zlib plugin is allowed to compress/decompress mails) */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* Message GUIDs can only be 128bit (always set
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen mailbox_status.have_only_guid128) */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen MAIL_STORAGE_CLASS_FLAG_HAVE_MAIL_GUID128 = 0x200,
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* Storage deletes all files internally - mailbox list's
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen delete_mailbox() shouldn't delete anything itself. */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen MAIL_STORAGE_CLASS_FLAG_NO_LIST_DELETES = 0x400,
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* Storage supports stubs (used for caching purposes). */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* Fields that the storage backend can get by other means than parsing
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen the message header/body. For example the imapc backend can lookup
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen MAIL_FETCH_IMAP_BODYSTRUCTURE from the remote server. Adding fields
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen here avoids adding them to index_mail_data.access_part. */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen/* private: */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* counting number of times mail_storage_create() has returned this
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen same storage. */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* counting number of objects (e.g. mailbox) that have a pointer
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen to this storage. */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* Linked list of all mailboxes in the storage */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* A "root dir" to enable storage sharing. It is only ever used for
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen * uniqueness checking (via strcmp) and never used as a path. */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* Last error set in mail_storage_set_critical(). */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* Filled lazily by mailbox_attribute_*() when accessing shared
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen attributes. */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* Module-specific contexts. See mail_storage_module_id. */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen ARRAY(union mail_storage_module_context *) module_contexts;
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen /* Failed to create shared attribute dict, don't try again */
0c17af9d3f9323136a94e66605776ed4462a172dTimo Sirainen const char *content_type, *content_disposition;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* convert backend UIDs to virtual UIDs. if some backend UID doesn't
16f816d3f3c32ae3351834253f52ddd0212bcbf3Timo Sirainen exist in mailbox, it's simply ignored */
8e5fedd9ada47735be8ac0f8af2a66e8528bd776Timo Sirainen /* like get_virtual_uids(), but if a backend UID doesn't exist,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen convert it to 0. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen void (*get_virtual_uid_map)(struct mailbox *box,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen void (*get_virtual_backend_boxes)(struct mailbox *box,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen int (*enable)(struct mailbox *box, enum mailbox_feature features);
b66a7b7ab0db2c9ad425912d3f21a36fcf76d876Timo Sirainen int (*exists)(struct mailbox *box, bool auto_boxes,
b66a7b7ab0db2c9ad425912d3f21a36fcf76d876Timo Sirainen const struct mailbox_update *update, bool directory);
b9b48aaaebf6f72dfab567cda073cde8a7b26598Timo Sirainen int (*rename_box)(struct mailbox *src, struct mailbox *dest);
992a9e2d6c6ee45d87089ac54267e0198a7802c3Timo Sirainen int (*get_status)(struct mailbox *box, enum mailbox_status_items items,
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainen int (*set_subscribed)(struct mailbox *box, bool set);
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainen int (*attribute_set)(struct mailbox_transaction_context *t,
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainen enum mail_attribute_type type, const char *key,
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainen enum mail_attribute_type type, const char *key,
e30b748edcef3cf3352478bf21fa8f785bdc773aTimo Sirainen const char *prefix);
44dc970b18c4e2d06f34cb908924152156e4a45bTimo Sirainen const char *(*attribute_iter_next)(struct mailbox_attribute_iter *iter);
44dc970b18c4e2d06f34cb908924152156e4a45bTimo Sirainen int (*attribute_iter_deinit)(struct mailbox_attribute_iter *iter);
1582b4d531679849bba299c17b6ec9402b7df67dTimo Sirainen /* Lookup sync extension record and figure out if it mailbox has
1582b4d531679849bba299c17b6ec9402b7df67dTimo Sirainen changed since. Returns 1 = yes, 0 = no, -1 = error. if quick==TRUE,
1582b4d531679849bba299c17b6ec9402b7df67dTimo Sirainen return 1 if it's too costly to find out exactly. */
1582b4d531679849bba299c17b6ec9402b7df67dTimo Sirainen int (*list_index_has_changed)(struct mailbox *box,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Update the sync extension record. */
9a107dedb8f35727c21b3d1d54475d33f6e2eb1fTimo Sirainen void (*list_index_update_sync)(struct mailbox *box,
44dc970b18c4e2d06f34cb908924152156e4a45bTimo Sirainen bool (*sync_next)(struct mailbox_sync_context *ctx,
6bf1543bb7af03324c04e8f9ac8e430f395989aeTimo Sirainen int (*sync_deinit)(struct mailbox_sync_context *ctx,
6bf1543bb7af03324c04e8f9ac8e430f395989aeTimo Sirainen /* Called once for each expunge. Called one or more times for
6bf1543bb7af03324c04e8f9ac8e430f395989aeTimo Sirainen flag/keyword changes. Once the sync is finished, called with
6bf1543bb7af03324c04e8f9ac8e430f395989aeTimo Sirainen uid=0 and sync_type=0. */
44dc970b18c4e2d06f34cb908924152156e4a45bTimo Sirainen void (*sync_notify)(struct mailbox *box, uint32_t uid,
ee116df08d0fdab703483e18fe8076b2ef9fd9d7Timo Sirainen const char *reason);
ee116df08d0fdab703483e18fe8076b2ef9fd9d7Timo Sirainen int (*transaction_commit)(struct mailbox_transaction_context *t,
44dc970b18c4e2d06f34cb908924152156e4a45bTimo Sirainen struct mail_transaction_commit_changes *changes_r);
44dc970b18c4e2d06f34cb908924152156e4a45bTimo Sirainen void (*transaction_rollback)(struct mailbox_transaction_context *t);
44dc970b18c4e2d06f34cb908924152156e4a45bTimo Sirainen enum mail_flags (*get_private_flags_mask)(struct mailbox *box);
44dc970b18c4e2d06f34cb908924152156e4a45bTimo Sirainen (*mail_alloc)(struct mailbox_transaction_context *t,
e30b748edcef3cf3352478bf21fa8f785bdc773aTimo Sirainen struct mailbox_header_lookup_ctx *wanted_headers);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen (*search_init)(struct mailbox_transaction_context *t,
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen struct mailbox_header_lookup_ctx *wanted_headers);
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen int (*search_deinit)(struct mail_search_context *ctx);
44dc970b18c4e2d06f34cb908924152156e4a45bTimo Sirainen bool (*search_next_nonblock)(struct mail_search_context *ctx,
e30b748edcef3cf3352478bf21fa8f785bdc773aTimo Sirainen /* Internal search function which updates ctx->seq */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen bool (*search_next_update_seq)(struct mail_search_context *ctx);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen (*save_alloc)(struct mailbox_transaction_context *t);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen int (*save_begin)(struct mail_save_context *ctx, struct istream *input);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen int (*save_continue)(struct mail_save_context *ctx);
aa62d8779ce53900c2f09bf2ff6fa790bc9f6a89Timo Sirainen int (*save_finish)(struct mail_save_context *ctx);
ea9fd7f876643e985946a2563140359064819b8eTimo Sirainen void (*save_cancel)(struct mail_save_context *ctx);
ea9fd7f876643e985946a2563140359064819b8eTimo Sirainen int (*copy)(struct mail_save_context *ctx, struct mail *mail);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Called during transaction commit/rollback if saving was done */
4b43f50117630aa12b3cfd0cbd05ae22ba27fec1Timo Sirainen int (*transaction_save_commit_pre)(struct mail_save_context *save_ctx);
6925fd9cd70c30884406d50f1d85efb6561e776cTimo Sirainen struct mail_index_transaction_commit_result *result_r);
6925fd9cd70c30884406d50f1d85efb6561e776cTimo Sirainen void (*transaction_save_rollback)(struct mail_save_context *save_ctx);
6925fd9cd70c30884406d50f1d85efb6561e776cTimo Sirainen /* mailbox's virtual name (from mail_namespace_get_vname()) */
992a9e2d6c6ee45d87089ac54267e0198a7802c3Timo Sirainen /* virtual mailboxes: */
992a9e2d6c6ee45d87089ac54267e0198a7802c3Timo Sirainen const struct virtual_mailbox_vfuncs *virtual_vfuncs;
4b43f50117630aa12b3cfd0cbd05ae22ba27fec1Timo Sirainen/* private: */
4b43f50117630aa12b3cfd0cbd05ae22ba27fec1Timo Sirainen /* Linked list of all mailboxes in this storage */
e0719fca14e337eee5a0d924bc4e9d53151a7188Timo Sirainen /* these won't be set until mailbox is opened: */
e0719fca14e337eee5a0d924bc4e9d53151a7188Timo Sirainen /* Private per-user index/view for shared mailboxes. These are synced
e0719fca14e337eee5a0d924bc4e9d53151a7188Timo Sirainen against the primary index and used to store per-user flags.
e0719fca14e337eee5a0d924bc4e9d53151a7188Timo Sirainen These are non-NULL only when mailbox has per-user flags. */
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen /* Filled lazily by mailbox_get_permissions() */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Filled lazily when mailbox is opened, use mailbox_get_path()
6925fd9cd70c30884406d50f1d85efb6561e776cTimo Sirainen to access it */
a87e5f15283e057c7dc26dd9db7b616268c95ca7Timo Sirainen /* Filled lazily when mailbox is opened, use mailbox_get_index_path()
6925fd9cd70c30884406d50f1d85efb6561e776cTimo Sirainen to access it */
6925fd9cd70c30884406d50f1d85efb6561e776cTimo Sirainen /* Reason for why mailbox is being accessed or NULL if unknown. */
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen /* default vfuncs for new struct mails. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Mailbox settings, or NULL if defaults */
8e5fedd9ada47735be8ac0f8af2a66e8528bd776Timo Sirainen /* If non-zero, fail mailbox_open() with this error. mailbox_alloc()
d22301419109ed4a38351715e6760011421dadecTimo Sirainen can set this to force open to fail. */
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen struct mail_msgpart_partial_cache partial_cache;
8e5fedd9ada47735be8ac0f8af2a66e8528bd776Timo Sirainen /* MAIL_RECENT flags handling */
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen /* Mailbox notification settings: */
43955c82f9f52c969c777b3da00bc170183dfdf2Timo Sirainen /* Increased by one for each new struct mailbox. */
8bb360f9e5de1c25e4f875205bb06e8bf15dae14Timo Sirainen /* Saved search results */
d3eff05aaa4c2bc0a7580ee87a54f6693f4a8241Timo Sirainen ARRAY(struct mail_search_result *) search_results;
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen /* Module-specific contexts. See mail_storage_module_id. */
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen ARRAY(union mailbox_module_context *) module_contexts;
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen /* When FAST open flag is used, the mailbox isn't actually opened until
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen it's synced for the first time. */
4dc8837ab37c1a606add1067e21ed868754db4e3Timo Sirainen /* Mailbox was deleted while we had it open. */
4dc8837ab37c1a606add1067e21ed868754db4e3Timo Sirainen /* Mailbox is being created */
4dc8837ab37c1a606add1067e21ed868754db4e3Timo Sirainen /* Mailbox is being deleted */
4dc8837ab37c1a606add1067e21ed868754db4e3Timo Sirainen /* Mailbox is being undeleted */
8e5fedd9ada47735be8ac0f8af2a66e8528bd776Timo Sirainen /* Don't use MAIL_INDEX_SYNC_FLAG_DELETING_INDEX for sync flag */
d22301419109ed4a38351715e6760011421dadecTimo Sirainen /* Delete mailbox only if it's empty */
32ee977e189266744ef69ac4e832fd3111d6f949Timo Sirainen /* The backend wants to skip checking if there are 0 messages before
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen calling mailbox_list.delete_mailbox() */
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen /* Mailbox was already marked as deleted within this allocation. */
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen /* TRUE if this is an INBOX for this user */
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen /* TRUE if this is an INBOX for this namespace (user or shared) */
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen /* When copying to this mailbox, require that mailbox_copy() uses
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen mailbox_save_*() to actually save a new physical copy rather than
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen simply incrementing a reference count (e.g. via hard link) */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Don't allow creating any new keywords */
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen /* Mailbox has been synced at least once */
43955c82f9f52c969c777b3da00bc170183dfdf2Timo Sirainen /* Updating cache file is disabled */
43955c82f9f52c969c777b3da00bc170183dfdf2Timo Sirainen /* Update first_saved field to mailbox list index. */
b3bb775c6b735a7f6021dea799601fbfdb656e58Timo Sirainen /* mailbox_verify_create_name() only checks for mailbox_verify_name() */
43955c82f9f52c969c777b3da00bc170183dfdf2Timo Sirainen /* Using LAYOUT=index and mailbox is being opened with a corrupted
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen mailbox name. Try to revert to the previously known good name. */
d22301419109ed4a38351715e6760011421dadecTimo Sirainen void (*set_seq)(struct mail *mail, uint32_t seq, bool saving);
4145cbac82bfc0c8bfeceeca0ef841700117930cTimo Sirainen bool (*set_uid)(struct mail *mail, uint32_t uid);
ced118ac5caf6fe83d34339c2c65c63b2aa768acTimo Sirainen void (*set_uid_cache_updates)(struct mail *mail, bool set);
41264e5dcef8335ab7ba422822b3ab518b7a327aTimo Sirainen void (*add_temp_wanted_fields)(struct mail *mail,
641f0c0900ee6e7cf9667f4b40ed95cec7d0cdcaTimo Sirainen enum mail_flags (*get_flags)(struct mail *mail);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const char *const *(*get_keywords)(struct mail *mail);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen uint64_t (*get_pvt_modseq)(struct mail *mail);
8754bb7a1f24705ffa5434f9e10d57e0b3b88d6eTimo Sirainen int (*get_date)(struct mail *mail, time_t *date_r, int *timezone_r);
8754bb7a1f24705ffa5434f9e10d57e0b3b88d6eTimo Sirainen int (*get_received_date)(struct mail *mail, time_t *date_r);
641f0c0900ee6e7cf9667f4b40ed95cec7d0cdcaTimo Sirainen int (*get_save_date)(struct mail *mail, time_t *date_r);
d67f54632110cfb6aafe2d7cd1f99b031c0b208aTimo Sirainen int (*get_virtual_size)(struct mail *mail, uoff_t *size_r);
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen int (*get_physical_size)(struct mail *mail, uoff_t *size_r);
641f0c0900ee6e7cf9667f4b40ed95cec7d0cdcaTimo Sirainen int (*get_first_header)(struct mail *mail, const char *field,
641f0c0900ee6e7cf9667f4b40ed95cec7d0cdcaTimo Sirainen int (*get_headers)(struct mail *mail, const char *field,
641f0c0900ee6e7cf9667f4b40ed95cec7d0cdcaTimo Sirainen bool decode_to_utf8, const char *const **value_r);
1d3f7c1278168d5b1cbfa9a2cc9929a0909056b4Timo Sirainen int (*get_stream)(struct mail *mail, bool get_body,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen int (*get_special)(struct mail *mail, enum mail_fetch_field field,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const char **value_r);
b60baf6af900a610b2b2ddd24a46f8311acc3386Timo Sirainen int (*get_backend_mail)(struct mail *mail, struct mail **real_mail_r);
641f0c0900ee6e7cf9667f4b40ed95cec7d0cdcaTimo Sirainen void (*update_flags)(struct mail *mail, enum modify_type modify_type,
641f0c0900ee6e7cf9667f4b40ed95cec7d0cdcaTimo Sirainen void (*update_keywords)(struct mail *mail, enum modify_type modify_type,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen void (*update_modseq)(struct mail *mail, uint64_t min_modseq);
43955c82f9f52c969c777b3da00bc170183dfdf2Timo Sirainen void (*update_pvt_modseq)(struct mail *mail, uint64_t min_pvt_modseq);
43955c82f9f52c969c777b3da00bc170183dfdf2Timo Sirainen void (*update_pop3_uidl)(struct mail *mail, const char *uidl);
d3eff05aaa4c2bc0a7580ee87a54f6693f4a8241Timo Sirainen void (*set_cache_corrupted)(struct mail *mail,
641f0c0900ee6e7cf9667f4b40ed95cec7d0cdcaTimo Sirainen const char *reason);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen int (*istream_opened)(struct mail *mail, struct istream **input);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* normally NULL, but in case this is a "backend mail" for a mail
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen created by virtual storage, this points back to the original virtual
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen mail. at least mailbox_copy() bypasses the virtual storage, so this
38df0cacce475112991e60d796f8f2105c616f01Timo Sirainen allows mail_log plugin to log the copy operation using the original
38df0cacce475112991e60d796f8f2105c616f01Timo Sirainen mailbox name. */
38df0cacce475112991e60d796f8f2105c616f01Timo Sirainen /* initial wanted fields/headers, set by mail_alloc(): */
41264e5dcef8335ab7ba422822b3ab518b7a327aTimo Sirainen struct mailbox_header_lookup_ctx *wanted_headers;
41264e5dcef8335ab7ba422822b3ab518b7a327aTimo Sirainen ARRAY(union mail_module_context *) module_contexts;
785d9cca224d33ca3938e9166784f6483e8a27d7Timo Sirainen /* number of files we've opened and read */
785d9cca224d33ca3938e9166784f6483e8a27d7Timo Sirainen /* number of bytes we've had to read from files */
785d9cca224d33ca3938e9166784f6483e8a27d7Timo Sirainen unsigned long long files_read_bytes;
785d9cca224d33ca3938e9166784f6483e8a27d7Timo Sirainen /* number of cache lookup hits */
43955c82f9f52c969c777b3da00bc170183dfdf2Timo Sirainen /* first saved mail is 0, second is 1, etc. we'll map these to UIDs
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainen using struct mail_transaction_commit_changes. */
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainen unsigned int mailnum;
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen union mail_index_transaction_module_context module_ctx;
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen struct dict_transaction_context *attr_pvt_trans, *attr_shared_trans;
3a854fc26bcccb0398f0a9a6fa72db1a4ab8f0b8Timo Sirainen /* view contains all changes done within this transaction */
3a854fc26bcccb0398f0a9a6fa72db1a4ab8f0b8Timo Sirainen /* for private index updates: */
3a854fc26bcccb0398f0a9a6fa72db1a4ab8f0b8Timo Sirainen struct mail_cache_transaction_ctx *cache_trans;
1f1ee8db68d9ae1604350801cd8dc33ebe29fe8aTimo Sirainen struct mail_transaction_commit_changes *changes;
3a854fc26bcccb0398f0a9a6fa72db1a4ab8f0b8Timo Sirainen ARRAY(union mailbox_transaction_module_context *) module_contexts;
7c449f545b10daa47027552f98d916a9805da662Timo Sirainen /* number of mails saved/copied within this transaction. */
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainen /* List of private flags added with save/copy. These are added to the
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainen private index after committing the mails to the shared index. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ARRAY(struct mail_save_private_changes) pvt_saves;
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen /* these statistics are never reset by mail-storage API: */
7c449f545b10daa47027552f98d916a9805da662Timo Sirainen /* Set to TRUE to update stats_* fields */
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen /* We've done some non-transactional (e.g. dovecot-uidlist updates) */
35283613d4c04ce18836e9fc431582c87b3710a0Timo Sirainen struct mailbox_transaction_context *transaction;
3a854fc26bcccb0398f0a9a6fa72db1a4ab8f0b8Timo Sirainen struct mail_search_sort_program *sort_program;
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers;
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen /* if non-NULL, specifies that a search resulting is being updated.
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen this can be used as a search optimization: if searched message
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen already exists in search result, it's not necessary to check if
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen static data matches. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* add matches to these search results */
7c65a07e04f28f2a881d83989f85f9ad0e87a7b4Timo Sirainen ARRAY(union mail_search_module_context *) module_contexts;
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen struct mailbox_transaction_context *transaction;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Set during mailbox_copy(). This is useful when copying is
b7b81543899e306c71e6152516d8698416162bcbTimo Sirainen implemented via save, and the save_*() methods want to access the
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen source mail. */
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainen /* data that changes for each saved mail */
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainen /* returns TRUE if message part is an attachment. */
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen bool (*part_is_attachment)(struct mail_save_context *ctx,
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainen /* mailbox_save_alloc() called, but finish/cancel not.
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen the same context is usually returned by the backends for reuse. */
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen /* mailbox_save_finish() or mailbox_copy() is being called. */
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen /* mail was copied or moved using saving (requires:
7c65a07e04f28f2a881d83989f85f9ad0e87a7b4Timo Sirainen copying_or_moving==TRUE). */
d61a5e0e4ff58d1aa613f0d51161e5bb0f092514Timo Sirainen /* mail is being saved, not copied. However, this is set also with
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen mailbox_save_using_mail() and then copying_or_moving==TRUE. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* mail is being moved - ignore quota (requires:
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen copying_or_moving==TRUE && saving==FALSE). */
7895c4845da515b0aa9bb156674a1fca40803f44Timo Sirainen /* mail is being copied or moved. However, this is set also with
7895c4845da515b0aa9bb156674a1fca40803f44Timo Sirainen mailbox_save_using_mail() and then saving==TRUE. */
7895c4845da515b0aa9bb156674a1fca40803f44Timo Sirainen unsigned int count;
7895c4845da515b0aa9bb156674a1fca40803f44Timo Sirainen const char *const *name;
7895c4845da515b0aa9bb156674a1fca40803f44Timo Sirainen unsigned int *idx;
0ed9ccd0047f75df54a49bc117ca301eb398e447Timo Sirainen/* Modules should use do "my_id = mail_storage_module_id++" and
0ed9ccd0047f75df54a49bc117ca301eb398e447Timo Sirainen use objects' module_contexts[id] for their own purposes. */
1d3f7c1278168d5b1cbfa9a2cc9929a0909056b4Timo Sirainenextern struct mail_storage_module_register mail_storage_module_register;
0ed9ccd0047f75df54a49bc117ca301eb398e447Timo Sirainen/* Storage's module_id for mail_index. */
1d3f7c1278168d5b1cbfa9a2cc9929a0909056b4Timo Sirainenextern struct mail_module_register mail_module_register;
0ed9ccd0047f75df54a49bc117ca301eb398e447Timo Sirainen MODULE_CONTEXT(obj, mail_storage_mail_index_module)
0ed9ccd0047f75df54a49bc117ca301eb398e447Timo Sirainenextern MODULE_CONTEXT_DEFINE(mail_storage_mail_index_module,
0ed9ccd0047f75df54a49bc117ca301eb398e447Timo Sirainenvoid mail_storage_obj_ref(struct mail_storage *storage);
0ed9ccd0047f75df54a49bc117ca301eb398e447Timo Sirainenvoid mail_storage_obj_unref(struct mail_storage *storage);
1d3f7c1278168d5b1cbfa9a2cc9929a0909056b4Timo Sirainen/* Set error message in storage. Critical errors are logged with i_error(),
1d3f7c1278168d5b1cbfa9a2cc9929a0909056b4Timo Sirainen but user sees only "internal error" message. */
c2cb5e469cd11759da22d82083d4fbb564d06dfaTimo Sirainenvoid mail_storage_clear_error(struct mail_storage *storage);
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainenvoid mail_storage_set_error(struct mail_storage *storage,
c2cb5e469cd11759da22d82083d4fbb564d06dfaTimo Sirainenvoid mail_storage_set_critical(struct mail_storage *storage,
35283613d4c04ce18836e9fc431582c87b3710a0Timo Sirainenvoid mail_storage_set_internal_error(struct mail_storage *storage);
ced118ac5caf6fe83d34339c2c65c63b2aa768acTimo Sirainenvoid mailbox_set_index_error(struct mailbox *box);
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainenvoid mail_storage_set_index_error(struct mail_storage *storage,
c2cb5e469cd11759da22d82083d4fbb564d06dfaTimo Sirainenbool mail_storage_set_error_from_errno(struct mail_storage *storage);
0ed9ccd0047f75df54a49bc117ca301eb398e447Timo Sirainenvoid mail_storage_copy_list_error(struct mail_storage *storage,
4145cbac82bfc0c8bfeceeca0ef841700117930cTimo Sirainenvoid mail_storage_copy_error(struct mail_storage *dest,
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainen/* set record in mail cache corrupted */
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainenvoid mail_set_mail_cache_corrupted(struct mail *mail, const char *fmt, ...)
0ed9ccd0047f75df54a49bc117ca301eb398e447Timo Sirainen/* Indicate mail being expunged by autoexpunge */
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainen/* Returns TRUE if everything should already be in memory after this call
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainen or if prefetching is not supported, i.e. the caller shouldn't do more
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainen prefetching before this message is handled. */
7d7f4648f72b8c70928e04514b0d93dad0ba6fd5Timo Sirainenvoid mail_set_seq_saving(struct mail *mail, uint32_t seq);
7d7f4648f72b8c70928e04514b0d93dad0ba6fd5Timo Sirainenint mailbox_mark_index_deleted(struct mailbox *box, bool del);
4145cbac82bfc0c8bfeceeca0ef841700117930cTimo Sirainen/* Easy wrapper for getting mailbox's MAILBOX_LIST_PATH_TYPE_MAILBOX.
c2cb5e469cd11759da22d82083d4fbb564d06dfaTimo Sirainen The mailbox must already be opened and the caller must know that the
c2cb5e469cd11759da22d82083d4fbb564d06dfaTimo Sirainen storage has mailbox files (i.e. NULL/empty path is never returned). */
3a854fc26bcccb0398f0a9a6fa72db1a4ab8f0b8Timo Sirainenconst char *mailbox_get_path(struct mailbox *box) ATTR_PURE;
3a854fc26bcccb0398f0a9a6fa72db1a4ab8f0b8Timo Sirainen/* Similar to mailbox_get_path() but for MAILBOX_LIST_PATH_TYPE_INDEX. */
3a854fc26bcccb0398f0a9a6fa72db1a4ab8f0b8Timo Sirainenconst char *mailbox_get_index_path(struct mailbox *box) ATTR_PURE;
b66d803de86bfb411165b3465b0d9ef64ecfe2a1Timo Sirainen/* Wrapper to mailbox_list_get_path() */
3a854fc26bcccb0398f0a9a6fa72db1a4ab8f0b8Timo Sirainenint mailbox_get_path_to(struct mailbox *box, enum mailbox_list_path_type type,
d22301419109ed4a38351715e6760011421dadecTimo Sirainen const char **path_r);
c2cb5e469cd11759da22d82083d4fbb564d06dfaTimo Sirainen/* Get mailbox permissions. */
c2cb5e469cd11759da22d82083d4fbb564d06dfaTimo Sirainenconst struct mailbox_permissions *mailbox_get_permissions(struct mailbox *box);
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen/* Force permissions to be refreshed on next lookup */
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainenvoid mailbox_refresh_permissions(struct mailbox *box);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Open private index files for mailbox. Returns 1 if opened, 0 if there
649823f9c7e42a424a8fadc427e12f3576c4f714Timo Sirainen are no private indexes (or flags) in this mailbox, -1 if error. */
f7ad1162969feff6b08f0e640a928db1783daae9Timo Sirainenint mailbox_open_index_pvt(struct mailbox *box);
ba3d9eeb0bec6ed8465d68fa2480ad085559b580Timo Sirainen/* Create path's directory with proper permissions. The root directory is also
7ede6554e451ec039a67beec7d6ee4aff61d386eTimo Sirainen created if necessary. Returns 1 if created, 0 if it already existed,
35283613d4c04ce18836e9fc431582c87b3710a0Timo Sirainen -1 if error. */
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainenint mailbox_mkdir(struct mailbox *box, const char *path,
c2cb5e469cd11759da22d82083d4fbb564d06dfaTimo Sirainen/* Create a non-mailbox type directory for mailbox if it's missing (e.g. index).
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen Optimized for case where the directory usually exists. */
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainenint mailbox_create_missing_dir(struct mailbox *box,
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainen/* Returns TRUE if mailbox is autocreated. */
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainenbool mailbox_is_autocreated(struct mailbox *box);
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainen/* Returns TRUE if mailbox is autosubscribed. */
ae9365d3de0cefae6f2a5d3e9ab79bc11c37b3d5Timo Sirainenbool mailbox_is_autosubscribed(struct mailbox *box);
c2cb5e469cd11759da22d82083d4fbb564d06dfaTimo Sirainen/* Returns -1 if error, 0 if failed with EEXIST, 1 if ok */
a38ef15060e45e5060bb24c403a580b9a57a818cTimo Sirainenint mailbox_create_fd(struct mailbox *box, const char *path, int flags,
d4dcb9c30dba354cff7af6d303ecef7698194c55Timo Sirainen/* Create a lock file to the mailbox with the given filename. If it succeeds,
d4dcb9c30dba354cff7af6d303ecef7698194c55Timo Sirainen returns 1 and lock_r, which needs to be freed once finished with the lock.
d4dcb9c30dba354cff7af6d303ecef7698194c55Timo Sirainen If lock_secs is reached, returns 0 and error_r. Returns -1 and sets error_r
d4dcb9c30dba354cff7af6d303ecef7698194c55Timo Sirainen on other errors. */
d4dcb9c30dba354cff7af6d303ecef7698194c55Timo Sirainenint mailbox_lock_file_create(struct mailbox *box, const char *lock_fname,
d4dcb9c30dba354cff7af6d303ecef7698194c55Timo Sirainen unsigned int lock_secs, struct file_lock **lock_r,
d4dcb9c30dba354cff7af6d303ecef7698194c55Timo Sirainen const char **error_r);
e05181d973025627ba08b631c12c07c3bbc99528Timo Sirainenunsigned int mail_storage_get_lock_timeout(struct mail_storage *storage,
d4dcb9c30dba354cff7af6d303ecef7698194c55Timo Sirainen unsigned int secs);
d4dcb9c30dba354cff7af6d303ecef7698194c55Timo Sirainenvoid mail_storage_free_binary_cache(struct mail_storage *storage);
d4dcb9c30dba354cff7af6d303ecef7698194c55Timo Sirainenmail_storage_settings_to_index_flags(const struct mail_storage_settings *set);