8c909e451d14075c05d90382cf8eebc4e354f569Timo Sirainen/* Default prefix for indexes */
573f0491a5733fe21fa062a455acb4790b4e0499Timo Sirainen/* Block size when read()ing message header. */
573f0491a5733fe21fa062a455acb4790b4e0499Timo Sirainen/* Block size when read()ing message (header and) body. */
3ed2d0f6b5e67e2663d44489d9da3176823789a8Timo Sirainen#define MAIL_READ_FULL_BLOCK_SIZE IO_BLOCK_SIZE
82d1fe3d5d04fb11e3e89cce03dc4de191e58f75Timo Sirainen /* Mailbox list index was found to be corrupted. */
82d1fe3d5d04fb11e3e89cce03dc4de191e58f75Timo Sirainen MAIL_STORAGE_LIST_INDEX_REBUILD_REASON_CORRUPTED,
8049d5792631981b50b0ad226a03298445e305c7Timo Sirainen /* Mailbox list index doesn't have INBOX in an inbox=yes namespace.
8049d5792631981b50b0ad226a03298445e305c7Timo Sirainen Rebuild is done to verify whether the user really is an empty new
8049d5792631981b50b0ad226a03298445e305c7Timo Sirainen user, or if an existing user's mailbox list index was lost. Because
8049d5792631981b50b0ad226a03298445e305c7Timo Sirainen this is called in non-error conditions, the callback shouldn't log
8049d5792631981b50b0ad226a03298445e305c7Timo Sirainen any errors or warnings if it didn't find any missing mailboxes. */
8049d5792631981b50b0ad226a03298445e305c7Timo Sirainen MAIL_STORAGE_LIST_INDEX_REBUILD_REASON_NO_INBOX,
b42817ce16a8660cbcc4adfc8bccc3db1c6d00c7Timo Sirainen /* MAILBOX_SYNC_FLAG_FORCE_RESYNC is run. This is called only once
b42817ce16a8660cbcc4adfc8bccc3db1c6d00c7Timo Sirainen per list, so that doveadm force-resync '*' won't cause it to run for
b42817ce16a8660cbcc4adfc8bccc3db1c6d00c7Timo Sirainen every mailbox. */
b42817ce16a8660cbcc4adfc8bccc3db1c6d00c7Timo Sirainen MAIL_STORAGE_LIST_INDEX_REBUILD_REASON_FORCE_RESYNC,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen const struct setting_parser_info *(*get_setting_parser_info)(void);
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen int (*create)(struct mail_storage *storage, struct mail_namespace *ns,
2dd39e478269d6fb0bb26d12b394aa30ee965e38Timo Sirainen const char **error_r);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen void (*destroy)(struct mail_storage *storage);
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen void (*add_list)(struct mail_storage *storage,
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen void (*get_list_settings)(const struct mail_namespace *ns,
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen bool (*autodetect)(const struct mail_namespace *ns,
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen struct mailbox *(*mailbox_alloc)(struct mail_storage *storage,
82d1fe3d5d04fb11e3e89cce03dc4de191e58f75Timo Sirainen /* Called when mailbox list index rebuild is requested.
857c471c13ca215f4be9dd4b336b742b8d434e31Timo Sirainen The callback should add any missing mailboxes to the list index.
857c471c13ca215f4be9dd4b336b742b8d434e31Timo Sirainen Returns 0 on success, -1 on temporary failure that didn't properly
82d1fe3d5d04fb11e3e89cce03dc4de191e58f75Timo Sirainen rebuild the index. */
82d1fe3d5d04fb11e3e89cce03dc4de191e58f75Timo Sirainen int (*list_index_rebuild)(struct mail_storage *storage,
82d1fe3d5d04fb11e3e89cce03dc4de191e58f75Timo Sirainen enum mail_storage_list_index_rebuild_reason reason);
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen /* mailboxes are files, not directories */
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen MAIL_STORAGE_CLASS_FLAG_MAILBOX_IS_FILE = 0x01,
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen /* root_dir points to a unique directory */
e5fd6dfd0a492e4708d4dbb7971d7fc5d7b8fd85Timo Sirainen /* mailbox_open_stream() is supported */
4ba9a1d3facc515b3feb5238a16bcf91f76fac61Timo Sirainen /* never use quota for this storage (e.g. virtual mailboxes) */
dfaefeabae939803ceb8c503101e86b5496541d1Timo Sirainen /* Storage doesn't need a mail root directory */
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen /* Storage uses one file per message */
8b31f966d9688e07672ef1958dcbdb7686523c04Timo Sirainen /* Messages have GUIDs (always set mailbox_status.have_guids=TRUE) */
9847ec56efa15fa063eea9988eee2d4ed9ec7d58Timo Sirainen MAIL_STORAGE_CLASS_FLAG_HAVE_MAIL_GUIDS = 0x40,
9847ec56efa15fa063eea9988eee2d4ed9ec7d58Timo Sirainen /* mailbox_save_set_guid() works (always set
9847ec56efa15fa063eea9988eee2d4ed9ec7d58Timo Sirainen mailbox_status.have_save_guids=TRUE) */
d46a1e3f999dda802dc5137e883adcd7a6629cd3Timo Sirainen MAIL_STORAGE_CLASS_FLAG_HAVE_MAIL_SAVE_GUIDS = 0x80,
d46a1e3f999dda802dc5137e883adcd7a6629cd3Timo Sirainen /* message content can be unstructured binary data
d46a1e3f999dda802dc5137e883adcd7a6629cd3Timo Sirainen (e.g. zlib plugin is allowed to compress/decompress mails) */
d1e843e77f4760e303c53d9fce10123fc8d230a1Timo Sirainen /* Message GUIDs can only be 128bit (always set
d1e843e77f4760e303c53d9fce10123fc8d230a1Timo Sirainen mailbox_status.have_only_guid128) */
291ce16fffca75e8598a8c9dceb08613413dcb07Timo Sirainen MAIL_STORAGE_CLASS_FLAG_HAVE_MAIL_GUID128 = 0x200,
291ce16fffca75e8598a8c9dceb08613413dcb07Timo Sirainen /* Storage deletes all files internally - mailbox list's
291ce16fffca75e8598a8c9dceb08613413dcb07Timo Sirainen delete_mailbox() shouldn't delete anything itself. */
08e9fd42eb8007e1f9db62c088eef74f906114a5Josef 'Jeff' Sipek MAIL_STORAGE_CLASS_FLAG_NO_LIST_DELETES = 0x400,
08e9fd42eb8007e1f9db62c088eef74f906114a5Josef 'Jeff' Sipek /* Storage supports stubs (used for caching purposes). */
afe1da042382720393eca6497253106e4eec75e0Timo Sirainen /* Fields that the storage backend can get by other means than parsing
afe1da042382720393eca6497253106e4eec75e0Timo Sirainen the message header/body. For example the imapc backend can lookup
afe1da042382720393eca6497253106e4eec75e0Timo Sirainen MAIL_FETCH_IMAP_BODYSTRUCTURE from the remote server. Adding fields
afe1da042382720393eca6497253106e4eec75e0Timo Sirainen here avoids adding them to index_mail_data.access_part. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* private: */
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainen /* counting number of times mail_storage_create() has returned this
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainen same storage. */
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainen /* counting number of objects (e.g. mailbox) that have a pointer
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainen to this storage. */
eecb235c14b49c01774134ea593c266f2d2c2be1Timo Sirainen /* Linked list of all mailboxes in the storage */
7900eb30bac4a46b259522c58362884661483d7cJosef 'Jeff' Sipek /* A "root dir" to enable storage sharing. It is only ever used for
7900eb30bac4a46b259522c58362884661483d7cJosef 'Jeff' Sipek * uniqueness checking (via strcmp) and never used as a path. */
98c217499d578495e982ea6010ebff831e9669aeMartti Rannanjärvi /* Last error set in mail_storage_set_critical(). */
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen /* Filled lazily by mailbox_attribute_*() when accessing shared
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen attributes. */
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen /* Module-specific contexts. See mail_storage_module_id. */
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(union mail_storage_module_context *) module_contexts;
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen /* Failed to create shared attribute dict, don't try again */
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen const char *content_type, *content_disposition;
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen /* convert backend UIDs to virtual UIDs. if some backend UID doesn't
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen exist in mailbox, it's simply ignored */
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen /* like get_virtual_uids(), but if a backend UID doesn't exist,
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen convert it to 0. */
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen void (*get_virtual_uid_map)(struct mailbox *box,
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen void (*get_virtual_backend_boxes)(struct mailbox *box,
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen int (*enable)(struct mailbox *box, enum mailbox_feature features);
cff1f182205e674285cf3ff446a0dcf7afea277dTimo Sirainen int (*exists)(struct mailbox *box, bool auto_boxes,
f318b3dbe2acc177b8ee1c160e4b5b14e7f2cd41Timo Sirainen const struct mailbox_update *update, bool directory);
f318b3dbe2acc177b8ee1c160e4b5b14e7f2cd41Timo Sirainen int (*rename_box)(struct mailbox *src, struct mailbox *dest);
d3280fe317a4598c0868cc440e7a1191c06d0db3Timo Sirainen int (*get_status)(struct mailbox *box, enum mailbox_status_items items,
6469cf211a57433335641725dc236ebb2b9fdd3bTimo Sirainen int (*set_subscribed)(struct mailbox *box, bool set);
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen int (*attribute_set)(struct mailbox_transaction_context *t,
6cc4cce2078aca138fbce19305e69e77edcee614Timo Sirainen enum mail_attribute_type type, const char *key,
bd6a8056771b6150685dea319ab5a94e021d17f1Josef 'Jeff' Sipek const struct mail_attribute_value *value);
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen enum mail_attribute_type type, const char *key,
62041dfb7d6ac6e9c633a557075999cdfcff7bd5Timo Sirainen const char *prefix);
62041dfb7d6ac6e9c633a557075999cdfcff7bd5Timo Sirainen const char *(*attribute_iter_next)(struct mailbox_attribute_iter *iter);
62041dfb7d6ac6e9c633a557075999cdfcff7bd5Timo Sirainen int (*attribute_iter_deinit)(struct mailbox_attribute_iter *iter);
d3442384ca53d4b18a493db7dd0b000f470419cfTimo Sirainen /* Lookup sync extension record and figure out if it mailbox has
aa47c9bd1d1fc70cd699c49fd1ca92dbc7615953Timo Sirainen changed since. Returns 1 = yes, 0 = no, -1 = error. if quick==TRUE,
aa47c9bd1d1fc70cd699c49fd1ca92dbc7615953Timo Sirainen return 1 if it's too costly to find out exactly. */
d3442384ca53d4b18a493db7dd0b000f470419cfTimo Sirainen int (*list_index_has_changed)(struct mailbox *box,
c0d069950af1dbc6a4e5c3de3bf2e437796e3ae0Timo Sirainen /* Update the sync extension record. */
c0d069950af1dbc6a4e5c3de3bf2e437796e3ae0Timo Sirainen void (*list_index_update_sync)(struct mailbox *box,
c979eeda1f46483d9c963e265786b701d7683d77Timo Sirainen bool (*sync_next)(struct mailbox_sync_context *ctx,
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen int (*sync_deinit)(struct mailbox_sync_context *ctx,
4b41116563110d00330896a568eff1078c382827Timo Sirainen /* Called once for each expunge. Called one or more times for
4b41116563110d00330896a568eff1078c382827Timo Sirainen flag/keyword changes. Once the sync is finished, called with
4b41116563110d00330896a568eff1078c382827Timo Sirainen uid=0 and sync_type=0. */
5137d2d80255938a0f5fb8f3c1a21b34cf11ada3Timo Sirainen void (*sync_notify)(struct mailbox *box, uint32_t uid,
b2c1349cf07410aefab0f5b17153af9e5cfcf48fTimo Sirainen int (*transaction_commit)(struct mailbox_transaction_context *t,
96308127e006bb3b1108093bcf4cc1fd9481cb7aTimo Sirainen struct mail_transaction_commit_changes *changes_r);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen void (*transaction_rollback)(struct mailbox_transaction_context *t);
8a13b020f90e080570658b18c042e7e352c8b14fTimo Sirainen enum mail_flags (*get_private_flags_mask)(struct mailbox *box);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen (*mail_alloc)(struct mailbox_transaction_context *t,
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen (*search_init)(struct mailbox_transaction_context *t,
eef4ba0cc3e78f8c26804c1c9251a76580a41f0cTimo Sirainen struct mailbox_header_lookup_ctx *wanted_headers);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen int (*search_deinit)(struct mail_search_context *ctx);
f3bb2fbe87425dc89a839908985af496f7f65702Timo Sirainen bool (*search_next_nonblock)(struct mail_search_context *ctx,
a3ee5ce6ecc8e228ee69300fdd562d7ac8be89a7Timo Sirainen /* Internal search function which updates ctx->seq */
bd1b2615928a1e8be190cb0405754f0aec8cac2fTimo Sirainen bool (*search_next_update_seq)(struct mail_search_context *ctx);
e3aeeb634245e80d4f643f8d2eea11d6b72336d8Timo Sirainen (*save_alloc)(struct mailbox_transaction_context *t);
e3aeeb634245e80d4f643f8d2eea11d6b72336d8Timo Sirainen int (*save_begin)(struct mail_save_context *ctx, struct istream *input);
a423d985ba7261661475811c22b21b80ec765a71Timo Sirainen int (*save_continue)(struct mail_save_context *ctx);
2ebeb22b9a8a8bb7fbe2f2e2908478a220792b87Timo Sirainen int (*save_finish)(struct mail_save_context *ctx);
a423d985ba7261661475811c22b21b80ec765a71Timo Sirainen void (*save_cancel)(struct mail_save_context *ctx);
bd4d0a1a7c0626452b8d82f37e3ec07267ac9896Timo Sirainen int (*copy)(struct mail_save_context *ctx, struct mail *mail);
1460ef7a18c53216ddb4a94bb62fba96076aae8eTimo Sirainen /* Called during transaction commit/rollback if saving was done */
1460ef7a18c53216ddb4a94bb62fba96076aae8eTimo Sirainen int (*transaction_save_commit_pre)(struct mail_save_context *save_ctx);
1460ef7a18c53216ddb4a94bb62fba96076aae8eTimo Sirainen struct mail_index_transaction_commit_result *result_r);
1460ef7a18c53216ddb4a94bb62fba96076aae8eTimo Sirainen void (*transaction_save_rollback)(struct mail_save_context *save_ctx);
df00412606a00714a6e85383fa87fbdc7cc1fb5bTimo Sirainen /* mailbox's virtual name (from mail_namespace_get_vname()) */
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen /* virtual mailboxes: */
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen const struct virtual_mailbox_vfuncs *virtual_vfuncs;
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen/* private: */
eecb235c14b49c01774134ea593c266f2d2c2be1Timo Sirainen /* Linked list of all mailboxes in this storage */
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen /* these won't be set until mailbox is opened: */
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen /* Private per-user index/view for shared mailboxes. These are synced
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen against the primary index and used to store per-user flags.
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen These are non-NULL only when mailbox has per-user flags. */
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen /* Filled lazily by mailbox_get_permissions() */
9fc97c8aa8190df87624d214bcc5d0b5362bec93Timo Sirainen /* Filled lazily when mailbox is opened, use mailbox_get_path()
9fc97c8aa8190df87624d214bcc5d0b5362bec93Timo Sirainen to access it */
546335814920fb6b5b44c68c7803e654eefeae9dTimo Sirainen /* Filled lazily when mailbox is opened, use mailbox_get_index_path()
546335814920fb6b5b44c68c7803e654eefeae9dTimo Sirainen to access it */
4b41218f9e09386ad5d8f279355aad1dfb64392dTimo Sirainen /* Reason for why mailbox is being accessed or NULL if unknown. */
ca98d6a1bbe73499da758a36bfab2963375c8d06Timo Sirainen /* default vfuncs for new struct mails. */
eb1572d7c44ebc7b0b039d085c3dbab2ef7043ddTimo Sirainen /* Mailbox settings, or NULL if defaults */
bd4e36a8cd7257cca7d1434c49a1e343ed7c5100Timo Sirainen /* If non-zero, fail mailbox_open() with this error. mailbox_alloc()
bd4e36a8cd7257cca7d1434c49a1e343ed7c5100Timo Sirainen can set this to force open to fail. */
0177594fa5217b02001f4ec8752154fd2b05c545Timo Sirainen struct mail_msgpart_partial_cache partial_cache;
817d027593510c3ba70ad542ce0011f5f6916d1eTimo Sirainen /* MAIL_RECENT flags handling */
f81f4bc282cd1944cec187bae89c0701a416ed2aTimo Sirainen /* Mailbox notification settings: */
fcfe85637e1ee14a9fc39c41fd6ceca106301542Timo Sirainen /* Increased by one for each new struct mailbox. */
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen /* Saved search results */
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(struct mail_search_result *) search_results;
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen /* Module-specific contexts. See mail_storage_module_id. */
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(union mailbox_module_context *) module_contexts;
5fb3bff645380804c9db2510940c41db6b8fdb01Timo Sirainen /* When FAST open flag is used, the mailbox isn't actually opened until
5fb3bff645380804c9db2510940c41db6b8fdb01Timo Sirainen it's synced for the first time. */
4bbd396aa6198c84f3f7763b6e8a63a26e97e141Timo Sirainen /* Mailbox was deleted while we had it open. */
7baab0b0b60df7ce9093d0881cd322dff1e79491Timo Sirainen /* Mailbox is being created */
3f91e60401495a4046c73992fabaa5e77200a451Timo Sirainen /* Mailbox is being deleted */
3857e2945a3b6744d603f0f5a656849ed8436ba3Timo Sirainen /* Mailbox is being undeleted */
f90cbe597c41d5cc91debd371f8648bd8e6ffbc2Timo Sirainen /* Don't use MAIL_INDEX_SYNC_FLAG_DELETING_INDEX for sync flag */
33b469d1ca66dd2cc496d2d990b8b98e72952a29Timo Sirainen /* Delete mailbox only if it's empty */
58ba0fe5a6904d3a65cfe268411f4cbb881234eeTimo Sirainen /* The backend wants to skip checking if there are 0 messages before
58ba0fe5a6904d3a65cfe268411f4cbb881234eeTimo Sirainen calling mailbox_list.delete_mailbox() */
6b0d8106ae51ffc6ce45636b34d2e21cbefca7fdTimo Sirainen /* Mailbox was already marked as deleted within this allocation. */
eb64c3586d854cddd693f0b811d897399076a441Timo Sirainen /* TRUE if this is an INBOX for this user */
eb64c3586d854cddd693f0b811d897399076a441Timo Sirainen /* TRUE if this is an INBOX for this namespace (user or shared) */
7f735cb86b2d8abd8f230089065eacfc24e9e5d6Timo Sirainen /* When copying to this mailbox, require that mailbox_copy() uses
7f735cb86b2d8abd8f230089065eacfc24e9e5d6Timo Sirainen mailbox_save_*() to actually save a new physical copy rather than
7f735cb86b2d8abd8f230089065eacfc24e9e5d6Timo Sirainen simply incrementing a reference count (e.g. via hard link) */
b3484b5b1f47e4cf112f0e371478a2d7794b31bbTimo Sirainen /* Don't allow creating any new keywords */
d81131d3bbb4f0befb62a661d1785cf8c84a17e2Timo Sirainen /* Mailbox has been synced at least once */
9456a4a3e74929f9d3d5b00b93be6d8eb69bc52aTimo Sirainen /* Updating cache file is disabled */
4e3bcf7fdaeef92dd07a2acb1ded58422a907e87Timo Sirainen /* Update first_saved field to mailbox list index. */
19e161dd9e2c3a2ffc96ee8852bec0720cb30d1cTimo Sirainen /* mailbox_verify_create_name() only checks for mailbox_verify_name() */
540555c5b435203e1c26c8e7b924b2643ae07ae3Timo Sirainen /* Using LAYOUT=index and mailbox is being opened with a corrupted
540555c5b435203e1c26c8e7b924b2643ae07ae3Timo Sirainen mailbox name. Try to revert to the previously known good name. */
7631f16156aca373004953fe6b01a7f343fb47e0Timo Sirainen void (*set_seq)(struct mail *mail, uint32_t seq, bool saving);
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen bool (*set_uid)(struct mail *mail, uint32_t uid);
aa247243412a49f9bdebf7255e131dc6ece4ed46Timo Sirainen void (*set_uid_cache_updates)(struct mail *mail, bool set);
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainen void (*add_temp_wanted_fields)(struct mail *mail,
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen enum mail_flags (*get_flags)(struct mail *mail);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen const char *const *(*get_keywords)(struct mail *mail);
f46885a5b78b15a8d2419f6e5d13b643bd85e41fTimo Sirainen uint64_t (*get_pvt_modseq)(struct mail *mail);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen int (*get_date)(struct mail *mail, time_t *date_r, int *timezone_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen int (*get_received_date)(struct mail *mail, time_t *date_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen int (*get_save_date)(struct mail *mail, time_t *date_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen int (*get_virtual_size)(struct mail *mail, uoff_t *size_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen int (*get_physical_size)(struct mail *mail, uoff_t *size_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen int (*get_first_header)(struct mail *mail, const char *field,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen int (*get_headers)(struct mail *mail, const char *field,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen bool decode_to_utf8, const char *const **value_r);
6df0ab0c1ab91f06b6418cb30eff44405a1b8f02Timo Sirainen int (*get_stream)(struct mail *mail, bool get_body,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen int (*get_special)(struct mail *mail, enum mail_fetch_field field,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen const char **value_r);
21aaa6affb9f134112b75b5db737309fc35ef1cfMartti Rannanjärvi int (*get_backend_mail)(struct mail *mail, struct mail **real_mail_r);
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen void (*update_flags)(struct mail *mail, enum modify_type modify_type,
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen void (*update_keywords)(struct mail *mail, enum modify_type modify_type,
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen void (*update_modseq)(struct mail *mail, uint64_t min_modseq);
f46885a5b78b15a8d2419f6e5d13b643bd85e41fTimo Sirainen void (*update_pvt_modseq)(struct mail *mail, uint64_t min_pvt_modseq);
225e82df5dd1e765f4e52b80c954558f00e5a7dfTimo Sirainen void (*update_pop3_uidl)(struct mail *mail, const char *uidl);
838e367716bbd5e44b4a1691db9cbf72af53e9f0Timo Sirainen void (*set_cache_corrupted)(struct mail *mail,
6564208826b0f46a00f010d1b5711d85944c3c88Timo Sirainen int (*istream_opened)(struct mail *mail, struct istream **input);
13e130c3af3032982de6b1d13c6dcddda9164848Timo Sirainen /* normally NULL, but in case this is a "backend mail" for a mail
13e130c3af3032982de6b1d13c6dcddda9164848Timo Sirainen created by virtual storage, this points back to the original virtual
13e130c3af3032982de6b1d13c6dcddda9164848Timo Sirainen mail. at least mailbox_copy() bypasses the virtual storage, so this
13e130c3af3032982de6b1d13c6dcddda9164848Timo Sirainen allows mail_log plugin to log the copy operation using the original
13e130c3af3032982de6b1d13c6dcddda9164848Timo Sirainen mailbox name. */
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainen /* initial wanted fields/headers, set by mail_alloc(): */
310767ca33e7636d40ec45dee68a2c319a5fa3c0Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers;
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(union mail_module_context *) module_contexts;
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen /* number of files we've opened and read */
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen /* number of bytes we've had to read from files */
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen /* number of cache lookup hits */
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen /* first saved mail is 0, second is 1, etc. we'll map these to UIDs
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen using struct mail_transaction_commit_changes. */
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen union mail_index_transaction_module_context module_ctx;
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen struct dict_transaction_context *attr_pvt_trans, *attr_shared_trans;
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen /* view contains all changes done within this transaction */
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen /* for private index updates: */
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen struct mail_cache_transaction_ctx *cache_trans;
96308127e006bb3b1108093bcf4cc1fd9481cb7aTimo Sirainen struct mail_transaction_commit_changes *changes;
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(union mailbox_transaction_module_context *) module_contexts;
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen /* number of mails saved/copied within this transaction. */
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen /* List of private flags added with save/copy. These are added to the
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen private index after committing the mails to the shared index. */
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen ARRAY(struct mail_save_private_changes) pvt_saves;
1eaaa2c9003cf3fbf672d597473e3f84e70d2ee6Timo Sirainen /* these statistics are never reset by mail-storage API: */
1eaaa2c9003cf3fbf672d597473e3f84e70d2ee6Timo Sirainen /* Set to TRUE to update stats_* fields */
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen struct mailbox_transaction_context *transaction;
e63bdfedcf61e1a9ee21990140cbd0d0638da7e1Timo Sirainen struct mail_search_sort_program *sort_program;
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers;
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen /* if non-NULL, specifies that a search resulting is being updated.
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen this can be used as a search optimization: if searched message
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen already exists in search result, it's not necessary to check if
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen static data matches. */
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen /* add matches to these search results */
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(union mail_search_module_context *) module_contexts;
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen struct mailbox_transaction_context *transaction;
d0d37a769d7e54646de025a43d2cb888478cb218Timo Sirainen /* Set during mailbox_copy(). This is useful when copying is
d0d37a769d7e54646de025a43d2cb888478cb218Timo Sirainen implemented via save, and the save_*() methods want to access the
d0d37a769d7e54646de025a43d2cb888478cb218Timo Sirainen source mail. */
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen /* data that changes for each saved mail */
b62140c5849297a800fee942026d9c3cb8c60206Timo Sirainen /* returns TRUE if message part is an attachment. */
b62140c5849297a800fee942026d9c3cb8c60206Timo Sirainen bool (*part_is_attachment)(struct mail_save_context *ctx,
b09eaeb9a81e5b58c6e605eb762573a2b4a69e0eTimo Sirainen /* mailbox_save_alloc() called, but finish/cancel not.
b09eaeb9a81e5b58c6e605eb762573a2b4a69e0eTimo Sirainen the same context is usually returned by the backends for reuse. */
ba8ff75a149d6936f769a2d1dfceaab9da87863bTimo Sirainen /* mailbox_save_finish() or mailbox_copy() is being called. */
05150df8fbda6b8fdfafcfb0aa9003f1da4ecacaTimo Sirainen /* mail was copied or moved using saving (requires:
05150df8fbda6b8fdfafcfb0aa9003f1da4ecacaTimo Sirainen copying_or_moving==TRUE). */
05150df8fbda6b8fdfafcfb0aa9003f1da4ecacaTimo Sirainen /* mail is being saved, not copied. However, this is set also with
05150df8fbda6b8fdfafcfb0aa9003f1da4ecacaTimo Sirainen mailbox_save_using_mail() and then copying_or_moving==TRUE. */
05150df8fbda6b8fdfafcfb0aa9003f1da4ecacaTimo Sirainen /* mail is being moved - ignore quota (requires:
05150df8fbda6b8fdfafcfb0aa9003f1da4ecacaTimo Sirainen copying_or_moving==TRUE && saving==FALSE). */
05150df8fbda6b8fdfafcfb0aa9003f1da4ecacaTimo Sirainen /* mail is being copied or moved. However, this is set also with
05150df8fbda6b8fdfafcfb0aa9003f1da4ecacaTimo Sirainen mailbox_save_using_mail() and then saving==TRUE. */
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen/* Modules should use do "my_id = mail_storage_module_id++" and
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen use objects' module_contexts[id] for their own purposes. */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenextern struct mail_storage_module_register mail_storage_module_register;
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen/* Storage's module_id for mail_index. */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenextern struct mail_module_register mail_module_register;
677cc0d62b41c7506246bf1b992a400a11896474Timo Sirainenextern struct event_category event_category_storage;
b644a77b00ce21c67a7becda974a12dfe3a946e4Timo Sirainenextern struct event_category event_category_mailbox;
c499c40caf37f766968a551909190c5b009a9b15Timo Sirainenextern struct event_category event_category_mail;
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen MODULE_CONTEXT(obj, mail_storage_mail_index_module)
c51390c3ae6e373e7b4a052a94e8e4065b98321cAki Tuomi MODULE_CONTEXT_REQUIRE(obj, mail_storage_mail_index_module)
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenextern MODULE_CONTEXT_DEFINE(mail_storage_mail_index_module,
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainenvoid mail_storage_obj_ref(struct mail_storage *storage);
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainenvoid mail_storage_obj_unref(struct mail_storage *storage);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Set error message in storage. Critical errors are logged with i_error(),
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen but user sees only "internal error" message. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_storage_clear_error(struct mail_storage *storage);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_storage_set_error(struct mail_storage *storage,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_storage_set_critical(struct mail_storage *storage,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_storage_set_internal_error(struct mail_storage *storage);
1f1ee8db68d9ae1604350801cd8dc33ebe29fe8aTimo Sirainenvoid mailbox_set_index_error(struct mailbox *box);
34902486e270728379fd147ca9d7b8d366fcd0e6Timo Sirainenvoid mail_storage_set_index_error(struct mail_storage *storage,
ff7056842f14fd3b30a2d327dfab165b9d15dd30Timo Sirainenbool mail_storage_set_error_from_errno(struct mail_storage *storage);
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainenvoid mail_storage_copy_list_error(struct mail_storage *storage,
268b72128fc3400912e9a6b83faf4950a367c2ffTimo Sirainenvoid mail_storage_copy_error(struct mail_storage *dest,
7522446d6514e5593c9d4d7e4beacd328301cb23Aki Tuomi/* set record in mail cache corrupted */
b99515ba4105f6bfd7fa7590dcc73fabf734dec6Timo Sirainenvoid mail_set_mail_cache_corrupted(struct mail *mail, const char *fmt, ...)
6c51e3c3dc8dc5dc6fef2280b7c2c9ebef3de8f0Aki Tuomi/* Indicate mail being expunged by autoexpunge */
d9a129b491613014ce5f31fe1ab20903e2899ea4Timo Sirainen/* Returns TRUE if everything should already be in memory after this call
d9a129b491613014ce5f31fe1ab20903e2899ea4Timo Sirainen or if prefetching is not supported, i.e. the caller shouldn't do more
d9a129b491613014ce5f31fe1ab20903e2899ea4Timo Sirainen prefetching before this message is handled. */
7631f16156aca373004953fe6b01a7f343fb47e0Timo Sirainenvoid mail_set_seq_saving(struct mail *mail, uint32_t seq);
722c012ccadcf1f63d70439a2564e77510b6dd86Aki Tuomi/* Returns true IF and only IF the mail has EITHER one of the
722c012ccadcf1f63d70439a2564e77510b6dd86Aki Tuomi attachment keywords set. If it has both, or none, it will return FALSE. */
722c012ccadcf1f63d70439a2564e77510b6dd86Aki Tuomibool mail_has_attachment_keywords(struct mail *mail);
722c012ccadcf1f63d70439a2564e77510b6dd86Aki Tuomi/* Sets attachment keywords. */
722c012ccadcf1f63d70439a2564e77510b6dd86Aki Tuomivoid mail_set_attachment_keywords(struct mail *mail);
b83deefd2cf1e293373673eefb4d5cf60907978cTimo Sirainenint mailbox_mark_index_deleted(struct mailbox *box, bool del);
9fc97c8aa8190df87624d214bcc5d0b5362bec93Timo Sirainen/* Easy wrapper for getting mailbox's MAILBOX_LIST_PATH_TYPE_MAILBOX.
9fc97c8aa8190df87624d214bcc5d0b5362bec93Timo Sirainen The mailbox must already be opened and the caller must know that the
9fc97c8aa8190df87624d214bcc5d0b5362bec93Timo Sirainen storage has mailbox files (i.e. NULL/empty path is never returned). */
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainenconst char *mailbox_get_path(struct mailbox *box) ATTR_PURE;
546335814920fb6b5b44c68c7803e654eefeae9dTimo Sirainen/* Similar to mailbox_get_path() but for MAILBOX_LIST_PATH_TYPE_INDEX. */
546335814920fb6b5b44c68c7803e654eefeae9dTimo Sirainenconst char *mailbox_get_index_path(struct mailbox *box) ATTR_PURE;
9fc97c8aa8190df87624d214bcc5d0b5362bec93Timo Sirainen/* Wrapper to mailbox_list_get_path() */
9fc97c8aa8190df87624d214bcc5d0b5362bec93Timo Sirainenint mailbox_get_path_to(struct mailbox *box, enum mailbox_list_path_type type,
9fc97c8aa8190df87624d214bcc5d0b5362bec93Timo Sirainen const char **path_r);
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen/* Get mailbox permissions. */
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainenconst struct mailbox_permissions *mailbox_get_permissions(struct mailbox *box);
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen/* Force permissions to be refreshed on next lookup */
3c493c276f599d9b9cd10764876d648003046954Timo Sirainenvoid mailbox_refresh_permissions(struct mailbox *box);
f46885a5b78b15a8d2419f6e5d13b643bd85e41fTimo Sirainen/* Open private index files for mailbox. Returns 1 if opened, 0 if there
f46885a5b78b15a8d2419f6e5d13b643bd85e41fTimo Sirainen are no private indexes (or flags) in this mailbox, -1 if error. */
f46885a5b78b15a8d2419f6e5d13b643bd85e41fTimo Sirainenint mailbox_open_index_pvt(struct mailbox *box);
94f84d1c3f786d1b92dd2a1507f83a2dad887c56Timo Sirainen/* Create path's directory with proper permissions. The root directory is also
94f84d1c3f786d1b92dd2a1507f83a2dad887c56Timo Sirainen created if necessary. Returns 1 if created, 0 if it already existed,
94f84d1c3f786d1b92dd2a1507f83a2dad887c56Timo Sirainen -1 if error. */
94f84d1c3f786d1b92dd2a1507f83a2dad887c56Timo Sirainenint mailbox_mkdir(struct mailbox *box, const char *path,
94f84d1c3f786d1b92dd2a1507f83a2dad887c56Timo Sirainen/* Create a non-mailbox type directory for mailbox if it's missing (e.g. index).
94f84d1c3f786d1b92dd2a1507f83a2dad887c56Timo Sirainen Optimized for case where the directory usually exists. */
94f84d1c3f786d1b92dd2a1507f83a2dad887c56Timo Sirainenint mailbox_create_missing_dir(struct mailbox *box,
b0f08544a680b029666ab0e43ebcd913f0b91965Timo Sirainen/* Returns TRUE if mailbox is autocreated. */
b0f08544a680b029666ab0e43ebcd913f0b91965Timo Sirainenbool mailbox_is_autocreated(struct mailbox *box);
2ceb75f820c9415b767a17e1f4830c75093ab867Stephan Bosch/* Returns TRUE if mailbox is autosubscribed. */
2ceb75f820c9415b767a17e1f4830c75093ab867Stephan Boschbool mailbox_is_autosubscribed(struct mailbox *box);
3c493c276f599d9b9cd10764876d648003046954Timo Sirainen/* Returns -1 if error, 0 if failed with EEXIST, 1 if ok */
3c493c276f599d9b9cd10764876d648003046954Timo Sirainenint mailbox_create_fd(struct mailbox *box, const char *path, int flags,
2039bdca260cd123832ddda9b2b6862a4abc53aaTimo Sirainen/* Create a lock file with the given path and settings. If it succeeds,
bd94a2a86e27f4809d087a8269bc4ccdd5f4ede3Timo Sirainen returns 1 and lock_r, which needs to be freed once finished with the lock.
2039bdca260cd123832ddda9b2b6862a4abc53aaTimo Sirainen If lock_set->lock_timeout_secs is reached, returns 0 and error_r. Returns
2039bdca260cd123832ddda9b2b6862a4abc53aaTimo Sirainen -1 and sets error_r on other errors. */
2039bdca260cd123832ddda9b2b6862a4abc53aaTimo Sirainenint mail_storage_lock_create(const char *lock_path,
2039bdca260cd123832ddda9b2b6862a4abc53aaTimo Sirainen struct file_lock **lock_r, const char **error_r);
2039bdca260cd123832ddda9b2b6862a4abc53aaTimo Sirainen/* Create a lock file to the mailbox with the given filename. Returns the same
2039bdca260cd123832ddda9b2b6862a4abc53aaTimo Sirainen as mail_storage_lock_create(). */
bd94a2a86e27f4809d087a8269bc4ccdd5f4ede3Timo Sirainenint mailbox_lock_file_create(struct mailbox *box, const char *lock_fname,
bd94a2a86e27f4809d087a8269bc4ccdd5f4ede3Timo Sirainen unsigned int lock_secs, struct file_lock **lock_r,
bd94a2a86e27f4809d087a8269bc4ccdd5f4ede3Timo Sirainen const char **error_r);
036626b19f14bef582f96e556913ae91b1d67881Timo Sirainenunsigned int mail_storage_get_lock_timeout(struct mail_storage *storage,
036626b19f14bef582f96e556913ae91b1d67881Timo Sirainen unsigned int secs);
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainenvoid mail_storage_free_binary_cache(struct mail_storage *storage);
7a2d48763b43c4fd8bc17c444271f0b802113a5fTimo Sirainenmail_storage_settings_to_index_flags(const struct mail_storage_settings *set);
897368f75a68f97e172ba76540759a10c557f1c3Timo Sirainenvoid mailbox_save_context_deinit(struct mail_save_context *ctx);
66fa646212a2c1cfd3ec45f97488b6a8ae41cdc0Aki Tuomi/* for unit testing */