c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#ifndef MAIL_STORAGE_PRIVATE_H
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#define MAIL_STORAGE_PRIVATE_H
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen#include "module-context.h"
d9076f5939edf5d20a261494b1a861dcbb0d32e2Timo Sirainen#include "unichar.h"
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen#include "file-lock.h"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include "mail-storage.h"
5666a3d6a7ea89362b8d9e8b39b15424cd9d6388Timo Sirainen#include "mail-storage-hooks.h"
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen#include "mail-storage-settings.h"
146f9076cd456ea1e9b3f8536456d9d3c962fadbStephan Bosch#include "mailbox-attribute-private.h"
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen#include "mail-index-private.h"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
2039bdca260cd123832ddda9b2b6862a4abc53aaTimo Sirainenstruct file_lock;
2039bdca260cd123832ddda9b2b6862a4abc53aaTimo Sirainenstruct file_create_settings;
2039bdca260cd123832ddda9b2b6862a4abc53aaTimo Sirainen
8c909e451d14075c05d90382cf8eebc4e354f569Timo Sirainen/* Default prefix for indexes */
8c909e451d14075c05d90382cf8eebc4e354f569Timo Sirainen#define MAIL_INDEX_PREFIX "dovecot.index"
8c909e451d14075c05d90382cf8eebc4e354f569Timo Sirainen
573f0491a5733fe21fa062a455acb4790b4e0499Timo Sirainen/* Block size when read()ing message header. */
573f0491a5733fe21fa062a455acb4790b4e0499Timo Sirainen#define MAIL_READ_HDR_BLOCK_SIZE (1024*4)
573f0491a5733fe21fa062a455acb4790b4e0499Timo Sirainen/* Block size when read()ing message (header and) body. */
3ed2d0f6b5e67e2663d44489d9da3176823789a8Timo Sirainen#define MAIL_READ_FULL_BLOCK_SIZE IO_BLOCK_SIZE
65f8fb656051f1059f7b5a2da9c5555adcc30439Timo Sirainen
1a5573ebc32fae2fe576ec544e1781323c1db609Timo Sirainen#define MAIL_SHARED_STORAGE_NAME "shared"
1a5573ebc32fae2fe576ec544e1781323c1db609Timo Sirainen
82d1fe3d5d04fb11e3e89cce03dc4de191e58f75Timo Sirainenenum mail_storage_list_index_rebuild_reason {
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,
82d1fe3d5d04fb11e3e89cce03dc4de191e58f75Timo Sirainen};
82d1fe3d5d04fb11e3e89cce03dc4de191e58f75Timo Sirainen
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenstruct mail_storage_module_register {
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen unsigned int id;
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen};
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenstruct mail_module_register {
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen unsigned int id;
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen};
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainenstruct mail_storage_vfuncs {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen const struct setting_parser_info *(*get_setting_parser_info)(void);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
f7539a17ea306191b53b8f5e752e228937df9ec3Timo Sirainen struct mail_storage *(*alloc)(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,
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen struct mailbox_list *list);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen void (*get_list_settings)(const struct mail_namespace *ns,
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen struct mailbox_list_settings *set);
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen bool (*autodetect)(const struct mail_namespace *ns,
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen struct mailbox_list_settings *set);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen struct mailbox *(*mailbox_alloc)(struct mail_storage *storage,
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen struct mailbox_list *list,
c0a87e5f3316a57e6f915882fa1951d0fbb74a61Timo Sirainen const char *vname,
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen enum mailbox_flags flags);
3e564425db51f3921ce4de11859777135fdedd15Timo Sirainen int (*purge)(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);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen};
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenunion mail_storage_module_context {
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen struct mail_storage_vfuncs super;
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen struct mail_storage_module_register *reg;
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen};
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainenenum mail_storage_class_flags {
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 MAIL_STORAGE_CLASS_FLAG_UNIQUE_ROOT = 0x02,
e5fd6dfd0a492e4708d4dbb7971d7fc5d7b8fd85Timo Sirainen /* mailbox_open_stream() is supported */
4ba9a1d3facc515b3feb5238a16bcf91f76fac61Timo Sirainen MAIL_STORAGE_CLASS_FLAG_OPEN_STREAMS = 0x04,
4ba9a1d3facc515b3feb5238a16bcf91f76fac61Timo Sirainen /* never use quota for this storage (e.g. virtual mailboxes) */
dfaefeabae939803ceb8c503101e86b5496541d1Timo Sirainen MAIL_STORAGE_CLASS_FLAG_NOQUOTA = 0x08,
dfaefeabae939803ceb8c503101e86b5496541d1Timo Sirainen /* Storage doesn't need a mail root directory */
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen MAIL_STORAGE_CLASS_FLAG_NO_ROOT = 0x10,
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen /* Storage uses one file per message */
8b31f966d9688e07672ef1958dcbdb7686523c04Timo Sirainen MAIL_STORAGE_CLASS_FLAG_FILE_PER_MSG = 0x20,
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 MAIL_STORAGE_CLASS_FLAG_BINARY_DATA = 0x100,
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). */
08e9fd42eb8007e1f9db62c088eef74f906114a5Josef 'Jeff' Sipek MAIL_STORAGE_CLASS_FLAG_STUBS = 0x800,
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen};
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainenstruct mail_binary_cache {
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen struct timeout *to;
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen struct mailbox *box;
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen uint32_t uid;
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen uoff_t orig_physical_pos;
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen bool include_hdr;
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen struct istream *input;
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen uoff_t size;
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen};
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen
97ae33602db7d5bc8eede82512a965d49ab8853bTimo Sirainenstruct mail_storage_error {
97ae33602db7d5bc8eede82512a965d49ab8853bTimo Sirainen char *error_string;
97ae33602db7d5bc8eede82512a965d49ab8853bTimo Sirainen enum mail_error error;
30d50c7e8706f2d750215e009504109ca19cd485Timo Sirainen char *last_internal_error;
30d50c7e8706f2d750215e009504109ca19cd485Timo Sirainen bool last_error_is_internal;
97ae33602db7d5bc8eede82512a965d49ab8853bTimo Sirainen};
97ae33602db7d5bc8eede82512a965d49ab8853bTimo Sirainen
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainenstruct mail_storage {
57a8c6a95e4bce3eeaba36985adb81c07dd683ffTimo Sirainen const char *name;
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen enum mail_storage_class_flags class_flags;
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. */
afe1da042382720393eca6497253106e4eec75e0Timo Sirainen enum mail_fetch_field nonbody_access_fields;
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen struct mail_storage_vfuncs v, *vlast;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* private: */
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen pool_t pool;
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen struct mail_storage *prev, *next;
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainen /* counting number of times mail_storage_create() has returned this
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainen same storage. */
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen int refcount;
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainen /* counting number of objects (e.g. mailbox) that have a pointer
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainen to this storage. */
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainen int obj_refcount;
eecb235c14b49c01774134ea593c266f2d2c2be1Timo Sirainen /* Linked list of all mailboxes in the storage */
eecb235c14b49c01774134ea593c266f2d2c2be1Timo Sirainen struct mailbox *mailboxes;
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. */
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen const char *unique_root_dir;
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen
98c217499d578495e982ea6010ebff831e9669aeMartti Rannanjärvi /* Last error set in mail_storage_set_critical(). */
98c217499d578495e982ea6010ebff831e9669aeMartti Rannanjärvi char *last_internal_error;
98c217499d578495e982ea6010ebff831e9669aeMartti Rannanjärvi
ff7056842f14fd3b30a2d327dfab165b9d15dd30Timo Sirainen char *error_string;
ff7056842f14fd3b30a2d327dfab165b9d15dd30Timo Sirainen enum mail_error error;
97ae33602db7d5bc8eede82512a965d49ab8853bTimo Sirainen ARRAY(struct mail_storage_error) error_stack;
ff7056842f14fd3b30a2d327dfab165b9d15dd30Timo Sirainen
f1743785713e7632459d623d5df2108f4b93accbTimo Sirainen const struct mail_storage *storage_class;
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen struct mail_user *user;
70ead6466f9baa8294e71fc2fba0a4f54f488b5eTimo Sirainen const char *temp_path_prefix;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen const struct mail_storage_settings *set;
ccc895c0358108d2304239063e940b7d75f364abTimo Sirainen
8d630c15a8ed6f85553467c3a231a273defca5f6Timo Sirainen enum mail_storage_flags flags;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
ee116df08d0fdab703483e18fe8076b2ef9fd9d7Timo Sirainen struct mail_storage_callbacks callbacks;
c5ab90cfad9cc3e33bcb1baeb30ffc82a7b7053aTimo Sirainen void *callback_context;
c5ab90cfad9cc3e33bcb1baeb30ffc82a7b7053aTimo Sirainen
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen struct mail_binary_cache binary_cache;
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen /* Filled lazily by mailbox_attribute_*() when accessing shared
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen attributes. */
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen struct dict *_shared_attr_dict;
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen /* Module-specific contexts. See mail_storage_module_id. */
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(union mail_storage_module_context *) module_contexts;
c6afd726060aae56b6622c6c52aec10231c4bf1cTimo Sirainen
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen /* Failed to create shared attribute dict, don't try again */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool shared_attr_dict_failed:1;
98c217499d578495e982ea6010ebff831e9669aeMartti Rannanjärvi bool last_error_is_internal:1;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen};
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenstruct mail_attachment_part {
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen struct message_part *part;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen const char *content_type, *content_disposition;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen};
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainenstruct virtual_mailbox_vfuncs {
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 void (*get_virtual_uids)(struct mailbox *box,
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen struct mailbox *backend_mailbox,
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen const ARRAY_TYPE(seq_range) *backend_uids,
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen ARRAY_TYPE(seq_range) *virtual_uids_r);
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 struct mailbox *backend_mailbox,
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen const ARRAY_TYPE(seq_range) *backend_uids,
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen ARRAY_TYPE(uint32_t) *virtual_uids_r);
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen void (*get_virtual_backend_boxes)(struct mailbox *box,
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen ARRAY_TYPE(mailboxes) *mailboxes,
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen bool only_with_msgs);
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen};
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainenstruct mailbox_vfuncs {
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen bool (*is_readonly)(struct mailbox *box);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen int (*enable)(struct mailbox *box, enum mailbox_feature features);
cff1f182205e674285cf3ff446a0dcf7afea277dTimo Sirainen int (*exists)(struct mailbox *box, bool auto_boxes,
cff1f182205e674285cf3ff446a0dcf7afea277dTimo Sirainen enum mailbox_existence *existence_r);
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen int (*open)(struct mailbox *box);
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen void (*close)(struct mailbox *box);
e03d986a74128f5ba30fcfda9f6e36578f5d8decTimo Sirainen void (*free)(struct mailbox *box);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
f318b3dbe2acc177b8ee1c160e4b5b14e7f2cd41Timo Sirainen int (*create_box)(struct mailbox *box,
f318b3dbe2acc177b8ee1c160e4b5b14e7f2cd41Timo Sirainen const struct mailbox_update *update, bool directory);
f318b3dbe2acc177b8ee1c160e4b5b14e7f2cd41Timo Sirainen int (*update_box)(struct mailbox *box,
f318b3dbe2acc177b8ee1c160e4b5b14e7f2cd41Timo Sirainen const struct mailbox_update *update);
f318b3dbe2acc177b8ee1c160e4b5b14e7f2cd41Timo Sirainen int (*delete_box)(struct mailbox *box);
f318b3dbe2acc177b8ee1c160e4b5b14e7f2cd41Timo Sirainen int (*rename_box)(struct mailbox *src, struct mailbox *dest);
17ad2164c747cedbf81dae1893063e71a3df0356Timo Sirainen
d3280fe317a4598c0868cc440e7a1191c06d0db3Timo Sirainen int (*get_status)(struct mailbox *box, enum mailbox_status_items items,
d3280fe317a4598c0868cc440e7a1191c06d0db3Timo Sirainen struct mailbox_status *status_r);
51327f2489a4e0e615eb9f7d921473cf8512bb79Timo Sirainen int (*get_metadata)(struct mailbox *box,
51327f2489a4e0e615eb9f7d921473cf8512bb79Timo Sirainen enum mailbox_metadata_items items,
51327f2489a4e0e615eb9f7d921473cf8512bb79Timo Sirainen struct mailbox_metadata *metadata_r);
6469cf211a57433335641725dc236ebb2b9fdd3bTimo Sirainen int (*set_subscribed)(struct mailbox *box, bool set);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
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);
9f37ef2a9192e7d47e3d7ac959080fd01120f2e9Aki Tuomi int (*attribute_get)(struct mailbox *box,
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen enum mail_attribute_type type, const char *key,
bd6a8056771b6150685dea319ab5a94e021d17f1Josef 'Jeff' Sipek struct mail_attribute_value *value_r);
62041dfb7d6ac6e9c633a557075999cdfcff7bd5Timo Sirainen struct mailbox_attribute_iter *
62041dfb7d6ac6e9c633a557075999cdfcff7bd5Timo Sirainen (*attribute_iter_init)(struct mailbox *box,
62041dfb7d6ac6e9c633a557075999cdfcff7bd5Timo Sirainen enum mail_attribute_type type,
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);
62041dfb7d6ac6e9c633a557075999cdfcff7bd5Timo Sirainen
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,
d3442384ca53d4b18a493db7dd0b000f470419cfTimo Sirainen struct mail_index_view *list_view,
aa47c9bd1d1fc70cd699c49fd1ca92dbc7615953Timo Sirainen uint32_t seq, bool quick);
c0d069950af1dbc6a4e5c3de3bf2e437796e3ae0Timo Sirainen /* Update the sync extension record. */
c0d069950af1dbc6a4e5c3de3bf2e437796e3ae0Timo Sirainen void (*list_index_update_sync)(struct mailbox *box,
c0d069950af1dbc6a4e5c3de3bf2e437796e3ae0Timo Sirainen struct mail_index_transaction *trans,
c0d069950af1dbc6a4e5c3de3bf2e437796e3ae0Timo Sirainen uint32_t seq);
d3442384ca53d4b18a493db7dd0b000f470419cfTimo Sirainen
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen struct mailbox_sync_context *
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen (*sync_init)(struct mailbox *box,
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen enum mailbox_sync_flags flags);
c979eeda1f46483d9c963e265786b701d7683d77Timo Sirainen bool (*sync_next)(struct mailbox_sync_context *ctx,
c979eeda1f46483d9c963e265786b701d7683d77Timo Sirainen struct mailbox_sync_rec *sync_rec_r);
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen int (*sync_deinit)(struct mailbox_sync_context *ctx,
2584e86cc2d8c31ba30a4109cf4ba09d1e37e28aTimo Sirainen struct mailbox_sync_status *status_r);
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen
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,
5137d2d80255938a0f5fb8f3c1a21b34cf11ada3Timo Sirainen enum mailbox_sync_type sync_type);
5137d2d80255938a0f5fb8f3c1a21b34cf11ada3Timo Sirainen
f81f4bc282cd1944cec187bae89c0701a416ed2aTimo Sirainen void (*notify_changes)(struct mailbox *box);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct mailbox_transaction_context *
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen (*transaction_begin)(struct mailbox *box,
c6ce2e251ac75fa650c7fbfa52150eae69386293Martti Rannanjärvi enum mailbox_transaction_flags flags,
c6ce2e251ac75fa650c7fbfa52150eae69386293Martti Rannanjärvi const char *reason);
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);
dbe64f3893616a4005c8946be75d2dc8f6823d72Timo Sirainen
8a13b020f90e080570658b18c042e7e352c8b14fTimo Sirainen enum mail_flags (*get_private_flags_mask)(struct mailbox *box);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen struct mail *
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen (*mail_alloc)(struct mailbox_transaction_context *t,
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen enum mail_fetch_field wanted_fields,
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct mail_search_context *
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen (*search_init)(struct mailbox_transaction_context *t,
c4b376dd6e0c423006d7ac83a39253bcaf8e7c47Timo Sirainen struct mail_search_args *args,
eef4ba0cc3e78f8c26804c1c9251a76580a41f0cTimo Sirainen const enum mail_sort_type *sort_program,
eef4ba0cc3e78f8c26804c1c9251a76580a41f0cTimo Sirainen enum mail_fetch_field wanted_fields,
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,
eef4ba0cc3e78f8c26804c1c9251a76580a41f0cTimo Sirainen struct mail **mail_r, bool *tryagain_r);
a3ee5ce6ecc8e228ee69300fdd562d7ac8be89a7Timo Sirainen /* Internal search function which updates ctx->seq */
bd1b2615928a1e8be190cb0405754f0aec8cac2fTimo Sirainen bool (*search_next_update_seq)(struct mail_search_context *ctx);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
e3aeeb634245e80d4f643f8d2eea11d6b72336d8Timo Sirainen struct mail_save_context *
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);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
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 void (*transaction_save_commit_post)
1460ef7a18c53216ddb4a94bb62fba96076aae8eTimo Sirainen (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);
1460ef7a18c53216ddb4a94bb62fba96076aae8eTimo Sirainen
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen bool (*is_inconsistent)(struct mailbox *box);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen};
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenunion mailbox_module_context {
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen struct mailbox_vfuncs super;
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen struct mail_storage_module_register *reg;
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen};
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen
0177594fa5217b02001f4ec8752154fd2b05c545Timo Sirainenstruct mail_msgpart_partial_cache {
0177594fa5217b02001f4ec8752154fd2b05c545Timo Sirainen uint32_t uid;
0177594fa5217b02001f4ec8752154fd2b05c545Timo Sirainen uoff_t physical_start;
0177594fa5217b02001f4ec8752154fd2b05c545Timo Sirainen uoff_t physical_pos, virtual_pos;
0177594fa5217b02001f4ec8752154fd2b05c545Timo Sirainen};
0177594fa5217b02001f4ec8752154fd2b05c545Timo Sirainen
2c70086138fe7ac9abf52cd4223c224fe0bbb488Timo Sirainenstruct mailbox_index_vsize {
2c70086138fe7ac9abf52cd4223c224fe0bbb488Timo Sirainen uint64_t vsize;
2c70086138fe7ac9abf52cd4223c224fe0bbb488Timo Sirainen uint32_t highest_uid;
2c70086138fe7ac9abf52cd4223c224fe0bbb488Timo Sirainen uint32_t message_count;
2c70086138fe7ac9abf52cd4223c224fe0bbb488Timo Sirainen};
2c70086138fe7ac9abf52cd4223c224fe0bbb488Timo Sirainen
2b9dbb270ad82e58d5f3581436e6f143176d5819Timo Sirainenstruct mailbox_index_pop3_uidl {
2b9dbb270ad82e58d5f3581436e6f143176d5819Timo Sirainen uint32_t max_uid_with_pop3_uidl;
2b9dbb270ad82e58d5f3581436e6f143176d5819Timo Sirainen};
2b9dbb270ad82e58d5f3581436e6f143176d5819Timo Sirainen
1ae5d61ec366fdb2f3c5b150ca378d6141b0f4bdTimo Sirainenstruct mailbox_index_first_saved {
1ae5d61ec366fdb2f3c5b150ca378d6141b0f4bdTimo Sirainen uint32_t uid;
1ae5d61ec366fdb2f3c5b150ca378d6141b0f4bdTimo Sirainen uint32_t timestamp;
1ae5d61ec366fdb2f3c5b150ca378d6141b0f4bdTimo Sirainen};
1ae5d61ec366fdb2f3c5b150ca378d6141b0f4bdTimo Sirainen
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainenstruct mailbox {
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen const char *name;
df00412606a00714a6e85383fa87fbdc7cc1fb5bTimo Sirainen /* mailbox's virtual name (from mail_namespace_get_vname()) */
df00412606a00714a6e85383fa87fbdc7cc1fb5bTimo Sirainen const char *vname;
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen struct mail_storage *storage;
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen struct mailbox_list *list;
b644a77b00ce21c67a7becda974a12dfe3a946e4Timo Sirainen struct event *event;
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen struct mailbox_vfuncs v, *vlast;
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen /* virtual mailboxes: */
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen const struct virtual_mailbox_vfuncs *virtual_vfuncs;
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen/* private: */
d938e9e4ec4c0f326dffd5ebe42c1ad893ce7e52Timo Sirainen pool_t pool, metadata_pool;
eecb235c14b49c01774134ea593c266f2d2c2be1Timo Sirainen /* Linked list of all mailboxes in this storage */
eecb235c14b49c01774134ea593c266f2d2c2be1Timo Sirainen struct mailbox *prev, *next;
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen /* these won't be set until mailbox is opened: */
ca98d6a1bbe73499da758a36bfab2963375c8d06Timo Sirainen struct mail_index *index;
ca98d6a1bbe73499da758a36bfab2963375c8d06Timo Sirainen struct mail_index_view *view;
ca98d6a1bbe73499da758a36bfab2963375c8d06Timo Sirainen struct mail_cache *cache;
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. */
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen struct mail_index *index_pvt;
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen struct mail_index_view *view_pvt;
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen /* Filled lazily by mailbox_get_permissions() */
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen struct mailbox_permissions _perm;
9fc97c8aa8190df87624d214bcc5d0b5362bec93Timo Sirainen /* Filled lazily when mailbox is opened, use mailbox_get_path()
9fc97c8aa8190df87624d214bcc5d0b5362bec93Timo Sirainen to access it */
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen const char *_path;
546335814920fb6b5b44c68c7803e654eefeae9dTimo Sirainen /* Filled lazily when mailbox is opened, use mailbox_get_index_path()
546335814920fb6b5b44c68c7803e654eefeae9dTimo Sirainen to access it */
546335814920fb6b5b44c68c7803e654eefeae9dTimo Sirainen const char *_index_path;
4b41218f9e09386ad5d8f279355aad1dfb64392dTimo Sirainen /* Reason for why mailbox is being accessed or NULL if unknown. */
4b41218f9e09386ad5d8f279355aad1dfb64392dTimo Sirainen const char *reason;
ca98d6a1bbe73499da758a36bfab2963375c8d06Timo Sirainen
ca98d6a1bbe73499da758a36bfab2963375c8d06Timo Sirainen /* default vfuncs for new struct mails. */
ca98d6a1bbe73499da758a36bfab2963375c8d06Timo Sirainen const struct mail_vfuncs *mail_vfuncs;
eb1572d7c44ebc7b0b039d085c3dbab2ef7043ddTimo Sirainen /* Mailbox settings, or NULL if defaults */
eb1572d7c44ebc7b0b039d085c3dbab2ef7043ddTimo Sirainen const struct mailbox_settings *set;
ca98d6a1bbe73499da758a36bfab2963375c8d06Timo Sirainen
bd4e36a8cd7257cca7d1434c49a1e343ed7c5100Timo Sirainen /* If non-zero, fail mailbox_open() with this error. mailbox_alloc()
bd4e36a8cd7257cca7d1434c49a1e343ed7c5100Timo Sirainen can set this to force open to fail. */
bd4e36a8cd7257cca7d1434c49a1e343ed7c5100Timo Sirainen enum mail_error open_error;
bd4e36a8cd7257cca7d1434c49a1e343ed7c5100Timo Sirainen
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen struct istream *input;
df00412606a00714a6e85383fa87fbdc7cc1fb5bTimo Sirainen const char *index_prefix;
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen enum mailbox_flags flags;
42507d758b053bb483de58fba55c73a9eb5d3fbaTimo Sirainen unsigned int transaction_count;
c0c346d0e6a76137ba5006857ed03b1227804170Timo Sirainen unsigned int attribute_iter_count;
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen enum mailbox_feature enabled_features;
0177594fa5217b02001f4ec8752154fd2b05c545Timo Sirainen struct mail_msgpart_partial_cache partial_cache;
382f23541ce657be87b079abd6784d376fb4eb43Timo Sirainen uint32_t vsize_hdr_ext_id;
2b9dbb270ad82e58d5f3581436e6f143176d5819Timo Sirainen uint32_t pop3_uidl_hdr_ext_id;
97a5e150cacf7da9dd200e317b75460352038d65Timo Sirainen uint32_t box_name_hdr_ext_id;
3743948b65bd079cd6f2502d35bd21666c1a2f5aAki Tuomi uint32_t box_last_rename_stamp_ext_id;
134987bc3b685d7ec71c04e9337f7125cff0698fTimo Sirainen uint32_t mail_vsize_ext_id;
42507d758b053bb483de58fba55c73a9eb5d3fbaTimo Sirainen
817d027593510c3ba70ad542ce0011f5f6916d1eTimo Sirainen /* MAIL_RECENT flags handling */
817d027593510c3ba70ad542ce0011f5f6916d1eTimo Sirainen ARRAY_TYPE(seq_range) recent_flags;
817d027593510c3ba70ad542ce0011f5f6916d1eTimo Sirainen uint32_t recent_flags_prev_uid;
817d027593510c3ba70ad542ce0011f5f6916d1eTimo Sirainen uint32_t recent_flags_count;
817d027593510c3ba70ad542ce0011f5f6916d1eTimo Sirainen
6ae329de09afb7214c906d762320847e05469d53Timo Sirainen struct mail_index_view *tmp_sync_view;
6ae329de09afb7214c906d762320847e05469d53Timo Sirainen
f81f4bc282cd1944cec187bae89c0701a416ed2aTimo Sirainen /* Mailbox notification settings: */
f81f4bc282cd1944cec187bae89c0701a416ed2aTimo Sirainen mailbox_notify_callback_t *notify_callback;
f81f4bc282cd1944cec187bae89c0701a416ed2aTimo Sirainen void *notify_context;
7e2671b295927b461adc8b6c4ed6a1c4761fb323Timo Sirainen struct timeout *to_notify, *to_notify_delay;
7e2671b295927b461adc8b6c4ed6a1c4761fb323Timo Sirainen struct mailbox_notify_file *notify_files;
f81f4bc282cd1944cec187bae89c0701a416ed2aTimo Sirainen
fcfe85637e1ee14a9fc39c41fd6ceca106301542Timo Sirainen /* Increased by one for each new struct mailbox. */
fcfe85637e1ee14a9fc39c41fd6ceca106301542Timo Sirainen unsigned int generation_sequence;
fcfe85637e1ee14a9fc39c41fd6ceca106301542Timo Sirainen
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen /* Saved search results */
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(struct mail_search_result *) search_results;
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen /* Module-specific contexts. See mail_storage_module_id. */
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(union mailbox_module_context *) module_contexts;
5fb3bff645380804c9db2510940c41db6b8fdb01Timo Sirainen
5fb3bff645380804c9db2510940c41db6b8fdb01Timo Sirainen /* When FAST open flag is used, the mailbox isn't actually opened until
5fb3bff645380804c9db2510940c41db6b8fdb01Timo Sirainen it's synced for the first time. */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool opened:1;
4bbd396aa6198c84f3f7763b6e8a63a26e97e141Timo Sirainen /* Mailbox was deleted while we had it open. */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool mailbox_deleted:1;
7baab0b0b60df7ce9093d0881cd322dff1e79491Timo Sirainen /* Mailbox is being created */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool creating:1;
3f91e60401495a4046c73992fabaa5e77200a451Timo Sirainen /* Mailbox is being deleted */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool deleting:1;
3857e2945a3b6744d603f0f5a656849ed8436ba3Timo Sirainen /* Mailbox is being undeleted */
3857e2945a3b6744d603f0f5a656849ed8436ba3Timo Sirainen bool mailbox_undeleting:1;
f90cbe597c41d5cc91debd371f8648bd8e6ffbc2Timo Sirainen /* Don't use MAIL_INDEX_SYNC_FLAG_DELETING_INDEX for sync flag */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool delete_sync_check:1;
33b469d1ca66dd2cc496d2d990b8b98e72952a29Timo Sirainen /* Delete mailbox only if it's empty */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool deleting_must_be_empty:1;
58ba0fe5a6904d3a65cfe268411f4cbb881234eeTimo Sirainen /* The backend wants to skip checking if there are 0 messages before
58ba0fe5a6904d3a65cfe268411f4cbb881234eeTimo Sirainen calling mailbox_list.delete_mailbox() */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool delete_skip_empty_check:1;
6b0d8106ae51ffc6ce45636b34d2e21cbefca7fdTimo Sirainen /* Mailbox was already marked as deleted within this allocation. */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool marked_deleted:1;
eb64c3586d854cddd693f0b811d897399076a441Timo Sirainen /* TRUE if this is an INBOX for this user */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool inbox_user:1;
eb64c3586d854cddd693f0b811d897399076a441Timo Sirainen /* TRUE if this is an INBOX for this namespace (user or shared) */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool inbox_any:1;
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) */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool disable_reflink_copy_to:1;
b3484b5b1f47e4cf112f0e371478a2d7794b31bbTimo Sirainen /* Don't allow creating any new keywords */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool disallow_new_keywords:1;
d81131d3bbb4f0befb62a661d1785cf8c84a17e2Timo Sirainen /* Mailbox has been synced at least once */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool synced:1;
9456a4a3e74929f9d3d5b00b93be6d8eb69bc52aTimo Sirainen /* Updating cache file is disabled */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool mail_cache_disabled:1;
4e3bcf7fdaeef92dd07a2acb1ded58422a907e87Timo Sirainen /* Update first_saved field to mailbox list index. */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool update_first_saved:1;
19e161dd9e2c3a2ffc96ee8852bec0720cb30d1cTimo Sirainen /* mailbox_verify_create_name() only checks for mailbox_verify_name() */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool skip_create_name_restrictions:1;
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. */
540555c5b435203e1c26c8e7b924b2643ae07ae3Timo Sirainen bool corrupted_mailbox_name:1;
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen};
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainenstruct mail_vfuncs {
0d86aa0d47f7393c669c084b34c0537b193688adTimo Sirainen void (*close)(struct mail *mail);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen void (*free)(struct mail *mail);
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);
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen bool (*prefetch)(struct mail *mail);
421d30619384e72a27e2a5d13ff6525aff4d17feTimo Sirainen void (*precache)(struct mail *mail);
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainen void (*add_temp_wanted_fields)(struct mail *mail,
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainen enum mail_fetch_field fields,
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainen struct mailbox_header_lookup_ctx *headers);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen enum mail_flags (*get_flags)(struct mail *mail);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen const char *const *(*get_keywords)(struct mail *mail);
a757f31393b9d6fc7760a9dec8363404ab3ae576Timo Sirainen const ARRAY_TYPE(keyword_indexes) *
a757f31393b9d6fc7760a9dec8363404ab3ae576Timo Sirainen (*get_keyword_indexes)(struct mail *mail);
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen uint64_t (*get_modseq)(struct mail *mail);
f46885a5b78b15a8d2419f6e5d13b643bd85e41fTimo Sirainen uint64_t (*get_pvt_modseq)(struct mail *mail);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen int (*get_parts)(struct mail *mail,
c0225f7f6b43d34dc58c17d3304f0fd60ab89894Timo Sirainen struct message_part **parts_r);
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
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen int (*get_first_header)(struct mail *mail, const char *field,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen bool decode_to_utf8, const char **value_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen int (*get_headers)(struct mail *mail, const char *field,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen bool decode_to_utf8, const char *const **value_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen int (*get_header_stream)(struct mail *mail,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen struct mailbox_header_lookup_ctx *headers,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen struct istream **stream_r);
6df0ab0c1ab91f06b6418cb30eff44405a1b8f02Timo Sirainen int (*get_stream)(struct mail *mail, bool get_body,
6df0ab0c1ab91f06b6418cb30eff44405a1b8f02Timo Sirainen struct message_size *hdr_size,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen struct message_size *body_size,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen struct istream **stream_r);
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen int (*get_binary_stream)(struct mail *mail,
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen const struct message_part *part,
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen bool include_hdr, uoff_t *size_r,
e53ab6c7081246c865917f9aa0eff031a08ad1e7Timo Sirainen unsigned int *lines_r, bool *binary_r,
e53ab6c7081246c865917f9aa0eff031a08ad1e7Timo Sirainen struct istream **stream_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen
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);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen void (*update_flags)(struct mail *mail, enum modify_type modify_type,
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen enum mail_flags flags);
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen void (*update_keywords)(struct mail *mail, enum modify_type modify_type,
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen struct mail_keywords *keywords);
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);
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen void (*expunge)(struct mail *mail);
838e367716bbd5e44b4a1691db9cbf72af53e9f0Timo Sirainen void (*set_cache_corrupted)(struct mail *mail,
0206dc57f2c04da69599dea5816235cfeb2b897aMartti Rannanjärvi enum mail_fetch_field field,
0206dc57f2c04da69599dea5816235cfeb2b897aMartti Rannanjärvi const char *reason);
6564208826b0f46a00f010d1b5711d85944c3c88Timo Sirainen int (*istream_opened)(struct mail *mail, struct istream **input);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen};
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenunion mail_module_context {
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen struct mail_vfuncs super;
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen struct mail_module_register *reg;
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen};
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainenstruct mail_private {
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen struct mail mail;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen struct mail_vfuncs v, *vlast;
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. */
13e130c3af3032982de6b1d13c6dcddda9164848Timo Sirainen struct mail *vmail;
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen uint32_t seq_pvt;
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainen /* initial wanted fields/headers, set by mail_alloc(): */
310767ca33e7636d40ec45dee68a2c319a5fa3c0Timo Sirainen enum mail_fetch_field wanted_fields;
310767ca33e7636d40ec45dee68a2c319a5fa3c0Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers;
310767ca33e7636d40ec45dee68a2c319a5fa3c0Timo Sirainen
5f44975ec6c5755dd74bcd4c47a123a7242ecab3Timo Sirainen pool_t pool, data_pool;
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(union mail_module_context *) module_contexts;
2c8ca7e88ec881c473fb90e5f647c1f563877164Timo Sirainen
2c8ca7e88ec881c473fb90e5f647c1f563877164Timo Sirainen const char *get_stream_reason;
6c51e3c3dc8dc5dc6fef2280b7c2c9ebef3de8f0Aki Tuomi
6c51e3c3dc8dc5dc6fef2280b7c2c9ebef3de8f0Aki Tuomi bool autoexpunged:1;
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen};
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct mailbox_list_context {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct mail_storage *storage;
e4c90f0b88e40a8f92b8f5e1f1a3ea701e5c965cTimo Sirainen enum mailbox_list_flags flags;
defb12ecd360df672ffb2f4dbf4d1218a0a9549cTimo Sirainen bool failed;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen};
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenunion mailbox_transaction_module_context {
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen struct mail_storage_module_register *reg;
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen};
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainenstruct mailbox_transaction_stats {
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen unsigned long open_lookup_count;
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen unsigned long stat_lookup_count;
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen unsigned long fstat_lookup_count;
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen /* number of files we've opened and read */
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen unsigned long files_read_count;
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen /* number of bytes we've had to read from files */
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen unsigned long long files_read_bytes;
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen /* number of cache lookup hits */
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen unsigned long cache_hit_count;
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen};
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainenstruct mail_save_private_changes {
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. */
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen unsigned int mailnum;
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen enum mail_flags flags;
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen};
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct mailbox_transaction_context {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct mailbox *box;
194603b35061fea1ee8d171a7104b6985c610966Timo Sirainen enum mailbox_transaction_flags flags;
d1fbd2c264368d8b4c7139b96e3b21f45930b857Timo Sirainen char *reason;
194603b35061fea1ee8d171a7104b6985c610966Timo Sirainen
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen union mail_index_transaction_module_context module_ctx;
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen struct mail_index_transaction_vfuncs super;
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen int mail_ref_count;
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen struct mail_index_transaction *itrans;
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen struct dict_transaction_context *attr_pvt_trans, *attr_shared_trans;
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen /* view contains all changes done within this transaction */
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen struct mail_index_view *view;
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen /* for private index updates: */
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen struct mail_index_transaction *itrans_pvt;
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen struct mail_index_view *view_pvt;
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen struct mail_cache_view *cache_view;
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen struct mail_cache_transaction_ctx *cache_trans;
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen
96308127e006bb3b1108093bcf4cc1fd9481cb7aTimo Sirainen struct mail_transaction_commit_changes *changes;
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(union mailbox_transaction_module_context *) module_contexts;
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen
2b9dbb270ad82e58d5f3581436e6f143176d5819Timo Sirainen uint32_t prev_pop3_uidl_tracking_seq;
2b9dbb270ad82e58d5f3581436e6f143176d5819Timo Sirainen uint32_t highest_pop3_uidl_uid;
2b9dbb270ad82e58d5f3581436e6f143176d5819Timo Sirainen
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen struct mail_save_context *save_ctx;
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen /* number of mails saved/copied within this transaction. */
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen unsigned int save_count;
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
1eaaa2c9003cf3fbf672d597473e3f84e70d2ee6Timo Sirainen /* these statistics are never reset by mail-storage API: */
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen struct mailbox_transaction_stats stats;
1eaaa2c9003cf3fbf672d597473e3f84e70d2ee6Timo Sirainen /* Set to TRUE to update stats_* fields */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool stats_track:1;
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen};
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenunion mail_search_module_context {
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen struct mail_storage_module_register *reg;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen};
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct mail_search_context {
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen struct mailbox_transaction_context *transaction;
e63bdfedcf61e1a9ee21990140cbd0d0638da7e1Timo Sirainen
c4b376dd6e0c423006d7ac83a39253bcaf8e7c47Timo Sirainen struct mail_search_args *args;
e63bdfedcf61e1a9ee21990140cbd0d0638da7e1Timo Sirainen struct mail_search_sort_program *sort_program;
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen enum mail_fetch_field wanted_fields;
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers;
d9076f5939edf5d20a261494b1a861dcbb0d32e2Timo Sirainen normalizer_func_t *normalizer;
e63bdfedcf61e1a9ee21990140cbd0d0638da7e1Timo Sirainen
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 struct mail_search_result *update_result;
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen /* add matches to these search results */
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(struct mail_search_result *) results;
3dd0679b6f24be0287cc42d7a60bbf59cdf8b637Timo Sirainen
a3ee5ce6ecc8e228ee69300fdd562d7ac8be89a7Timo Sirainen uint32_t seq;
f4616f1875297fb2f583d913c0f01b075bdecd5bTimo Sirainen uint32_t progress_cur, progress_max;
f4616f1875297fb2f583d913c0f01b075bdecd5bTimo Sirainen
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(union mail_search_module_context *) module_contexts;
4321f6c969e7b8f6b243ff5bb6b8d297921676f6Timo Sirainen
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool seen_lost_data:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool progress_hidden:1;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen};
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainenstruct mail_save_data {
e3aeeb634245e80d4f643f8d2eea11d6b72336d8Timo Sirainen enum mail_flags flags;
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen enum mail_flags pvt_flags;
e3aeeb634245e80d4f643f8d2eea11d6b72336d8Timo Sirainen struct mail_keywords *keywords;
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen uint64_t min_modseq;
e3aeeb634245e80d4f643f8d2eea11d6b72336d8Timo Sirainen
0cce885512b836ce021260a58e7b4f099b36d0f1Timo Sirainen time_t received_date, save_date;
e3aeeb634245e80d4f643f8d2eea11d6b72336d8Timo Sirainen int received_tz_offset;
e3aeeb634245e80d4f643f8d2eea11d6b72336d8Timo Sirainen
61cae213dc69070c1cef266578057710e34e0d12Timo Sirainen uint32_t uid, stub_seq;
0cce885512b836ce021260a58e7b4f099b36d0f1Timo Sirainen char *guid, *pop3_uidl, *from_envelope;
9617ac7078a17bd346fed69526861c3e7fd9d809Timo Sirainen unsigned int pop3_order;
4d527c363482be2b65dd0573d878ecda86cbb0bbTimo Sirainen
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen struct ostream *output;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen struct mail_save_attachment *attach;
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen};
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainenstruct mail_save_context {
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen struct mailbox_transaction_context *transaction;
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen struct mail *dest_mail;
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. */
d0d37a769d7e54646de025a43d2cb888478cb218Timo Sirainen struct mail *copy_src_mail;
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen /* data that changes for each saved mail */
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen struct mail_save_data data;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen
b62140c5849297a800fee942026d9c3cb8c60206Timo Sirainen /* returns TRUE if message part is an attachment. */
b62140c5849297a800fee942026d9c3cb8c60206Timo Sirainen bool (*part_is_attachment)(struct mail_save_context *ctx,
b62140c5849297a800fee942026d9c3cb8c60206Timo Sirainen const struct mail_attachment_part *part);
b62140c5849297a800fee942026d9c3cb8c60206Timo Sirainen
b09eaeb9a81e5b58c6e605eb762573a2b4a69e0eTimo Sirainen /* mailbox_save_alloc() called, but finish/cancel not.
b09eaeb9a81e5b58c6e605eb762573a2b4a69e0eTimo Sirainen the same context is usually returned by the backends for reuse. */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool unfinished:1;
ba8ff75a149d6936f769a2d1dfceaab9da87863bTimo Sirainen /* mailbox_save_finish() or mailbox_copy() is being called. */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool finishing:1;
05150df8fbda6b8fdfafcfb0aa9003f1da4ecacaTimo Sirainen /* mail was copied or moved using saving (requires:
05150df8fbda6b8fdfafcfb0aa9003f1da4ecacaTimo Sirainen copying_or_moving==TRUE). */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool copying_via_save:1;
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. */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool saving:1;
05150df8fbda6b8fdfafcfb0aa9003f1da4ecacaTimo Sirainen /* mail is being moved - ignore quota (requires:
05150df8fbda6b8fdfafcfb0aa9003f1da4ecacaTimo Sirainen copying_or_moving==TRUE && saving==FALSE). */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool moving:1;
05150df8fbda6b8fdfafcfb0aa9003f1da4ecacaTimo Sirainen /* mail is being copied or moved. However, this is set also with
05150df8fbda6b8fdfafcfb0aa9003f1da4ecacaTimo Sirainen mailbox_save_using_mail() and then saving==TRUE. */
05150df8fbda6b8fdfafcfb0aa9003f1da4ecacaTimo Sirainen bool copying_or_moving:1;
a423d985ba7261661475811c22b21b80ec765a71Timo Sirainen};
a423d985ba7261661475811c22b21b80ec765a71Timo Sirainen
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainenstruct mailbox_sync_context {
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen struct mailbox *box;
64b61cd24d630223478ccbe1934b9f60f0881f59Timo Sirainen enum mailbox_sync_flags flags;
4906f652013f9f9ea806602b5cd677ef0d039d62Timo Sirainen bool open_failed;
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen};
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenstruct mailbox_header_lookup_ctx {
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen struct mailbox *box;
a4f09749814b93e8ad3ec8a0dc18885b874d6f8cTimo Sirainen pool_t pool;
de58be41126e5d68008d2ea706d62ccdc1f29337Timo Sirainen int refcount;
a4f09749814b93e8ad3ec8a0dc18885b874d6f8cTimo Sirainen
a4f09749814b93e8ad3ec8a0dc18885b874d6f8cTimo Sirainen unsigned int count;
a4f09749814b93e8ad3ec8a0dc18885b874d6f8cTimo Sirainen const char *const *name;
a4f09749814b93e8ad3ec8a0dc18885b874d6f8cTimo Sirainen unsigned int *idx;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen};
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
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
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen/* Storage's module_id for mail_index. */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenextern struct mail_module_register mail_module_register;
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen
677cc0d62b41c7506246bf1b992a400a11896474Timo Sirainenextern struct event_category event_category_storage;
b644a77b00ce21c67a7becda974a12dfe3a946e4Timo Sirainenextern struct event_category event_category_mailbox;
c499c40caf37f766968a551909190c5b009a9b15Timo Sirainenextern struct event_category event_category_mail;
677cc0d62b41c7506246bf1b992a400a11896474Timo Sirainen
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen#define MAIL_STORAGE_CONTEXT(obj) \
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen MODULE_CONTEXT(obj, mail_storage_mail_index_module)
c51390c3ae6e373e7b4a052a94e8e4065b98321cAki Tuomi#define MAIL_STORAGE_CONTEXT_REQUIRE(obj) \
c51390c3ae6e373e7b4a052a94e8e4065b98321cAki Tuomi MODULE_CONTEXT_REQUIRE(obj, mail_storage_mail_index_module)
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenextern MODULE_CONTEXT_DEFINE(mail_storage_mail_index_module,
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen &mail_index_module_register);
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainenvoid mail_storage_obj_ref(struct mail_storage *storage);
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainenvoid mail_storage_obj_unref(struct mail_storage *storage);
420040a5930a2b497e79ff0b5f59ba4b764a5b39Timo Sirainen
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,
ff7056842f14fd3b30a2d327dfab165b9d15dd30Timo Sirainen enum mail_error error, const char *string);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_storage_set_critical(struct mail_storage *storage,
43d32cbe60fdaef2699d99f1ca259053e9350411Timo Sirainen const char *fmt, ...) ATTR_FORMAT(2, 3);
4e3b79ac7787b1a867514a6ac3d1b623b72a26c6Timo Sirainenvoid mailbox_set_critical(struct mailbox *box,
4e3b79ac7787b1a867514a6ac3d1b623b72a26c6Timo Sirainen const char *fmt, ...) ATTR_FORMAT(2, 3);
4e3b79ac7787b1a867514a6ac3d1b623b72a26c6Timo Sirainenvoid mail_set_critical(struct mail *mail,
4e3b79ac7787b1a867514a6ac3d1b623b72a26c6Timo Sirainen const char *fmt, ...) ATTR_FORMAT(2, 3);
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,
34902486e270728379fd147ca9d7b8d366fcd0e6Timo Sirainen struct mail_index *index);
ff7056842f14fd3b30a2d327dfab165b9d15dd30Timo Sirainenbool mail_storage_set_error_from_errno(struct mail_storage *storage);
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainenvoid mail_storage_copy_list_error(struct mail_storage *storage,
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen struct mailbox_list *list);
268b72128fc3400912e9a6b83faf4950a367c2ffTimo Sirainenvoid mail_storage_copy_error(struct mail_storage *dest,
268b72128fc3400912e9a6b83faf4950a367c2ffTimo Sirainen struct mail_storage *src);
7522446d6514e5593c9d4d7e4beacd328301cb23Aki Tuomi/* set record in mail cache corrupted */
b99515ba4105f6bfd7fa7590dcc73fabf734dec6Timo Sirainenvoid mail_set_mail_cache_corrupted(struct mail *mail, const char *fmt, ...)
b99515ba4105f6bfd7fa7590dcc73fabf734dec6Timo Sirainen ATTR_FORMAT(2, 3);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen
6c51e3c3dc8dc5dc6fef2280b7c2c9ebef3de8f0Aki Tuomi/* Indicate mail being expunged by autoexpunge */
6c51e3c3dc8dc5dc6fef2280b7c2c9ebef3de8f0Aki Tuomivoid mail_autoexpunge(struct mail *mail);
6c51e3c3dc8dc5dc6fef2280b7c2c9ebef3de8f0Aki Tuomi
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. */
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainenbool mail_prefetch(struct mail *mail);
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainenvoid mail_set_aborted(struct mail *mail);
910fa4e4204a73d3d24c03f3059dd24e727ca057Timo Sirainenvoid mail_set_expunged(struct mail *mail);
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);
722c012ccadcf1f63d70439a2564e77510b6dd86Aki Tuomi
4bbd396aa6198c84f3f7763b6e8a63a26e97e141Timo Sirainenvoid mailbox_set_deleted(struct mailbox *box);
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);
3c493c276f599d9b9cd10764876d648003046954Timo Sirainen
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 enum mailbox_list_path_type type);
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,
94f84d1c3f786d1b92dd2a1507f83a2dad887c56Timo Sirainen enum mailbox_list_path_type type);
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);
94f84d1c3f786d1b92dd2a1507f83a2dad887c56Timo Sirainen
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,
3c493c276f599d9b9cd10764876d648003046954Timo Sirainen int *fd_r);
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 const struct file_create_settings *lock_set,
74943466e541d8bfe3916bb0eb9fb9cb0599dfe7Timo Sirainen const struct mail_storage_settings *mail_set,
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);
b3b4f3875850099c9292ad74d08bb385c3988f8fTimo Sirainen
7a2d48763b43c4fd8bc17c444271f0b802113a5fTimo Sirainenenum mail_index_open_flags
7a2d48763b43c4fd8bc17c444271f0b802113a5fTimo Sirainenmail_storage_settings_to_index_flags(const struct mail_storage_settings *set);
897368f75a68f97e172ba76540759a10c557f1c3Timo Sirainenvoid mailbox_save_context_deinit(struct mail_save_context *ctx);
7a2d48763b43c4fd8bc17c444271f0b802113a5fTimo Sirainen
66fa646212a2c1cfd3ec45f97488b6a8ae41cdc0Aki Tuomi/* for unit testing */
66fa646212a2c1cfd3ec45f97488b6a8ae41cdc0Aki Tuomiint mailbox_verify_name(struct mailbox *box);
66fa646212a2c1cfd3ec45f97488b6a8ae41cdc0Aki Tuomi
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#endif