mail-index.h revision 5bced341c27719fe5ec48e1cd079843f33c6d4b5
550d2fe097e95f12e8fa60ef52753ea7fe53d4eaTimo Sirainen/* Log a warning when transaction log has been locked for this many seconds.
dff32d11a411a24f3b76003c1ae22c5a960f180eTimo Sirainen This lock is held also between mail_index_sync_begin()..commit(). */
eb209d12e3b1cfed564c35cf19fdb1bf7fcc6811Timo Sirainen /* Create index if it doesn't exist */
09060303d565e15d54e42b4ef722f9d3c26f5336Timo Sirainen /* Don't try to mmap() index files */
a5ddfd7a8b473f73135b93d5e081e470a87f0f7eTimo Sirainen /* Rely on O_EXCL when creating dotlocks */
ae32667c54480d329eed994b3defab89cd76c077Timo Sirainen /* Flush NFS attr/data/write cache when necessary */
bfef6891565ff9018ac92add6eae401e9352c657Timo Sirainen /* Open the index read-only */
8c2b4a45f17a5cb13bb01058ca37798cf48d91baTimo Sirainen /* Create backups of dovecot.index files once in a while */
8c2b4a45f17a5cb13bb01058ca37798cf48d91baTimo Sirainen /* If we run out of disk space, fail modifications instead of moving
8c2b4a45f17a5cb13bb01058ca37798cf48d91baTimo Sirainen indexes to memory. */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* We're only going to save new messages to the index.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen Avoid unnecessary reads. */
c13fce16374a6fa8d127742c527498d38e777789Timo Sirainen /* Index file is corrupted, reopen or recreate it. */
c13fce16374a6fa8d127742c527498d38e777789Timo Sirainen /* For private use by backend. Replacing flags doesn't change this. */
c13fce16374a6fa8d127742c527498d38e777789Timo Sirainen /* Message flags haven't been written to backend */
c13fce16374a6fa8d127742c527498d38e777789Timo Sirainen /* Force updating this message's modseq via a flag update record */
c13fce16374a6fa8d127742c527498d38e777789Timo Sirainen (MAIL_ANSWERED | MAIL_FLAGGED | MAIL_DELETED | MAIL_SEEN | MAIL_DRAFT)
c13fce16374a6fa8d127742c527498d38e777789Timo Sirainen /* major version is increased only when you can't have backwards
c13fce16374a6fa8d127742c527498d38e777789Timo Sirainen compatibility. minor version is increased when header size is
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen increased to contain new non-critical fields. */
1b7cd57585d8c2f133dd612d2d5d9c775595659fTimo Sirainen uint32_t header_size; /* base + extended header size */
1b7cd57585d8c2f133dd612d2d5d9c775595659fTimo Sirainen uint8_t compat_flags; /* enum mail_index_header_compat_flags */
1b7cd57585d8c2f133dd612d2d5d9c775595659fTimo Sirainen /* these UIDs may not exist and may not even be unseen/deleted */
1b7cd57585d8c2f133dd612d2d5d9c775595659fTimo Sirainen /* non-external records between tail..head haven't been committed to
1b7cd57585d8c2f133dd612d2d5d9c775595659fTimo Sirainen mailbox yet. */
009217abb57a24a4076092e8e4e165545747839eStephan Bosch /* daily first UIDs that have been added to index. */
5f5713d6468dca1acf3d350dd8a33057331f78c5Timo Sirainen uint8_t flags; /* enum mail_flags | enum mail_index_mail_flags */
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen unsigned int count;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* variable sized list of keyword indexes */
edd318d5866ac3fbc6e8df28fb24a4dfef93c884Timo Sirainen /* If transaction is marked as hidden, the changes are marked with
d3bae1f9d2448e5c398145ea250849ec12583845Timo Sirainen hidden=TRUE when the view is synchronized. */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* External transactions describe changes to mailbox that have already
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* Don't add flag updates unless they actually change something.
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen This is reliable only when syncing, otherwise someone else might
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen have already committed a transaction that had changed the flags. */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen MAIL_INDEX_TRANSACTION_FLAG_AVOID_FLAG_UPDATES = 0x04,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* fsync() this transaction (unless fsyncs are disabled) */
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen /* Sync transaction describes changes to mailbox that already happened
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainen to another mailbox with whom we're syncing with (dsync) */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen /* Resync all dirty messages' flags. */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen /* Drop recent flags from all messages */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* Create the transaction with AVOID_FLAG_UPDATES flag */
1df39b899804fd1dbc560f75382364822935c857Timo Sirainen MAIL_INDEX_SYNC_FLAG_AVOID_FLAG_UPDATES = 0x04,
1df39b899804fd1dbc560f75382364822935c857Timo Sirainen /* If there are no new transactions and nothing else to do,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return 0 in mail_index_sync_begin() */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* Create the transaction with FSYNC flag */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* If we see "delete index" request transaction, finish it.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen This flag also allows committing more changes to a deleted index. */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* Same as MAIL_INDEX_SYNC_FLAG_DELETING_INDEX, but finish index
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen deletion only once and fail the rest (= avoid race conditions when
c4900d31385344bfadaee53a897daeafdb3063d8Timo Sirainen multiple processes try to mark the index deleted) */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen MAIL_INDEX_SYNC_FLAG_TRY_DELETING_INDEX = 0x40,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* Update header's tail_offset to head_offset, even if it's the only
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen thing we do and there's no strict need for it. */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen MAIL_INDEX_SYNC_FLAG_UPDATE_TAIL_OFFSET = 0x80
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* Don't sync expunges */
468c28dfb03613ab8d487b5aebc985a969193aceTimo Sirainen /* Make sure view isn't inconsistent after syncing. This also means
abe29107f5dce932d28a00912d2d75a01021bef1Timo Sirainen that you don't care about view_sync_next()'s output, so it won't
433f5c9cc560a8cbff47257513d0bacb1cf250f4Timo Sirainen return anything. */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen MAIL_INDEX_VIEW_SYNC_FLAG_FIX_INCONSISTENT = 0x02
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen /* MAIL_INDEX_SYNC_TYPE_FLAGS: */
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen /* MAIL_INDEX_SYNC_TYPE_KEYWORD_ADD, .._REMOVE: */
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen /* MAIL_INDEX_SYNC_TYPE_EXPUNGE: */
ab779efe68458cf6fdcaa4f99527685d5563df0aTimo Sirainen /* Flags or keywords changed */
550d2fe097e95f12e8fa60ef52753ea7fe53d4eaTimo Sirainen /* TRUE if this was a hidden transaction. */
36e091dc733c6cd690c5aae6e411e41adb1eca73Timo Sirainen /* seq/offset points to end of transaction */
36e091dc733c6cd690c5aae6e411e41adb1eca73Timo Sirainen /* number of bytes in the written transaction.
36e091dc733c6cd690c5aae6e411e41adb1eca73Timo Sirainen all of it was written to the same file. */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstruct mail_index *mail_index_alloc(const char *dir, const char *prefix);
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainenvoid mail_index_free(struct mail_index **index);
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainen/* Specify how often to do fsyncs. If mode is FSYNC_MODE_OPTIMIZED, the mask
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainen can be used to specify which transaction types to fsync. */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenvoid mail_index_set_fsync_mode(struct mail_index *index, enum fsync_mode mode,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenvoid mail_index_set_permissions(struct mail_index *index,
de92873c366becfaea1554642f89b9169d7955e2Timo Sirainen mode_t mode, gid_t gid, const char *gid_origin);
de92873c366becfaea1554642f89b9169d7955e2Timo Sirainen/* Set locking method and maximum time to wait for a lock
de92873c366becfaea1554642f89b9169d7955e2Timo Sirainen (UINT_MAX = default). */
de92873c366becfaea1554642f89b9169d7955e2Timo Sirainenvoid mail_index_set_lock_method(struct mail_index *index,
c3a2a487e23a282e59254b82deb9344ed0306bb2Timo Sirainen/* When creating a new index file or reseting an existing one, add the given
1df39b899804fd1dbc560f75382364822935c857Timo Sirainen extension header data immediately to it. */
1df39b899804fd1dbc560f75382364822935c857Timo Sirainenvoid mail_index_set_ext_init_data(struct mail_index *index, uint32_t ext_id,
1f7f4294207557edf83171642ef62ce4922ffc9dTimo Sirainen/* Open index. Returns 1 if ok, 0 if index doesn't exist and CREATE flags
1f7f4294207557edf83171642ef62ce4922ffc9dTimo Sirainen wasn't given, -1 if error. */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenint mail_index_open(struct mail_index *index, enum mail_index_open_flags flags);
struct mail_index_transaction *
struct mail_index_view *
struct mail_index_view *
const char *reason);
struct mail_index_view_sync_ctx *
bool *delayed_expunges_r);
const struct mail_index_header *
const struct mail_index_record *
const struct mail_index_record *
const char *keyword,
unsigned int *idx_r);
struct mail_keywords *
struct mail_keywords *
bool prepend);
bool *expunged_r);