5363a534097c170ef9cccbdde5ca802f581f5eb7Timo Sirainen/* Log a warning when transaction log has been locked for this many seconds.
5363a534097c170ef9cccbdde5ca802f581f5eb7Timo Sirainen This lock is held also between mail_index_sync_begin()..commit(). */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Create index if it doesn't exist */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Don't try to mmap() index files */
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen /* Rely on O_EXCL when creating dotlocks */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Flush NFS attr/data/write cache when necessary */
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen /* Open the index read-only */
d371507847d62ba311b4bcc23d18f45c3d0f1a38Timo Sirainen /* Create backups of dovecot.index files once in a while */
f0569d9fbb25c8437760be69f194595a841ad711Timo Sirainen /* If we run out of disk space, fail modifications instead of moving
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen indexes to memory. */
2d3aac5be07b96f72cf0551fac35ac74a4f07770Timo Sirainen /* We're only going to save new messages to the index.
2d3aac5be07b96f72cf0551fac35ac74a4f07770Timo Sirainen Avoid unnecessary reads. */
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen /* Enable debug logging */
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen /* MAIL_INDEX_MAIL_FLAG_DIRTY can be used as a backend-specific flag.
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen All special handling of the flag is disabled by this. */
f0569d9fbb25c8437760be69f194595a841ad711Timo Sirainen /* Index file is corrupted, reopen or recreate it. */
12d34ab79772e0748a1daef30fa749dfe3036608Timo Sirainen /* Index has been fsck'd. The caller may want to resync the index
a6a2b38d806f3ab3198160e39240a8200775e525Timo Sirainen to make sure it's valid and drop this flag. */
12d34ab79772e0748a1daef30fa749dfe3036608Timo Sirainen /* For private use by backend. Replacing flags doesn't change this. */
12d34ab79772e0748a1daef30fa749dfe3036608Timo Sirainen /* Message flags haven't been written to backend. If
12d34ab79772e0748a1daef30fa749dfe3036608Timo Sirainen MAIL_INDEX_OPEN_FLAG_NO_DIRTY is set, this is treated as a
f0569d9fbb25c8437760be69f194595a841ad711Timo Sirainen backend-specific flag with no special internal handling. */
f0569d9fbb25c8437760be69f194595a841ad711Timo Sirainen /* Force updating this message's modseq via a flag update record */
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen (MAIL_ANSWERED | MAIL_FLAGGED | MAIL_DELETED | MAIL_SEEN | MAIL_DRAFT)
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen /* major version is increased only when you can't have backwards
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen compatibility. minor version is increased when header size is
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen increased to contain new non-critical fields. */
821984ecb6c90696f35c32a8dc4c8a60f9e98f99Timo Sirainen uint32_t header_size; /* base + extended header size */
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen uint8_t compat_flags; /* enum mail_index_header_compat_flags */
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen /* these UIDs may not exist and may not even be unseen/deleted */
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen /* non-external records between tail..head haven't been committed to
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen mailbox yet. */
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen /* Timestamp of when .log was rotated into .log.2. This can be used to
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen optimize checking when it's time to unlink it without stat()ing it.
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen 0 = unknown, -1 = .log.2 doesn't exists. */
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen /* daily first UIDs that have been added to index. */
821984ecb6c90696f35c32a8dc4c8a60f9e98f99Timo Sirainen#define MAIL_INDEX_RECORD_MIN_SIZE (sizeof(uint32_t) + sizeof(uint8_t))
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen uint8_t flags; /* enum mail_flags | enum mail_index_mail_flags */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen /* variable sized list of keyword indexes */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen /* If transaction is marked as hidden, the changes are marked with
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen hidden=TRUE when the view is synchronized. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen /* External transactions describe changes to mailbox that have already
5363a534097c170ef9cccbdde5ca802f581f5eb7Timo Sirainen /* Don't add flag updates unless they actually change something.
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen This is reliable only when syncing, otherwise someone else might
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen have already committed a transaction that had changed the flags. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen MAIL_INDEX_TRANSACTION_FLAG_AVOID_FLAG_UPDATES = 0x04,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen /* fsync() this transaction (unless fsyncs are disabled) */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen /* Sync transaction describes changes to mailbox that already happened
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen to another mailbox with whom we're syncing with (dsync) */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen /* Resync all dirty messages' flags. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen /* Drop recent flags from all messages */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen /* Create the transaction with AVOID_FLAG_UPDATES flag */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen MAIL_INDEX_SYNC_FLAG_AVOID_FLAG_UPDATES = 0x04,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen /* If there are no new transactions and nothing else to do,
d22301419109ed4a38351715e6760011421dadecTimo Sirainen return 0 in mail_index_sync_begin() */
5363a534097c170ef9cccbdde5ca802f581f5eb7Timo Sirainen /* Create the transaction with FSYNC flag */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen /* If we see "delete index" request transaction, finish it.
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen This flag also allows committing more changes to a deleted index. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen /* Same as MAIL_INDEX_SYNC_FLAG_DELETING_INDEX, but finish index
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen deletion only once and fail the rest (= avoid race conditions when
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen multiple processes try to mark the index deleted) */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen MAIL_INDEX_SYNC_FLAG_TRY_DELETING_INDEX = 0x40,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen /* Update header's tail_offset to head_offset, even if it's the only
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen thing we do and there's no strict need for it. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAIL_INDEX_SYNC_FLAG_UPDATE_TAIL_OFFSET = 0x80
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Don't sync expunges */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Make sure view isn't inconsistent after syncing. This also means
7f773564b94e6054a40d3785cb63c29f1e4d4deeTimo Sirainen that you don't care about view_sync_next()'s output, so it won't
7f773564b94e6054a40d3785cb63c29f1e4d4deeTimo Sirainen return anything. */
7f773564b94e6054a40d3785cb63c29f1e4d4deeTimo Sirainen MAIL_INDEX_VIEW_SYNC_FLAG_FIX_INCONSISTENT = 0x02
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen /* MAIL_INDEX_SYNC_TYPE_FLAGS: */
2054222e84cb972842cc4de88e16516bef41b542Timo Sirainen /* MAIL_INDEX_SYNC_TYPE_KEYWORD_ADD, .._REMOVE: */
84e1634acc701d14e358e27f1beff5ad74f5004aTimo Sirainen /* MAIL_INDEX_SYNC_TYPE_EXPUNGE: */
58eb2cb24dbeadd94500670acad7ceb1c8b0d9b4Timo Sirainen /* Flags or keywords changed */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* TRUE if this was a hidden transaction. */
84e1634acc701d14e358e27f1beff5ad74f5004aTimo Sirainen MAIL_INDEX_TRANSACTION_CHANGE_APPEND = BIT(0),
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAIL_INDEX_TRANSACTION_CHANGE_EXPUNGE = BIT(1),
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAIL_INDEX_TRANSACTION_CHANGE_KEYWORDS = BIT(3),
d371507847d62ba311b4bcc23d18f45c3d0f1a38Timo Sirainen MAIL_INDEX_TRANSACTION_CHANGE_MODSEQ = BIT(4),
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAIL_INDEX_TRANSACTION_CHANGE_ATTRIBUTE = BIT(5),
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MAIL_INDEX_TRANSACTION_CHANGE_OTHERS = BIT(30),
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* seq/offset points to end of transaction */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* number of bytes in the written transaction.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen all of it was written to the same file. */
84e1634acc701d14e358e27f1beff5ad74f5004aTimo Sirainen enum mail_index_transaction_change changes_mask;
d371507847d62ba311b4bcc23d18f45c3d0f1a38Timo Sirainen /* Rewrite the index when the number of bytes that needs to be read
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen from the .log on refresh is between these min/max values. */
08b30498acefc69e223baf7eda6429be98cc3a10Timo Sirainen /* Rotate transaction log after it's a) min_size or larger and it was
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen created at least min_age_secs or b) larger than max_size. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Delete .log.2 when it's older than log2_stale_secs. Don't be too
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen eager, because older files are useful for QRESYNC and dsync. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct mail_index_cache_optimization_settings {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Drop fields that haven't been accessed for n seconds */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* If cache record becomes larger than this, don't add it. */
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen /* Never compress the file if it's smaller than this */
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen /* Compress the file when n% of records are deleted */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Compress the file when n% of rows contain continued rows.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen For example 200% means that the record has 2 continued rows, i.e.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen it exists in 3 separate segments in the cache file. */
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen /* Compress the file when we need to follow more than n next_offsets to
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen find the latest cache header. */
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen struct mail_index_base_optimization_settings index;
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen struct mail_index_log_optimization_settings log;
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen struct mail_index_cache_optimization_settings cache;
92139717fd109c34692670df54d157d8c4df9b71Timo Sirainenstruct mail_index *mail_index_alloc(struct event *parent_event,
92139717fd109c34692670df54d157d8c4df9b71Timo Sirainenvoid mail_index_free(struct mail_index **index);
92139717fd109c34692670df54d157d8c4df9b71Timo Sirainen/* Change .cache file's directory. */
92139717fd109c34692670df54d157d8c4df9b71Timo Sirainenvoid mail_index_set_cache_dir(struct mail_index *index, const char *dir);
92139717fd109c34692670df54d157d8c4df9b71Timo Sirainen/* Specify how often to do fsyncs. If mode is FSYNC_MODE_OPTIMIZED, the mask
92139717fd109c34692670df54d157d8c4df9b71Timo Sirainen can be used to specify which transaction types to fsync. */
92139717fd109c34692670df54d157d8c4df9b71Timo Sirainenvoid mail_index_set_fsync_mode(struct mail_index *index, enum fsync_mode mode,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* Try to set the index's permissions based on its index directory. Returns
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen TRUE if successful (directory existed), FALSE if mail_index_set_permissions()
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen should be called. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenbool mail_index_use_existing_permissions(struct mail_index *index);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenvoid mail_index_set_permissions(struct mail_index *index,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen mode_t mode, gid_t gid, const char *gid_origin);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* Set locking method and maximum time to wait for a lock
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen (UINT_MAX = default). */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenvoid mail_index_set_lock_method(struct mail_index *index,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* Override the default optimization-related settings. Anything set to 0 will
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen use the default. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenvoid mail_index_set_optimization_settings(struct mail_index *index,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen const struct mail_index_optimization_settings *set);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* When creating a new index file or reseting an existing one, add the given
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen extension header data immediately to it. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenvoid mail_index_set_ext_init_data(struct mail_index *index, uint32_t ext_id,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* Open index. Returns 1 if ok, 0 if index doesn't exist and CREATE flags
1cd97699af9c77d8f5920832ec3374884544fd68Timo Sirainen wasn't given, -1 if error. */
1cd97699af9c77d8f5920832ec3374884544fd68Timo Sirainenint mail_index_open(struct mail_index *index, enum mail_index_open_flags flags);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* Open or create index. Returns 0 if ok, -1 if error. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenint mail_index_open_or_create(struct mail_index *index,
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainenvoid mail_index_close(struct mail_index *index);
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen/* unlink() all the index files. */
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainenint mail_index_unlink(struct mail_index *index);
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen/* Returns TRUE if index is currently in memory. */
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainenbool mail_index_is_in_memory(struct mail_index *index);
84e1634acc701d14e358e27f1beff5ad74f5004aTimo Sirainen/* Move the index into memory. Returns 0 if ok, -1 if error occurred. */
84e1634acc701d14e358e27f1beff5ad74f5004aTimo Sirainenint mail_index_move_to_memory(struct mail_index *index);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenstruct mail_cache *mail_index_get_cache(struct mail_index *index);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* Refresh index so mail_index_lookup*() will return latest values. Note that
84e1634acc701d14e358e27f1beff5ad74f5004aTimo Sirainen immediately after this call there may already be changes, so if you need to
84e1634acc701d14e358e27f1beff5ad74f5004aTimo Sirainen rely on validity of the returned values, use some external locking for it. */
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen/* View can be used to look into index. Sequence numbers inside view change
84e1634acc701d14e358e27f1beff5ad74f5004aTimo Sirainen only when you synchronize it. The view acquires required locks
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen automatically, but you'll have to drop them manually. */
bf301a34ffbfd049be583094019b2644884b6d0bTimo Sirainen const char *source_filename, unsigned int source_linenum);
58eb2cb24dbeadd94500670acad7ceb1c8b0d9b4Timo Sirainen mail_index_view_open(index, __FILE__, __LINE__)
bf301a34ffbfd049be583094019b2644884b6d0bTimo Sirainenvoid mail_index_view_close(struct mail_index_view **view);
2054222e84cb972842cc4de88e16516bef41b542Timo Sirainen/* Returns the index for given view. */
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainenstruct mail_index *mail_index_view_get_index(struct mail_index_view *view);
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen/* Returns number of mails in view. */
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainenuint32_t mail_index_view_get_messages_count(struct mail_index_view *view);
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen/* Returns TRUE if we lost track of changes for some reason. */
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainenbool mail_index_view_is_inconsistent(struct mail_index_view *view);
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen/* Returns number of transactions open for the view. */
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainenmail_index_view_get_transaction_count(struct mail_index_view *view);
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen/* Transaction has to be opened to be able to modify index. You can have
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen multiple transactions open simultaneously. Committed transactions won't
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen show up until you've synchronized the view. Expunges won't show up until
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen you've synchronized the mailbox (mail_index_sync_begin). */
a60c1c1fca85402e6fccbf3ae0784b7179ae186cTimo Sirainenmail_index_transaction_begin(struct mail_index_view *view,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_transaction_commit(struct mail_index_transaction **t);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_transaction_commit_full(struct mail_index_transaction **t,
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen struct mail_index_transaction_commit_result *result_r);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_index_transaction_rollback(struct mail_index_transaction **t);
1e76a5b92f9d82d557f81f080f3dfad1c9d8f200Timo Sirainen/* Discard all changes in the transaction. */
7a6b45405fb1544ac476e6eb1402a70cc1ddcdcfTimo Sirainenvoid mail_index_transaction_reset(struct mail_index_transaction *t);
ced118ac5caf6fe83d34339c2c65c63b2aa768acTimo Sirainen/* When committing transaction, drop flag/keyword updates for messages whose
d0d7fcf3ce44f26fdf34c1542a25cec644c5c4c7Timo Sirainen mdoseq is larger than max_modseq. Save those messages' sequences to the
08fa343b3aace9343da3195686c65c5326eda207Timo Sirainen given array. */
1cd97699af9c77d8f5920832ec3374884544fd68Timo Sirainenvoid mail_index_transaction_set_max_modseq(struct mail_index_transaction *t,
dc049c5e83d947aaf1b97c26ae819cc9577e0475Timo Sirainen/* Returns the resulting highest-modseq after this commit. This can be called
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen only if transaction log is locked, which normally means only during mail
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen index syncing. If there are any appends, they all must have been assigned
1cd97699af9c77d8f5920832ec3374884544fd68Timo Sirainen UIDs before calling this. */
33ae95df45c9b5ec51332a6b39eb5322038686b9Timo Sirainenuint64_t mail_index_transaction_get_highest_modseq(struct mail_index_transaction *t);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Returns the view transaction was created for. */
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainenmail_index_transaction_get_view(struct mail_index_transaction *t);
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen/* Returns TRUE if the given sequence is being expunged in this transaction. */
19e8adccba16ff419f5675b1575358c2956dce83Timo Sirainenbool mail_index_transaction_is_expunged(struct mail_index_transaction *t,
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen/* Returns a view containing the mailbox state after changes in transaction
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen are applied. The view can still be used after transaction has been
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen committed. */
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainenmail_index_transaction_open_updated_view(struct mail_index_transaction *t);
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen/* Begin synchronizing mailbox with index file. Returns 1 if ok,
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen 0 if MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES is set and there's nothing to
d0d7fcf3ce44f26fdf34c1542a25cec644c5c4c7Timo Sirainen sync, -1 if error.
345212e8f61ebf14ff4f80df26df9e655eb5121eTimo Sirainen mail_index_sync_next() returns all changes from previously committed
ced118ac5caf6fe83d34339c2c65c63b2aa768acTimo Sirainen transactions which haven't yet been committed to the actual mailbox.
d0d7fcf3ce44f26fdf34c1542a25cec644c5c4c7Timo Sirainen They're returned in ascending order and they never overlap (if we add more
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen sync types, then they might). You must go through all of them and update
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen the mailbox accordingly.
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen Changes done to the returned transaction are expected to describe the
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen mailbox's current state.
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen The returned view already contains all the changes (except expunge
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen requests). After applying sync records on top of backend flags they should
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen match flags in the view. If they don't, there have been external changes.
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen Returned expunges are treated as expunge requests. They're not really
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen removed from the index until you mark them expunged to the returned
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen transaction. If it's not possible to expunge the message (e.g. permission
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen denied), simply don't mark them expunged.
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen Returned sequence numbers describe the mailbox state at the beginning of
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen synchronization, ie. expunges don't affect them. */
91dca97b367c54a139c268b56a0c67f564bd9197Timo Sirainenint mail_index_sync_begin(struct mail_index *index,
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen/* Like mail_index_sync_begin(), but returns 1 if OK and if index is already
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen synchronized up to the given log_file_seq+offset, the synchronization isn't
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen started and this function returns 0. This should be done when you wish to
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen sync your committed transaction instead of doing a full mailbox
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen synchronization. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenint mail_index_sync_begin_to(struct mail_index *index,
dc52b16795b56589923ff586e5cdd0c0f1fd5931Timo Sirainen uint32_t log_file_seq, uoff_t log_file_offset,
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen/* Returns TRUE if it currently looks like syncing would return changes. */
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainenbool mail_index_sync_have_any(struct mail_index *index,
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen/* Returns TRUE if it currently looks like syncing would return expunges. */
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainenbool mail_index_sync_have_any_expunges(struct mail_index *index);
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen/* Returns the log file seq+offsets for the area which this sync is handling. */
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainenvoid mail_index_sync_get_offsets(struct mail_index_sync_ctx *ctx,
19e8adccba16ff419f5675b1575358c2956dce83Timo Sirainen/* Returns -1 if error, 0 if sync is finished, 1 if record was filled. */
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainenbool mail_index_sync_next(struct mail_index_sync_ctx *ctx,
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen/* Returns TRUE if there's more to sync. */
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);