mail-index.h revision 2674b4f0cf8f3c203d8e56b29735f5e267038daf
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Create index if it doesn't exist */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Don't try to mmap() index files */
8887bf3757d51d73887dd20b1db3334d867d3817Timo Sirainen /* Rely on O_EXCL when creating dotlocks */
369a1084c500a9df7448ffa9409ce32e42060bc2Timo Sirainen /* Don't fsync() or fdatasync() */
b7b81543899e306c71e6152516d8698416162bcbTimo Sirainen /* Index file is corrupted, reopen or recreate it. */
e12648867876aaec17e06ee4caef0bb60363449dTimo Sirainen /* fsck the index next time when opening */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen (MAIL_ANSWERED | MAIL_FLAGGED | MAIL_DELETED | MAIL_SEEN | MAIL_DRAFT)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* major version is increased only when you can't have backwards
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen compatibility. minor version is increased when header size is
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen increased to contain new non-critical fields. */
024815ea2ffdda9ea79919f18e865663977f73eaTimo Sirainen uint32_t header_size; /* base + extended header size */
811f2e26d9782d9cb99fdf82e18ffa0a77564fe2Timo Sirainen uint8_t compat_flags; /* enum mail_index_header_compat_flags */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* these UIDs may not exist and may not even be unseen */
2a734f36105e33ab452d057df6bc7a2b7d9f96f0Timo Sirainen /* We have internal and external sync offsets. External changes are
2a734f36105e33ab452d057df6bc7a2b7d9f96f0Timo Sirainen synced into index somewhat more often, so int_offset <= ext_offset */
8aacc9e7c84f8376822823ec98c2f551d4919b2eTimo Sirainen /* daily first UIDs that have been added to index. */
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen uint8_t flags; /* enum mail_flags | enum mail_index_mail_flags */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen unsigned int count;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen /* variable sized list of keyword indexes */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* MAIL_INDEX_SYNC_TYPE_FLAGS: */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen /* MAIL_INDEX_SYNC_TYPE_KEYWORD_ADD, .._REMOVE: */
020a39a395d2adb768e0179631b37bc78ecd9471Timo Sirainen /* keyword appends and removes are packed into one and same
020a39a395d2adb768e0179631b37bc78ecd9471Timo Sirainen MAIL_INDEX_SYNC_TYPE_KEYWORD_ADD */
8d80659e504ffb34bb0c6a633184fece35751b18Timo SirainenARRAY_DEFINE_TYPE(keyword_indexes, unsigned int);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct mail_index *mail_index_alloc(const char *dir, const char *prefix);
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainenvoid mail_index_free(struct mail_index **index);
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainenvoid mail_index_set_permissions(struct mail_index *index,
a53cb86b4d733d9c48ee4d285bed477c80825804Timo Sirainenint mail_index_open(struct mail_index *index, enum mail_index_open_flags flags,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_index_close(struct mail_index *index);
a045c3aba2610c6ed0bf1c346df1c6d8f7b9fbfdTimo Sirainen/* Move the index into memory. Returns 0 if ok, -1 if error occurred. */
a045c3aba2610c6ed0bf1c346df1c6d8f7b9fbfdTimo Sirainenint mail_index_move_to_memory(struct mail_index *index);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct mail_cache *mail_index_get_cache(struct mail_index *index);
d30da25fb6be1f1c667d93767c9194000194b618Timo Sirainen/* Refresh index so mail_index_lookup*() will return latest values. Note that
d30da25fb6be1f1c667d93767c9194000194b618Timo Sirainen immediately after this call there may already be changes, so if you need to
d30da25fb6be1f1c667d93767c9194000194b618Timo Sirainen rely on validity of the returned values, use some external locking for it. */
d30da25fb6be1f1c667d93767c9194000194b618Timo Sirainenint mail_index_refresh(struct mail_index *index);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* View can be used to look into index. Sequence numbers inside view change
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen only when you synchronize it. The view acquires required locks
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen automatically, but you'll have to drop them manually. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct mail_index_view *mail_index_view_open(struct mail_index *index);
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainenvoid mail_index_view_close(struct mail_index_view **view);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Returns the index for given view. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct mail_index *mail_index_view_get_index(struct mail_index_view *view);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Call whenever you've done with requesting messages from view for a while. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_index_view_unlock(struct mail_index_view *view);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Returns number of mails in view. */
df4018ae2f0a95be602f724ca70df7e0e3bd6a7dTimo Sirainenuint32_t mail_index_view_get_messages_count(struct mail_index_view *view);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Returns TRUE if we lost track of changes for some reason. */
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainenbool mail_index_view_is_inconsistent(struct mail_index_view *view);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Transaction has to be opened to be able to modify index. You can have
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen multiple transactions open simultaneously. Note that committed transactions
8afec4d1a32b78f540257a27769b372aad753384Timo Sirainen won't show up until you've synchronized mailbox (mail_index_sync_begin).
8afec4d1a32b78f540257a27769b372aad753384Timo Sirainen If transaction is marked as hidden, the changes won't be listed when the
8afec4d1a32b78f540257a27769b372aad753384Timo Sirainen view is synchronized. Expunges can't be hidden.
8afec4d1a32b78f540257a27769b372aad753384Timo Sirainen External transactions describe changes to mailbox that have already
7c95b03620a03a43dd72d39608cea5fc77393ad6Timo Sirainenmail_index_transaction_begin(struct mail_index_view *view,
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainenint mail_index_transaction_commit(struct mail_index_transaction **t,
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainenvoid mail_index_transaction_rollback(struct mail_index_transaction **t);
eac3948d67eff8623d51aeaea9eca582f3aec677Timo Sirainen/* Discard all changes in the transaction. */
2674b4f0cf8f3c203d8e56b29735f5e267038dafTimo Sirainenvoid mail_index_transaction_reset(struct mail_index_transaction *t);
48136ae5a0eb49daa44e343553f3688a500307e2Timo Sirainen/* Returns the view transaction was created for. */
2674b4f0cf8f3c203d8e56b29735f5e267038dafTimo Sirainenmail_index_transaction_get_view(struct mail_index_transaction *t);
24fc71a693331ffe77e2b6d81c70aca6fa055e47Timo Sirainen/* Returns a view to transaction. Currently this differs from normal view only
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainen in that it contains newly appended messages in transaction. The view can
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainen still be used after transaction has been committed. */
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainenmail_index_transaction_open_updated_view(struct mail_index_transaction *t);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Begin synchronizing mailbox with index file. This call locks the index
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen exclusively against other modifications. Returns 1 if ok, -1 if error.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen If log_file_seq is not (uint32_t)-1 and index is already synchronized up
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen to given log_file_offset, the synchronization isn't started and this
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen function returns 0. This should be done when you wish to sync your previous
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen transaction instead of doing a full mailbox synchronization.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen mail_index_sync_next() returns all changes from previously committed
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen transactions which haven't yet been committed to the actual mailbox.
b92813e2f96d4b28f989528ed5dd6115da7d9bdbTimo Sirainen They're returned in ascending order and they never overlap (if we add more
b92813e2f96d4b28f989528ed5dd6115da7d9bdbTimo Sirainen sync types, then they might). You must go through all of them and update
b92813e2f96d4b28f989528ed5dd6115da7d9bdbTimo Sirainen the mailbox accordingly.
d9de52132072d80b8c268094b879c0ef5a108db3Timo Sirainen None of the changes actually show up in index until after successful
d9de52132072d80b8c268094b879c0ef5a108db3Timo Sirainen mail_index_sync_commit().
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen Returned sequence numbers describe the mailbox state at the beginning of
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen synchronization, ie. expunges don't affect them.
aa0647f2debf0d48d504a321186f66c85596aaf4Timo Sirainen Changes done to the returned transaction are expected to describe the
aa0647f2debf0d48d504a321186f66c85596aaf4Timo Sirainen mailbox's current state. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_sync_begin(struct mail_index *index,
88553367d677170a4b703b9d52aac9eabf91c656Timo Sirainen uint32_t log_file_seq, uoff_t log_file_offset,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Returns -1 if error, 0 if sync is finished, 1 if record was filled. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_sync_next(struct mail_index_sync_ctx *ctx,
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen/* Returns TRUE if there's more to sync. */
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainenbool mail_index_sync_have_more(struct mail_index_sync_ctx *ctx);
89caf81340a4da959ef18c5f9b9c99824a53066bTimo Sirainen/* Reset syncing to initial state after mail_index_sync_begin(), so you can
89caf81340a4da959ef18c5f9b9c99824a53066bTimo Sirainen go through all the sync records again with mail_index_sync_next(). */
89caf81340a4da959ef18c5f9b9c99824a53066bTimo Sirainenvoid mail_index_sync_reset(struct mail_index_sync_ctx *ctx);
d9de52132072d80b8c268094b879c0ef5a108db3Timo Sirainen/* Commit synchronization by writing all changes to mail index file. */
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainenint mail_index_sync_commit(struct mail_index_sync_ctx **ctx);
d9de52132072d80b8c268094b879c0ef5a108db3Timo Sirainen/* Rollback synchronization - none of the changes listed by sync_next() are
d9de52132072d80b8c268094b879c0ef5a108db3Timo Sirainen actually written to index file. */
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainenvoid mail_index_sync_rollback(struct mail_index_sync_ctx **ctx);
685393de106e55b61f754d420e378d05bd462ebbTimo Sirainen/* Mark index file corrupted. Invalidates all views. */
87712707722ef7d73acb065546e61afa4455cd9eTimo Sirainenvoid mail_index_mark_corrupted(struct mail_index *index);
b35f7104715edee0cfac6d46ab0b342033867eb7Timo Sirainen/* Check and fix any found problems. If index is broken beyond repair, it's
b35f7104715edee0cfac6d46ab0b342033867eb7Timo Sirainen marked corrupted and 0 is returned. Otherwise returns -1 if there was some
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen I/O error or 1 if everything went ok. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Synchronize changes in view. You have to go through all records, or view
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen will be marked inconsistent. Only sync_mask type records are
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen synchronized. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_view_sync_begin(struct mail_index_view *view,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Returns -1 if error, 0 if sync is finished, 1 if record was filled. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_view_sync_next(struct mail_index_view_sync_ctx *ctx,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenmail_index_view_sync_get_expunges(struct mail_index_view_sync_ctx *ctx,
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainenvoid mail_index_view_sync_end(struct mail_index_view_sync_ctx **ctx);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Returns the index header. */
b20fb5b1df9d604a7541f5118fc5b4b466d211efTimo Sirainenmail_index_get_header(struct mail_index_view *view);
b5ea11802f2bafbec06282a7b3b6704dc5fae584Timo Sirainen/* Returns the given message. Returns -1 if error, 1 if ok, 0 if mail was
b5ea11802f2bafbec06282a7b3b6704dc5fae584Timo Sirainen expunged but data was returned from some older index. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_lookup(struct mail_index_view *view, uint32_t seq,
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainenint mail_index_lookup_full(struct mail_index_view *view, uint32_t seq,
bb26f09873c18f342cd1ab2d0ee0b9018e6546d9Timo Sirainen/* Note that returned keyword indexes aren't sorted. */
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenint mail_index_lookup_keywords(struct mail_index_view *view, uint32_t seq,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Returns the UID for given message. May be slightly faster than
b5ea11802f2bafbec06282a7b3b6704dc5fae584Timo Sirainen mail_index_lookup()->uid. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_lookup_uid(struct mail_index_view *view, uint32_t seq,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Convert UID range to sequence range. If no UIDs are found, sequences are
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen set to 0. Note that any of the returned sequences may have been expunged
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_lookup_uid_range(struct mail_index_view *view,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Find first mail with (mail->flags & flags_mask) == flags. Useful mostly for
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen taking advantage of lowwater-fields in headers. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_lookup_first(struct mail_index_view *view, enum mail_flags flags,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Append a new record to index. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_index_append(struct mail_index_transaction *t, uint32_t uid,
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainen/* Assigns UIDs for appended mails all at once. UID must have been given as 0
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainen for mail_index_append(). Returns the next unused UID. */
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainenvoid mail_index_append_assign_uids(struct mail_index_transaction *t,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Expunge record from index. Note that this doesn't affect sequence numbers
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen until transaction is committed and mailbox is synced. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_index_expunge(struct mail_index_transaction *t, uint32_t seq);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Update flags in index. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_index_update_flags(struct mail_index_transaction *t, uint32_t seq,
c251a38df327599a62d341bf5c2282f31352faa5Timo Sirainenvoid mail_index_update_flags_range(struct mail_index_transaction *t,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* Lookup a keyword, returns TRUE if found, FALSE if not. If autocreate is
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen TRUE, the keyword is automatically created and TRUE is always returned. */
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainenbool mail_index_keyword_lookup(struct mail_index *index,
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen unsigned int *idx_r);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* Return a pointer to array of NULL-terminated list of keywords. Note that
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen the array contents (and thus pointers inside it) may change after calling
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen mail_index_keywords_create() or mail_index_sync_begin(). */
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainenconst ARRAY_TYPE(keywords) *mail_index_get_keywords(struct mail_index *index);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen/* Create a keyword list structure. It's freed automatically at the end of
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen the transaction. */
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenmail_index_keywords_create(struct mail_index_transaction *t,
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen const char *const keywords[]);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainenmail_index_keywords_create_from_indexes(struct mail_index_transaction *t,
faed8babca9914257f34fb2e603d74016d563b2dTimo Sirainen/* Free the keywords. */
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainenvoid mail_index_keywords_free(struct mail_keywords **keywords);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen/* Update keywords for given message. */
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenvoid mail_index_update_keywords(struct mail_index_transaction *t, uint32_t seq,
aa38d1a0945f0bc13a225d043f53fad2eec666b1Timo Sirainen/* Update field in header. If prepend is TRUE, the header change is visible
aa38d1a0945f0bc13a225d043f53fad2eec666b1Timo Sirainen before message syncing begins. */
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainenvoid mail_index_update_header(struct mail_index_transaction *t,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Returns the full error message for last error. This message may
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen contain paths etc. so it shouldn't be shown to users. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenconst char *mail_index_get_error_message(struct mail_index *index);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Reset the error message. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_index_reset_error(struct mail_index *index);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Apply changes in MAIL_INDEX_SYNC_TYPE_FLAGS typed sync records to given
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen flags variable. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_index_sync_flags_apply(const struct mail_index_sync_rec *sync_rec,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen/* Apply changes in MAIL_INDEX_SYNC_TYPE_KEYWORD_* typed sync records to given
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen keywords array. Returns TRUE If something was changed. */
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainenbool mail_index_sync_keywords_apply(const struct mail_index_sync_rec *sync_rec,
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen/* register index extension. name is a unique identifier for the extension.
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen returns unique identifier for the name. */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenuint32_t mail_index_ext_register(struct mail_index *index, const char *name,
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen/* Resize existing extension data. If size is grown, the new data will be
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen zero-filled. If size is shrinked, the data is simply dropped. */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenvoid mail_index_ext_resize(struct mail_index_transaction *t, uint32_t ext_id,
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen/* Reset extension records and header. Any updates for this extension which
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen were issued before the writer had seen this reset are discarded. reset_id is
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen used to figure this out, so it must be different every time. */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainenvoid mail_index_ext_reset(struct mail_index_transaction *t, uint32_t ext_id,
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen/* Returns extension header. */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenint mail_index_get_header_ext(struct mail_index_view *view, uint32_t ext_id,
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainenint mail_index_map_get_header_ext(struct mail_index_view *view,
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen/* Returns the wanted extension record for given message. If it doesn't exist,
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen *data_r is set to NULL. Return values are same as for mail_index_lookup(). */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenint mail_index_lookup_ext(struct mail_index_view *view, uint32_t seq,
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainenint mail_index_lookup_ext_full(struct mail_index_view *view, uint32_t seq,
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen uint32_t ext_id, struct mail_index_map **map_r,
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen const void **data_r);
bb2b91b4c5363348b737237893d414639510a561Timo Sirainen/* Get current extension sizes. Returns 1 if ok, 0 if extension doesn't exist
bb2b91b4c5363348b737237893d414639510a561Timo Sirainen in view. Any of the _r parameters may be NULL. */
bb2b91b4c5363348b737237893d414639510a561Timo Sirainenint mail_index_ext_get_size(struct mail_index_view *view,
bb2b91b4c5363348b737237893d414639510a561Timo Sirainen uint32_t *hdr_size_r, uint16_t *record_size_r,
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen/* Update extension header field. */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenvoid mail_index_update_header_ext(struct mail_index_transaction *t,
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen/* Update extension record. If old_data_r is non-NULL and the record extension
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen was already updated in this transaction, it's set to contain the data it's
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen now overwriting. */
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenvoid mail_index_update_ext(struct mail_index_transaction *t, uint32_t seq,
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen uint32_t ext_id, const void *data, void *old_data);