mail-index.h revision d2475500ee2a5f3c07eb22886797cef0e11ce7c4
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk /* Create index if it doesn't exist */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk /* Don't try to mmap() index files */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk /* Rely on O_EXCL when creating dotlocks */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk /* Don't fsync() or fdatasync() */
a75d470c9223a75801418fcdda258885c36317e0Timo Sirainen /* Index file is corrupted, reopen or recreate it. */
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen /* fsck the index next time when opening */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk (MAIL_ANSWERED | MAIL_FLAGGED | MAIL_DELETED | MAIL_SEEN | MAIL_DRAFT)
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk /* major version is increased only when you can't have backwards
a75d470c9223a75801418fcdda258885c36317e0Timo Sirainen compatibility. minor version is increased when header size is
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk increased to contain new non-critical fields. */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk uint32_t header_size; /* base + extended header size */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk uint8_t compat_flags; /* enum mail_index_header_compat_flags */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk /* these UIDs may not exist and may not even be unseen */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk /* daily first UIDs that have been added to index. */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk uint8_t flags; /* enum mail_flags | enum mail_index_mail_flags */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk unsigned int count;
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk /* variable sized list of keyword indexes */
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomi /* MAIL_INDEX_SYNC_TYPE_FLAGS: */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk /* MAIL_INDEX_SYNC_TYPE_KEYWORD_ADD, .._REMOVE: */
633a1bf10559b9a8d85bfab662fa2a7ba97d45baAki Tuomi /* keyword appends and removes are packed into one and same
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk MAIL_INDEX_SYNC_TYPE_KEYWORD_ADD */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal VolkARRAY_DEFINE_TYPE(keyword_indexes, unsigned int);
a75d470c9223a75801418fcdda258885c36317e0Timo Sirainenstruct mail_index *mail_index_alloc(const char *dir, const char *prefix);
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkvoid mail_index_set_permissions(struct mail_index *index,
a75d470c9223a75801418fcdda258885c36317e0Timo Sirainenint mail_index_open(struct mail_index *index, enum mail_index_open_flags flags,
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk/* Move the index into memory. Returns 0 if ok, -1 if error occurred. */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkint mail_index_move_to_memory(struct mail_index *index);
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkstruct mail_cache *mail_index_get_cache(struct mail_index *index);
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk/* Refresh index so mail_index_lookup*() will return latest values. Note that
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk immediately after this call there may already be changes, so if you need to
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk rely on validity of the returned values, use some external locking for it. */
a75d470c9223a75801418fcdda258885c36317e0Timo Sirainenint mail_index_refresh(struct mail_index *index);
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk/* View can be used to look into index. Sequence numbers inside view change
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk only when you synchronize it. The view acquires required locks
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk automatically, but you'll have to drop them manually. */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkstruct mail_index_view *mail_index_view_open(struct mail_index *index);
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkvoid mail_index_view_close(struct mail_index_view **view);
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk/* Returns the index for given view. */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkstruct mail_index *mail_index_view_get_index(struct mail_index_view *view);
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk/* Call whenever you've done with requesting messages from view for a while. */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkvoid mail_index_view_unlock(struct mail_index_view *view);
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk/* Returns number of mails in view. */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkuint32_t mail_index_view_get_messages_count(struct mail_index_view *view);
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk/* Returns TRUE if we lost track of changes for some reason. */
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volkbool mail_index_view_is_inconsistent(struct mail_index_view *view);
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk/* Transaction has to be opened to be able to modify index. You can have
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk multiple transactions open simultaneously. Committed transactions won't
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomi show up until you've synchronized the view. Expunges won't show up until
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk you've synchronized the mailbox (mail_index_sync_begin).
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk If transaction is marked as hidden, the changes won't be listed when the
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk view is synchronized. Expunges can't be hidden.
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomi External transactions describe changes to mailbox that have already
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomi happened. */
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomimail_index_transaction_begin(struct mail_index_view *view,
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomiint mail_index_transaction_commit(struct mail_index_transaction **t,
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomivoid mail_index_transaction_rollback(struct mail_index_transaction **t);
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomi/* Discard all changes in the transaction. */
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomivoid mail_index_transaction_reset(struct mail_index_transaction *t);
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomi/* Returns the view transaction was created for. */
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomimail_index_transaction_get_view(struct mail_index_transaction *t);
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomi/* Returns TRUE if the given sequence is being expunged in this transaction. */
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomibool mail_index_transaction_is_expunged(struct mail_index_transaction *t,
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk/* Returns a view to transaction. Currently this differs from normal view only
678d0463849ba777106eb7875f27db07a5d8e3dfTimo Sirainen in that it contains newly appended messages in transaction. The view can
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk still be used after transaction has been committed. */
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomimail_index_transaction_open_updated_view(struct mail_index_transaction *t);
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomi/* Begin synchronizing mailbox with index file. Returns 1 if ok, -1 if error.
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk If log_file_seq is not (uint32_t)-1 and index is already synchronized up
633a1bf10559b9a8d85bfab662fa2a7ba97d45baAki Tuomi to the given log_file_offset, the synchronization isn't started and this
633a1bf10559b9a8d85bfab662fa2a7ba97d45baAki Tuomi function returns 0. This should be done when you wish to sync your committed
633a1bf10559b9a8d85bfab662fa2a7ba97d45baAki Tuomi transaction instead of doing a full mailbox synchronization.
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk mail_index_sync_next() returns all changes from previously committed
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk transactions which haven't yet been committed to the actual mailbox.
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk They're returned in ascending order and they never overlap (if we add more
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk sync types, then they might). You must go through all of them and update
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk the mailbox accordingly.
381daab1e3b56a0bc94d2191cf62beba0df51af9Pascal Volk None of the changes actually show up in the index until after a successful
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomi mail_index_sync_commit().
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomi Returned sequence numbers describe the mailbox state at the beginning of
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomi synchronization, ie. expunges don't affect them.
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomi Changes done to the returned transaction are expected to describe the
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomi mailbox's current state. */
6eb1a7a7ae2c1dfff6731956ade08f9a4a7c791aAki Tuomiint mail_index_sync_begin(struct mail_index *index,
const struct mail_index_header *
unsigned int *idx_r);
struct mail_keywords *
const char *const keywords[]);
struct mail_keywords *
bool prepend);
const void **data_r);