mail-index.h revision 62f4a199b5c9a0862f486cbf18e195cc621bbe25
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch#ifndef MAIL_INDEX_H
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch#define MAIL_INDEX_H
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch#include "file-lock.h"
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch#include "mail-types.h"
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch#include "seq-range-array.h"
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch#define MAIL_INDEX_MAJOR_VERSION 7
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch#define MAIL_INDEX_MINOR_VERSION 1
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch#define MAIL_INDEX_HEADER_MIN_SIZE 120
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschenum mail_index_open_flags {
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* Create index if it doesn't exist */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_OPEN_FLAG_CREATE = 0x01,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* Don't try to mmap() index files */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_OPEN_FLAG_MMAP_DISABLE = 0x04,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* Rely on O_EXCL when creating dotlocks */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_OPEN_FLAG_DOTLOCK_USE_EXCL = 0x10,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* Don't fsync() or fdatasync() */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_OPEN_FLAG_FSYNC_DISABLE = 0x20,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* Flush NFS attr/data/write cache when necessary */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_OPEN_FLAG_NFS_FLUSH = 0x40,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch};
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschenum mail_index_header_compat_flags {
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_COMPAT_LITTLE_ENDIAN = 0x01
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch};
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschenum mail_index_header_flag {
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* Index file is corrupted, reopen or recreate it. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_HDR_FLAG_CORRUPTED = 0x0001,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_HDR_FLAG_HAVE_DIRTY = 0x0002
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch};
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschenum mail_index_mail_flags {
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_MAIL_FLAG_DIRTY = 0x80
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch};
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch#define MAIL_INDEX_FLAGS_MASK \
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch (MAIL_ANSWERED | MAIL_FLAGGED | MAIL_DELETED | MAIL_SEEN | MAIL_DRAFT)
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschstruct mail_index_header {
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* major version is increased only when you can't have backwards
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch compatibility. minor version is increased when header size is
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch increased to contain new non-critical fields. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint8_t major_version;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint8_t minor_version;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint16_t base_header_size;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t header_size; /* base + extended header size */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t record_size;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint8_t compat_flags; /* enum mail_index_header_compat_flags */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint8_t unused[3];
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t indexid;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t flags;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t uid_validity;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t next_uid;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t messages_count;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t unused_old_recent_messages_count;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t seen_messages_count;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t deleted_messages_count;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t first_recent_uid;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* these UIDs may not exist and may not even be unseen/deleted */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t first_unseen_uid_lowwater;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t first_deleted_uid_lowwater;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t log_file_seq;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* non-external records between tail..head haven't been committed to
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch mailbox yet. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t log_file_tail_offset;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t log_file_head_offset;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint64_t sync_size;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t sync_stamp;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* daily first UIDs that have been added to index. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t day_stamp;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t day_first_uid[8];
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch};
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschstruct mail_index_record {
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t uid;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint8_t flags; /* enum mail_flags | enum mail_index_mail_flags */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch};
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschstruct mail_keywords {
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch struct mail_index *index;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch unsigned int count;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* variable sized list of keyword indexes */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch unsigned int idx[1];
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch};
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschenum mail_index_transaction_flags {
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* If transaction is marked as hidden, the changes won't be listed
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch when the view is synchronized. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_TRANSACTION_FLAG_HIDE = 0x01,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* External transactions describe changes to mailbox that have already
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch happened. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL = 0x02,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* Don't add flag updates unless they actually change something.
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch This is reliable only when syncing, otherwise someone else might
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch have already committed a transaction that had changed the flags. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_TRANSACTION_FLAG_AVOID_FLAG_UPDATES = 0x04
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch};
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschenum mail_index_sync_type {
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_SYNC_TYPE_APPEND = 0x01,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_SYNC_TYPE_EXPUNGE = 0x02,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_SYNC_TYPE_FLAGS = 0x04,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_SYNC_TYPE_KEYWORD_ADD = 0x08,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_SYNC_TYPE_KEYWORD_REMOVE = 0x10,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_SYNC_TYPE_KEYWORD_RESET = 0x20
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch};
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschenum mail_index_sync_flags {
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* Resync all dirty messages' flags. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY = 0x01,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* Drop recent flags from all messages */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_SYNC_FLAG_DROP_RECENT = 0x02,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* Create the transaction with AVOID_FLAG_UPDATES flag */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_SYNC_FLAG_AVOID_FLAG_UPDATES = 0x04,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch};
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschenum mail_index_view_sync_flags {
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* Don't sync expunges */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_VIEW_SYNC_FLAG_NOEXPUNGES = 0x01,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* Make sure view isn't inconsistent after syncing. This also means
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch that you don't care about view_sync_next()'s output, so it won't
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch return anything. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_VIEW_SYNC_FLAG_FIX_INCONSISTENT = 0x02
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch};
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschstruct mail_index_sync_rec {
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t uid1, uid2;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch enum mail_index_sync_type type;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* MAIL_INDEX_SYNC_TYPE_FLAGS: */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint8_t add_flags;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint8_t remove_flags;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* MAIL_INDEX_SYNC_TYPE_KEYWORD_ADD, .._REMOVE: */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch unsigned int keyword_idx;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch};
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschstruct mail_index_view_sync_rec {
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t uid1, uid2;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch /* keyword appends and removes are packed into one and same
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch MAIL_INDEX_SYNC_TYPE_KEYWORD_ADD */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch enum mail_index_sync_type type;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch};
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan BoschARRAY_DEFINE_TYPE(keyword_indexes, unsigned int);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschstruct mail_index;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschstruct mail_index_map;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschstruct mail_index_view;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschstruct mail_index_transaction;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschstruct mail_index_sync_ctx;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschstruct mail_index_view_sync_ctx;
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschstruct mail_index *mail_index_alloc(const char *dir, const char *prefix);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_free(struct mail_index **index);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_set_permissions(struct mail_index *index,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch mode_t mode, gid_t gid);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschint mail_index_open(struct mail_index *index, enum mail_index_open_flags flags,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch enum file_lock_method lock_method);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_close(struct mail_index *index);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Move the index into memory. Returns 0 if ok, -1 if error occurred. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschint mail_index_move_to_memory(struct mail_index *index);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschstruct mail_cache *mail_index_get_cache(struct mail_index *index);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Refresh index so mail_index_lookup*() will return latest values. Note that
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch immediately after this call there may already be changes, so if you need to
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch rely on validity of the returned values, use some external locking for it. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschint mail_index_refresh(struct mail_index *index);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* View can be used to look into index. Sequence numbers inside view change
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch only when you synchronize it. The view acquires required locks
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch automatically, but you'll have to drop them manually. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschstruct mail_index_view *mail_index_view_open(struct mail_index *index);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_view_close(struct mail_index_view **view);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Returns the index for given view. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschstruct mail_index *mail_index_view_get_index(struct mail_index_view *view);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Returns number of mails in view. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschuint32_t mail_index_view_get_messages_count(struct mail_index_view *view);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Returns TRUE if we lost track of changes for some reason. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschbool mail_index_view_is_inconsistent(struct mail_index_view *view);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Transaction has to be opened to be able to modify index. You can have
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch multiple transactions open simultaneously. Committed transactions won't
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch show up until you've synchronized the view. Expunges won't show up until
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch you've synchronized the mailbox (mail_index_sync_begin). */
639bb36b12b9f9bb54c8bb1be50eac623622f8a0Timo Sirainenstruct mail_index_transaction *
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschmail_index_transaction_begin(struct mail_index_view *view,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch enum mail_index_transaction_flags flags);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschint mail_index_transaction_commit(struct mail_index_transaction **t,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t *log_file_seq_r,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uoff_t *log_file_offset_r);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_transaction_rollback(struct mail_index_transaction **t);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Discard all changes in the transaction. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_transaction_reset(struct mail_index_transaction *t);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
639bb36b12b9f9bb54c8bb1be50eac623622f8a0Timo Sirainen/* Returns the view transaction was created for. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschstruct mail_index_view *
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschmail_index_transaction_get_view(struct mail_index_transaction *t);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Returns TRUE if the given sequence is being expunged in this transaction. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschbool mail_index_transaction_is_expunged(struct mail_index_transaction *t,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t seq);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Returns a view to transaction. Currently this differs from normal view only
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch in that it contains newly appended messages in transaction. The view can
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch still be used after transaction has been committed. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschstruct mail_index_view *
639bb36b12b9f9bb54c8bb1be50eac623622f8a0Timo Sirainenmail_index_transaction_open_updated_view(struct mail_index_transaction *t);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
639bb36b12b9f9bb54c8bb1be50eac623622f8a0Timo Sirainen/* Begin synchronizing mailbox with index file. Returns 0 if ok, -1 if error.
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
639bb36b12b9f9bb54c8bb1be50eac623622f8a0Timo Sirainen mail_index_sync_next() returns all changes from previously committed
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch transactions which haven't yet been committed to the actual mailbox.
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch They're returned in ascending order and they never overlap (if we add more
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch sync types, then they might). You must go through all of them and update
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch the mailbox accordingly.
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch Changes done to the returned transaction are expected to describe the
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch mailbox's current state.
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch The returned view already contains all the changes, so if e.g. a record's
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch flags are different in view than in the mailbox you can assume that they
639bb36b12b9f9bb54c8bb1be50eac623622f8a0Timo Sirainen were changed externally, and you need to update the index.
639bb36b12b9f9bb54c8bb1be50eac623622f8a0Timo Sirainen
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch Returned expunges are treated as expunge requests. They're not really
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch removed from the index until you mark them expunged to the returned
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch transaction. If it's not possible to expunge the message (e.g. permission
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch denied), simply don't mark them expunged.
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch Returned sequence numbers describe the mailbox state at the beginning of
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch synchronization, ie. expunges don't affect them. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschint mail_index_sync_begin(struct mail_index *index,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch struct mail_index_sync_ctx **ctx_r,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch struct mail_index_view **view_r,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch struct mail_index_transaction **trans_r,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch enum mail_index_sync_flags flags);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Like mail_index_sync_begin(), but returns 1 if OK and if index is already
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch synchronized up to the given log_file_seq+offset, the synchronization isn't
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch started and this function returns 0. This should be done when you wish to
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch sync your committed transaction instead of doing a full mailbox
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch synchronization. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschint mail_index_sync_begin_to(struct mail_index *index,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch struct mail_index_sync_ctx **ctx_r,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch struct mail_index_view **view_r,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch struct mail_index_transaction **trans_r,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t log_file_seq, uoff_t log_file_offset,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch enum mail_index_sync_flags flags);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Returns TRUE if it currently looks like syncing would return changes. */
639bb36b12b9f9bb54c8bb1be50eac623622f8a0Timo Sirainenbool mail_index_sync_have_any(struct mail_index *index,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch enum mail_index_sync_flags flags);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Returns -1 if error, 0 if sync is finished, 1 if record was filled. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschbool mail_index_sync_next(struct mail_index_sync_ctx *ctx,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch struct mail_index_sync_rec *sync_rec);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Returns TRUE if there's more to sync. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschbool mail_index_sync_have_more(struct mail_index_sync_ctx *ctx);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Reset syncing to initial state after mail_index_sync_begin(), so you can
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch go through all the sync records again with mail_index_sync_next(). */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_sync_reset(struct mail_index_sync_ctx *ctx);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Commit synchronization by writing all changes to mail index file. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschint mail_index_sync_commit(struct mail_index_sync_ctx **ctx);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Rollback synchronization - none of the changes listed by sync_next() are
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch actually written to index file. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_sync_rollback(struct mail_index_sync_ctx **ctx);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Mark index file corrupted. Invalidates all views. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_mark_corrupted(struct mail_index *index);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Check and fix any found problems. Returns -1 if we couldn't lock for sync,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch 0 if everything went ok. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschint mail_index_fsck(struct mail_index *index);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Synchronize changes in view. You have to go through all records, or view
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch will be marked inconsistent. Only sync_mask type records are
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch synchronized. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschint mail_index_view_sync_begin(struct mail_index_view *view,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch enum mail_index_view_sync_flags flags,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch struct mail_index_view_sync_ctx **ctx_r);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschbool mail_index_view_sync_next(struct mail_index_view_sync_ctx *ctx,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch struct mail_index_view_sync_rec *sync_rec);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschmail_index_view_sync_get_expunges(struct mail_index_view_sync_ctx *ctx,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch const ARRAY_TYPE(seq_range) **expunges_r);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschint mail_index_view_sync_commit(struct mail_index_view_sync_ctx **ctx);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Returns the index header. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschconst struct mail_index_header *
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschmail_index_get_header(struct mail_index_view *view);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Returns the wanted message record. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschconst struct mail_index_record *
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschmail_index_lookup(struct mail_index_view *view, uint32_t seq);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschconst struct mail_index_record *
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschmail_index_lookup_full(struct mail_index_view *view, uint32_t seq,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch struct mail_index_map **map_r);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Returns TRUE if the given message has already been expunged from index. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschbool mail_index_is_expunged(struct mail_index_view *view, uint32_t seq);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Note that returned keyword indexes aren't sorted. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_lookup_keywords(struct mail_index_view *view, uint32_t seq,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch ARRAY_TYPE(keyword_indexes) *keyword_idx);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Returns the UID for given message. May be slightly faster than
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch mail_index_lookup()->uid. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_lookup_uid(struct mail_index_view *view, uint32_t seq,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t *uid_r);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Convert UID range to sequence range. If no UIDs are found, sequences are
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch set to 0. Note that any of the returned sequences may have been expunged
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch already. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_lookup_uid_range(struct mail_index_view *view,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t first_uid, uint32_t last_uid,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t *first_seq_r, uint32_t *last_seq_r);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Find first mail with (mail->flags & flags_mask) == flags. Useful mostly for
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch taking advantage of lowwater-fields in headers. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_lookup_first(struct mail_index_view *view,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch enum mail_flags flags, uint8_t flags_mask,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t *seq_r);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Append a new record to index. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_append(struct mail_index_transaction *t, uint32_t uid,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t *seq_r);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Assigns UIDs for appended mails all at once. UID must have been given as 0
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch for mail_index_append(). Returns the next unused UID. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_append_assign_uids(struct mail_index_transaction *t,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t first_uid, uint32_t *next_uid_r);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Expunge record from index. Note that this doesn't affect sequence numbers
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch until transaction is committed and mailbox is synced. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_expunge(struct mail_index_transaction *t, uint32_t seq);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Update flags in index. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_update_flags(struct mail_index_transaction *t, uint32_t seq,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch enum modify_type modify_type,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch enum mail_flags flags);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_update_flags_range(struct mail_index_transaction *t,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t seq1, uint32_t seq2,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch enum modify_type modify_type,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch enum mail_flags flags);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Reset the index before committing this transaction. This is usually done
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch only when UIDVALIDITY changes. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_reset(struct mail_index_transaction *t);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Lookup a keyword, returns TRUE if found, FALSE if not. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschbool mail_index_keyword_lookup(struct mail_index *index,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch const char *keyword, unsigned int *idx_r);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_keyword_lookup_or_create(struct mail_index *index,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch const char *keyword,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch unsigned int *idx_r);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Return a pointer to array of NULL-terminated list of keywords. Note that
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch the array contents (and thus pointers inside it) may change after calling
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch mail_index_keywords_create() or mail_index_sync_begin(). */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschconst ARRAY_TYPE(keywords) *mail_index_get_keywords(struct mail_index *index);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Create a keyword list structure. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschstruct mail_keywords *
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschmail_index_keywords_create(struct mail_index *index,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch const char *const keywords[]);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschstruct mail_keywords *
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschmail_index_keywords_create_from_indexes(struct mail_index *index,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch const ARRAY_TYPE(keyword_indexes)
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch *keyword_indexes);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Free the keywords. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_keywords_free(struct mail_keywords **keywords);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Update keywords for given message. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_update_keywords(struct mail_index_transaction *t, uint32_t seq,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch enum modify_type modify_type,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch struct mail_keywords *keywords);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Update field in header. If prepend is TRUE, the header change is visible
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch before message syncing begins. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_update_header(struct mail_index_transaction *t,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch size_t offset, const void *data, size_t size,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch bool prepend);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Returns the full error message for last error. This message may
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch contain paths etc. so it shouldn't be shown to users. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschconst char *mail_index_get_error_message(struct mail_index *index);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Reset the error message. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_reset_error(struct mail_index *index);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Apply changes in MAIL_INDEX_SYNC_TYPE_FLAGS typed sync records to given
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch flags variable. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_sync_flags_apply(const struct mail_index_sync_rec *sync_rec,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint8_t *flags);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Apply changes in MAIL_INDEX_SYNC_TYPE_KEYWORD_* typed sync records to given
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch keywords array. Returns TRUE If something was changed. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschbool mail_index_sync_keywords_apply(const struct mail_index_sync_rec *sync_rec,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch ARRAY_TYPE(keyword_indexes) *keywords);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* register index extension. name is a unique identifier for the extension.
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch returns unique identifier for the name. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschuint32_t mail_index_ext_register(struct mail_index *index, const char *name,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t default_hdr_size,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint16_t default_record_size,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint16_t default_record_align);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Resize existing extension data. If size is grown, the new data will be
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch zero-filled. If size is shrinked, the data is simply dropped. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_ext_resize(struct mail_index_transaction *t, uint32_t ext_id,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t hdr_size, uint16_t record_size,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint16_t record_align);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Reset extension records and header. Any updates for this extension which
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch were issued before the writer had seen this reset are discarded. reset_id is
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch used to figure this out, so it must be different every time. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_ext_reset(struct mail_index_transaction *t, uint32_t ext_id,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t reset_id);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Discard existing extension updates and write new updates using the given
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch reset_id. The difference to mail_index_ext_reset() is that this doesn't
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch clear any existing record or header data. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_ext_set_reset_id(struct mail_index_transaction *t,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t ext_id, uint32_t reset_id);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Get the current reset_id for given extension. Returns TRUE if it exists. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschbool mail_index_ext_get_reset_id(struct mail_index_view *view,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch struct mail_index_map *map,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t ext_id, uint32_t *reset_id_r);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Returns extension header. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_get_header_ext(struct mail_index_view *view, uint32_t ext_id,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch const void **data_r, size_t *data_size_r);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_map_get_header_ext(struct mail_index_view *view,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch struct mail_index_map *map, uint32_t ext_id,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch const void **data_r, size_t *data_size_r);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Returns the wanted extension record for given message. If it doesn't exist,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch *data_r is set to NULL. expunged_r is TRUE if the message has already been
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch expunged from the index. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_lookup_ext(struct mail_index_view *view, uint32_t seq,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t ext_id, const void **data_r,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch bool *expunged_r);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_lookup_ext_full(struct mail_index_view *view, uint32_t seq,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t ext_id, struct mail_index_map **map_r,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch const void **data_r, bool *expunged_r);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Get current extension sizes. Returns 1 if ok, 0 if extension doesn't exist
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch in view. Any of the _r parameters may be NULL. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_ext_get_size(struct mail_index_view *view,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t ext_id, struct mail_index_map *map,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t *hdr_size_r, uint16_t *record_size_r,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint16_t *record_align_r);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Update extension header field. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_update_header_ext(struct mail_index_transaction *t,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t ext_id, size_t offset,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch const void *data, size_t size);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch/* Update extension record. If old_data_r is non-NULL and the record extension
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch was already updated in this transaction, it's set to contain the data it's
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch now overwriting. */
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Boschvoid mail_index_update_ext(struct mail_index_transaction *t, uint32_t seq,
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch uint32_t ext_id, const void *data, void *old_data);
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch#endif
8fe8f97e688779add9cd042a9db4ddb7b117cce2Stephan Bosch