/usr/include/dovecot/mail-cache.h is in dovecot-dev 1:2.2.22-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | #ifndef MAIL_CACHE_H
#define MAIL_CACHE_H
#include "mail-index.h"
#define MAIL_CACHE_FILE_SUFFIX ".cache"
struct mail_cache;
struct mail_cache_view;
struct mail_cache_transaction_ctx;
struct mail_cache_compress_lock;
enum mail_cache_decision_type {
/* Not needed currently */
MAIL_CACHE_DECISION_NO = 0x00,
/* Needed only for new mails. Drop when compressing. */
MAIL_CACHE_DECISION_TEMP = 0x01,
/* Needed. */
MAIL_CACHE_DECISION_YES = 0x02,
/* This decision has been forced manually, don't change it. */
MAIL_CACHE_DECISION_FORCED = 0x80
};
enum mail_cache_field_type {
MAIL_CACHE_FIELD_FIXED_SIZE,
MAIL_CACHE_FIELD_VARIABLE_SIZE,
MAIL_CACHE_FIELD_STRING,
MAIL_CACHE_FIELD_BITMASK,
MAIL_CACHE_FIELD_HEADER,
MAIL_CACHE_FIELD_COUNT
};
struct mail_cache_field {
const char *name;
unsigned int idx;
enum mail_cache_field_type type;
unsigned int field_size;
enum mail_cache_decision_type decision;
/* If higher than the current last_used field, update it */
time_t last_used;
};
struct mail_cache *mail_cache_open_or_create(struct mail_index *index);
void mail_cache_free(struct mail_cache **cache);
/* Register fields. fields[].idx is updated to contain field index.
If field already exists and its caching decision is NO, the decision is
updated to the input field's decision. */
void mail_cache_register_fields(struct mail_cache *cache,
struct mail_cache_field *fields,
unsigned int fields_count);
/* Returns registered field index, or UINT_MAX if not found. */
unsigned int
mail_cache_register_lookup(struct mail_cache *cache, const char *name);
/* Returns specified field */
const struct mail_cache_field *
mail_cache_register_get_field(struct mail_cache *cache, unsigned int field_idx);
/* Returns a list of all registered fields */
const struct mail_cache_field *
mail_cache_register_get_list(struct mail_cache *cache, pool_t pool,
unsigned int *count_r);
/* Returns TRUE if cache should be compressed. */
bool mail_cache_need_compress(struct mail_cache *cache);
/* Compress cache file. Offsets are updated to given transaction. The cache
compression lock should be kept until the transaction is committed.
mail_cache_compress_unlock() needs to be called afterwards. The lock doesn't
prevent updates to the cache while it's held, it only prevents another cache
compression. */
int mail_cache_compress(struct mail_cache *cache,
struct mail_index_transaction *trans,
struct mail_cache_compress_lock **lock_r);
void mail_cache_compress_unlock(struct mail_cache_compress_lock **lock);
/* Returns TRUE if there is at least something in the cache. */
bool mail_cache_exists(struct mail_cache *cache);
/* Open and read cache header. Returns 0 if ok, -1 if error/corrupted. */
int mail_cache_open_and_verify(struct mail_cache *cache);
struct mail_cache_view *
mail_cache_view_open(struct mail_cache *cache, struct mail_index_view *iview);
void mail_cache_view_close(struct mail_cache_view **view);
/* Normally cache decisions are updated on lookup/add. Use this function to
enable/disable this (useful for precaching data). */
void mail_cache_view_update_cache_decisions(struct mail_cache_view *view,
bool update);
/* Get index transaction specific cache transaction. */
struct mail_cache_transaction_ctx *
mail_cache_get_transaction(struct mail_cache_view *view,
struct mail_index_transaction *t);
void mail_cache_transaction_reset(struct mail_cache_transaction_ctx *ctx);
int mail_cache_transaction_commit(struct mail_cache_transaction_ctx **ctx);
void mail_cache_transaction_rollback(struct mail_cache_transaction_ctx **ctx);
/* Add new field to given record. Updates are not allowed. Fixed size fields
must be exactly the expected size. */
void mail_cache_add(struct mail_cache_transaction_ctx *ctx, uint32_t seq,
unsigned int field_idx, const void *data, size_t data_size);
/* Returns TRUE if field is wanted to be added and it doesn't already exist.
If current caching decisions say not to cache this field, FALSE is returned.
If seq is 0, the existence isn't checked. */
bool mail_cache_field_want_add(struct mail_cache_transaction_ctx *ctx,
uint32_t seq, unsigned int field_idx);
/* Like mail_cache_field_want_add(), but in caching decisions FALSE is
returned only if the decision is a forced no. */
bool mail_cache_field_can_add(struct mail_cache_transaction_ctx *ctx,
uint32_t seq, unsigned int field_idx);
/* Returns 1 if field exists, 0 if not, -1 if error. */
int mail_cache_field_exists(struct mail_cache_view *view, uint32_t seq,
unsigned int field_idx);
/* Returns TRUE if something is cached for the message, FALSE if not. */
bool mail_cache_field_exists_any(struct mail_cache_view *view, uint32_t seq);
/* Returns current caching decision for given field. */
enum mail_cache_decision_type
mail_cache_field_get_decision(struct mail_cache *cache, unsigned int field_idx);
/* Set data_r and size_r to point to wanted field in cache file.
Returns 1 if field was found, 0 if not, -1 if error. */
int mail_cache_lookup_field(struct mail_cache_view *view, buffer_t *dest_buf,
uint32_t seq, unsigned int field_idx);
/* Return specified cached headers. Returns 1 if all fields were found,
0 if not, -1 if error. dest is updated only if all fields were found. */
int mail_cache_lookup_headers(struct mail_cache_view *view, string_t *dest,
uint32_t seq, unsigned int field_idxs[],
unsigned int fields_count);
/* "Error in index cache file %s: ...". */
void mail_cache_set_corrupted(struct mail_cache *cache, const char *fmt, ...)
ATTR_FORMAT(2, 3);
/* Delete the cache file. */
void mail_cache_reset(struct mail_cache *cache);
#endif
|