mail-index.h revision 5fb7f20862718b2546e9d154d8924510d3f02729
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Log a warning when transaction log has been locked for this many seconds.
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen This lock is held also between mail_index_sync_begin()..commit(). */
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen /* Create index if it doesn't exist */
fcfb528483369975066c6adf1c55c16e6fb6e91fTimo Sirainen /* Don't try to mmap() index files */
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen /* Rely on O_EXCL when creating dotlocks */
fcfb528483369975066c6adf1c55c16e6fb6e91fTimo Sirainen /* Flush NFS attr/data/write cache when necessary */
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen /* Open the index read-only */
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen /* Create backups of dovecot.index files once in a while */
fcfb528483369975066c6adf1c55c16e6fb6e91fTimo Sirainen /* If we run out of disk space, fail modifications instead of moving
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen indexes to memory. */
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen /* We're only going to save new messages to the index.
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen Avoid unnecessary reads. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Index file is corrupted, reopen or recreate it. */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* For private use by backend. Replacing flags doesn't change this. */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* Message flags haven't been written to backend */
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen /* Force updating this message's modseq via a flag update record */
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen (MAIL_ANSWERED | MAIL_FLAGGED | MAIL_DELETED | MAIL_SEEN | MAIL_DRAFT)
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen /* major version is increased only when you can't have backwards
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen compatibility. minor version is increased when header size is
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen increased to contain new non-critical fields. */
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen uint32_t header_size; /* base + extended header size */
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen uint8_t compat_flags; /* enum mail_index_header_compat_flags */
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen /* these UIDs may not exist and may not even be unseen/deleted */
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen /* non-external records between tail..head haven't been committed to
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen mailbox yet. */
785b1ca149341b70bf2cb8cc3049f1c4c1070b52Timo Sirainen /* daily first UIDs that have been added to index. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen uint8_t flags; /* enum mail_flags | enum mail_index_mail_flags */
6a8a4c9f530668cd8961b73d702856ed94f05f80Timo Sirainen unsigned int count;
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen /* variable sized list of keyword indexes */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen /* If transaction is marked as hidden, the changes are marked with
73a44af966c790560a72a0447f37bb35b1031a83Timo Sirainen hidden=TRUE when the view is synchronized. */
73a44af966c790560a72a0447f37bb35b1031a83Timo Sirainen /* External transactions describe changes to mailbox that have already
73a44af966c790560a72a0447f37bb35b1031a83Timo Sirainen /* Don't add flag updates unless they actually change something.
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen This is reliable only when syncing, otherwise someone else might
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen have already committed a transaction that had changed the flags. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAIL_INDEX_TRANSACTION_FLAG_AVOID_FLAG_UPDATES = 0x04,
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen /* fsync() this transaction (unless fsyncs are disabled) */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen /* Sync transaction describes changes to mailbox that already happened
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen to another mailbox with whom we're syncing with (dsync) */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen /* Resync all dirty messages' flags. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen /* Drop recent flags from all messages */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen /* Create the transaction with AVOID_FLAG_UPDATES flag */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen MAIL_INDEX_SYNC_FLAG_AVOID_FLAG_UPDATES = 0x04,
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen /* If there are no new transactions and nothing else to do,
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen return 0 in mail_index_sync_begin() */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen /* Create the transaction with FSYNC flag */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen /* If we see "delete index" request transaction, finish it.
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen This flag also allows committing more changes to a deleted index. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen /* Same as MAIL_INDEX_SYNC_FLAG_DELETING_INDEX, but finish index
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen deletion only once and fail the rest (= avoid race conditions when
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen multiple processes try to mark the index deleted) */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen MAIL_INDEX_SYNC_FLAG_TRY_DELETING_INDEX = 0x40,
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen /* Update header's tail_offset to head_offset, even if it's the only
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen thing we do and there's no strict need for it. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen MAIL_INDEX_SYNC_FLAG_UPDATE_TAIL_OFFSET = 0x80
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen /* Don't sync expunges */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen /* Make sure view isn't inconsistent after syncing. This also means
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen that you don't care about view_sync_next()'s output, so it won't
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen return anything. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen MAIL_INDEX_VIEW_SYNC_FLAG_FIX_INCONSISTENT = 0x02
58febed28f2af78b2d8a281c851d9b67160c4bd3Timo Sirainen /* MAIL_INDEX_SYNC_TYPE_FLAGS: */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen /* MAIL_INDEX_SYNC_TYPE_KEYWORD_ADD, .._REMOVE: */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen /* MAIL_INDEX_SYNC_TYPE_EXPUNGE: */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen /* Flags or keywords changed */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen /* TRUE if this was a hidden transaction. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen /* seq/offset points to end of transaction */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen /* number of bytes in the written transaction.
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen all of it was written to the same file. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenstruct mail_index *mail_index_alloc(const char *dir, const char *prefix);
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenvoid mail_index_free(struct mail_index **index);
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen/* Specify how often to do fsyncs. If mode is FSYNC_MODE_OPTIMIZED, the mask
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen can be used to specify which transaction types to fsync. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenvoid mail_index_set_fsync_mode(struct mail_index *index, enum fsync_mode mode,
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenvoid mail_index_set_permissions(struct mail_index *index,
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen mode_t mode, gid_t gid, const char *gid_origin);
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen/* Set locking method and maximum time to wait for a lock
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen (UINT_MAX = default). */
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainenvoid mail_index_set_lock_method(struct mail_index *index,
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen/* When creating a new index file or reseting an existing one, add the given
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen extension header data immediately to it. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenvoid mail_index_set_ext_init_data(struct mail_index *index, uint32_t ext_id,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Open index. Returns 1 if ok, 0 if index doesn't exist and CREATE flags
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen wasn't given, -1 if error. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenint mail_index_open(struct mail_index *index, enum mail_index_open_flags flags);
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen/* Open or create index. Returns 0 if ok, -1 if error. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenint mail_index_open_or_create(struct mail_index *index,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenvoid mail_index_close(struct mail_index *index);
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen/* unlink() all the index files. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenint mail_index_unlink(struct mail_index *index);
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen/* Returns TRUE if index is currently in memory. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenbool mail_index_is_in_memory(struct mail_index *index);
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen/* Move the index into memory. Returns 0 if ok, -1 if error occurred. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenint mail_index_move_to_memory(struct mail_index *index);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct mail_cache *mail_index_get_cache(struct mail_index *index);
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen/* Refresh index so mail_index_lookup*() will return latest values. Note that
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen immediately after this call there may already be changes, so if you need to
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen rely on validity of the returned values, use some external locking for it. */
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen/* View can be used to look into index. Sequence numbers inside view change
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen only when you synchronize it. The view acquires required locks
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen automatically, but you'll have to drop them manually. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenstruct mail_index_view *mail_index_view_open(struct mail_index *index);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_index_view_close(struct mail_index_view **view);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Returns the index for given view. */
6a8a4c9f530668cd8961b73d702856ed94f05f80Timo Sirainenstruct mail_index *mail_index_view_get_index(struct mail_index_view *view);
6a8a4c9f530668cd8961b73d702856ed94f05f80Timo Sirainen/* Returns number of mails in view. */
6a8a4c9f530668cd8961b73d702856ed94f05f80Timo Sirainenuint32_t mail_index_view_get_messages_count(struct mail_index_view *view);
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen/* Returns TRUE if we lost track of changes for some reason. */
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainenbool mail_index_view_is_inconsistent(struct mail_index_view *view);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Returns number of transactions open for the view. */
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainenmail_index_view_get_transaction_count(struct mail_index_view *view);
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen/* Transaction has to be opened to be able to modify index. You can have
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen multiple transactions open simultaneously. Committed transactions won't
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen show up until you've synchronized the view. Expunges won't show up until
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen you've synchronized the mailbox (mail_index_sync_begin). */
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainenmail_index_transaction_begin(struct mail_index_view *view,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_transaction_commit(struct mail_index_transaction **t);
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainenint mail_index_transaction_commit_full(struct mail_index_transaction **t,
710deabc6b3c305c3a842e7a2e0d173c526d13a7Timo Sirainen struct mail_index_transaction_commit_result *result_r);
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainenvoid mail_index_transaction_rollback(struct mail_index_transaction **t);
710deabc6b3c305c3a842e7a2e0d173c526d13a7Timo Sirainen/* Discard all changes in the transaction. */
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainenvoid mail_index_transaction_reset(struct mail_index_transaction *t);
710deabc6b3c305c3a842e7a2e0d173c526d13a7Timo Sirainen/* When committing transaction, drop flag/keyword updates for messages whose
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen mdoseq is larger than max_modseq. Save those messages' sequences to the
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen given array. */
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainenvoid mail_index_transaction_set_max_modseq(struct mail_index_transaction *t,
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen/* Returns the view transaction was created for. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenmail_index_transaction_get_view(struct mail_index_transaction *t);
dd4b5f14b71b01a84af942e720a2d6e5f15ee1a7Timo Sirainen/* Returns TRUE if the given sequence is being expunged in this transaction. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenbool mail_index_transaction_is_expunged(struct mail_index_transaction *t,
dd4b5f14b71b01a84af942e720a2d6e5f15ee1a7Timo Sirainen/* Returns a view containing the mailbox state after changes in transaction
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen are applied. The view can still be used after transaction has been
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen committed. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenmail_index_transaction_open_updated_view(struct mail_index_transaction *t);
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen/* Begin synchronizing mailbox with index file. Returns 1 if ok,
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen 0 if MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set and there's nothing to
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen sync, -1 if error.
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen mail_index_sync_next() returns all changes from previously committed
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen transactions which haven't yet been committed to the actual mailbox.
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen They're returned in ascending order and they never overlap (if we add more
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen sync types, then they might). You must go through all of them and update
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen the mailbox accordingly.
dd4b5f14b71b01a84af942e720a2d6e5f15ee1a7Timo Sirainen Changes done to the returned transaction are expected to describe the
dd4b5f14b71b01a84af942e720a2d6e5f15ee1a7Timo Sirainen mailbox's current state.
710deabc6b3c305c3a842e7a2e0d173c526d13a7Timo Sirainen The returned view already contains all the changes (except expunge
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen requests). After applying sync records on top of backend flags they should
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen match flags in the view. If they don't, there have been external changes.
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen Returned expunges are treated as expunge requests. They're not really
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen removed from the index until you mark them expunged to the returned
8aacc9e7c84f8376822823ec98c2f551d4919b2eTimo Sirainen transaction. If it's not possible to expunge the message (e.g. permission
710deabc6b3c305c3a842e7a2e0d173c526d13a7Timo Sirainen denied), simply don't mark them expunged.
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen Returned sequence numbers describe the mailbox state at the beginning of
710deabc6b3c305c3a842e7a2e0d173c526d13a7Timo Sirainen synchronization, ie. expunges don't affect them. */
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainenint mail_index_sync_begin(struct mail_index *index,
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen/* Like mail_index_sync_begin(), but returns 1 if OK and if index is already
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen synchronized up to the given log_file_seq+offset, the synchronization isn't
dd4b5f14b71b01a84af942e720a2d6e5f15ee1a7Timo Sirainen started and this function returns 0. This should be done when you wish to
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen sync your committed transaction instead of doing a full mailbox
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen synchronization. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenint mail_index_sync_begin_to(struct mail_index *index,
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen uint32_t log_file_seq, uoff_t log_file_offset,
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen/* Returns TRUE if it currently looks like syncing would return changes. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenbool mail_index_sync_have_any(struct mail_index *index,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Returns TRUE if it currently looks like syncing would return expunges. */
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainenbool mail_index_sync_have_any_expunges(struct mail_index *index);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Returns the log file seq+offsets for the area which this sync is handling. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenvoid mail_index_sync_get_offsets(struct mail_index_sync_ctx *ctx,
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen/* Returns -1 if error, 0 if sync is finished, 1 if record was filled. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenbool mail_index_sync_next(struct mail_index_sync_ctx *ctx,
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen/* Returns TRUE if there's more to sync. */
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainenbool mail_index_sync_have_more(struct mail_index_sync_ctx *ctx);
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen/* Returns TRUE if sync has any expunges to handle. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenbool mail_index_sync_has_expunges(struct mail_index_sync_ctx *ctx);
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen/* Reset syncing to initial state after mail_index_sync_begin(), so you can
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen go through all the sync records again with mail_index_sync_next(). */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenvoid mail_index_sync_reset(struct mail_index_sync_ctx *ctx);
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen/* Update result when refreshing index at the end of sync. */
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainenvoid mail_index_sync_set_commit_result(struct mail_index_sync_ctx *ctx,
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen struct mail_index_transaction_commit_result *result);
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen/* Don't log a warning even if syncing took over
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen MAIL_TRANSACTION_LOG_LOCK_WARN_SECS seconds. Usually this is called because
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen the caller itself already logged a warning about it. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenvoid mail_index_sync_no_warning(struct mail_index_sync_ctx *ctx);
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen/* Commit synchronization by writing all changes to mail index file. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenint mail_index_sync_commit(struct mail_index_sync_ctx **ctx);
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen/* Rollback synchronization - none of the changes listed by sync_next() are
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen actually written to index file. */
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainenvoid mail_index_sync_rollback(struct mail_index_sync_ctx **ctx);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Mark index file corrupted. Invalidates all views. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenvoid mail_index_mark_corrupted(struct mail_index *index);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Check and fix any found problems. Returns -1 if we couldn't lock for sync,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen 0 if everything went ok. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Returns TRUE if mail_index_fsck() has been called since the last
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen mail_index_reset_fscked() call. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenbool mail_index_reset_fscked(struct mail_index *index);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Synchronize changes in view. You have to go through all records, or view
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen will be marked inconsistent. Only sync_mask type records are
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen synchronized. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenmail_index_view_sync_begin(struct mail_index_view *view,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenbool mail_index_view_sync_next(struct mail_index_view_sync_ctx *ctx,
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainenmail_index_view_sync_get_expunges(struct mail_index_view_sync_ctx *ctx,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_view_sync_commit(struct mail_index_view_sync_ctx **ctx,
da5d50534cfca45d0aaaf0bdac17b287b4588809Timo Sirainen/* Returns the index header. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenmail_index_get_header(struct mail_index_view *view);
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen/* Returns the wanted message record. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenmail_index_lookup(struct mail_index_view *view, uint32_t seq);
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenmail_index_lookup_full(struct mail_index_view *view, uint32_t seq,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Returns TRUE if the given message has already been expunged from index. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenbool mail_index_is_expunged(struct mail_index_view *view, uint32_t seq);
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen/* Note that returned keyword indexes aren't sorted. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenvoid mail_index_lookup_keywords(struct mail_index_view *view, uint32_t seq,
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen/* Return keywords from given map. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenvoid mail_index_map_lookup_keywords(struct mail_index_map *map, uint32_t seq,
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen/* mail_index_lookup[_keywords]() returns the latest flag changes.
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen This function instead attempts to return the flags and keywords done by the
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen last view sync. */
65a5fb2343f9870713bfca0b24abb58dcade605eTimo Sirainenvoid mail_index_lookup_view_flags(struct mail_index_view *view, uint32_t seq,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Returns the UID for given message. May be slightly faster than
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen mail_index_lookup()->uid. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenvoid mail_index_lookup_uid(struct mail_index_view *view, uint32_t seq,
2a21435425c50514fa4d0708110a4ed7f0d85661Timo Sirainen/* Convert UID range to sequence range. If no UIDs are found, returns FALSE and
2a21435425c50514fa4d0708110a4ed7f0d85661Timo Sirainen sequences are set to 0. Note that any of the returned sequences may have
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen been expunged already. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenbool mail_index_lookup_seq_range(struct mail_index_view *view,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenbool mail_index_lookup_seq(struct mail_index_view *view,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Find first mail with (mail->flags & flags_mask) == flags. Useful mostly for
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen taking advantage of lowwater-fields in headers. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenvoid mail_index_lookup_first(struct mail_index_view *view,
65a5fb2343f9870713bfca0b24abb58dcade605eTimo Sirainen/* Append a new record to index. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenvoid mail_index_append(struct mail_index_transaction *t, uint32_t uid,
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen/* Assign UIDs for mails with uid=0 or uid<first_uid. All the assigned UIDs
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen are higher than the highest unassigned UID (i.e. it doesn't try to fill UID
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen gaps). Assumes that mailbox is locked in a way that UIDs can be safely
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen assigned. Returns UIDs for all asigned messages, in their sequence order
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen (so UIDs are not necessary ascending). */
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainenvoid mail_index_append_finish_uids(struct mail_index_transaction *t,
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen/* Expunge record from index. Note that this doesn't affect sequence numbers
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen until transaction is committed and mailbox is synced. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenvoid mail_index_expunge(struct mail_index_transaction *t, uint32_t seq);
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen/* Like mail_index_expunge(), but also write message GUID to transaction log. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenvoid mail_index_expunge_guid(struct mail_index_transaction *t, uint32_t seq,
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen/* Update flags in index. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenvoid mail_index_update_flags(struct mail_index_transaction *t, uint32_t seq,
84004c37192dc91a8dcc9f213ca2cfa22b4f40e4Timo Sirainenvoid mail_index_update_flags_range(struct mail_index_transaction *t,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Specified attribute's value was changed. This is just a notification so the
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen change gets assigned its own modseq and any log readers can find out about
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainen this change. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenvoid mail_index_attribute_set(struct mail_index_transaction *t,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Attribute was deleted. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenvoid mail_index_attribute_unset(struct mail_index_transaction *t,
b1f58fea9e1813b48735a021043f1cea2b495c3bTimo Sirainen/* Update message's modseq to be at least min_modseq. */
6b85bc4b03e552cfaeeae872d63c2d8ac5fcb7c4Timo Sirainenvoid mail_index_update_modseq(struct mail_index_transaction *t, uint32_t seq,
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen/* Update highest modseq to be at least min_modseq. */
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainenvoid mail_index_update_highest_modseq(struct mail_index_transaction *t,
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen/* Reset the index before committing this transaction. This is usually done
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen only when UIDVALIDITY changes. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenvoid mail_index_reset(struct mail_index_transaction *t);
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen/* Mark index deleted. No further changes will be possible after the
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen transaction has been committed. */
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainenvoid mail_index_set_deleted(struct mail_index_transaction *t);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Mark a deleted index as undeleted. Afterwards index can be changed again. */
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainenvoid mail_index_set_undeleted(struct mail_index_transaction *t);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Returns TRUE if index has been set deleted. This gets set only after
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen index has been opened/refreshed and the transaction has been seen. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenbool mail_index_is_deleted(struct mail_index *index);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Returns the last time mailbox was modified. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenint mail_index_get_modification_time(struct mail_index *index, time_t *mtime_r);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Lookup a keyword, returns TRUE if found, FALSE if not. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenbool mail_index_keyword_lookup(struct mail_index *index,
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainenvoid mail_index_keyword_lookup_or_create(struct mail_index *index,
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen unsigned int *idx_r);
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen/* Return a pointer to array of NULL-terminated list of keywords. Note that
1b97a59edb073e9a89ac43a21a9abe5d590d4a56Timo Sirainen the array contents (and thus pointers inside it) may change after calling
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen mail_index_keywords_create() or mail_index_sync_begin(). */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenconst ARRAY_TYPE(keywords) *mail_index_get_keywords(struct mail_index *index);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen/* Create a keyword list structure. */
struct mail_keywords *
bool prepend);
bool *expunged_r);