53#include "hcache/hcversion.h"
57#if !(defined(HAVE_BDB) || defined(HAVE_GDBM) || defined(HAVE_KC) || \
58 defined(HAVE_LMDB) || defined(HAVE_QDBM) || defined(HAVE_ROCKSDB) || \
59 defined(HAVE_TC) || defined(HAVE_TDB))
60#error "No hcache backend defined"
72 return sizeof(int) +
sizeof(uint32_t);
100 memcpy(&e_dump, e,
sizeof(
struct Email));
126 memcpy(d + *off, &e_dump,
sizeof(
struct Email));
127 *off +=
sizeof(
struct Email);
151 off +=
sizeof(uint32_t);
154 off +=
sizeof(
unsigned int);
158 memcpy(e, d + off,
sizeof(
struct Email));
159 off +=
sizeof(
struct Email);
196#ifdef USE_HCACHE_COMPRESSION
198 if (c_header_cache_compress_method)
202 rk.
len = snprintf(rk.
key,
sizeof(rk.
key),
"%s-%s", key, cops->
name);
207 memcpy(rk.
key, key, keylen + 1);
225 char *p = strrchr(dir,
'/');
236 mutt_error(
_(
"Can't create %s: %s"), dir, strerror(errno));
266 struct stat st = { 0 };
269 int rc = stat(path, &st);
270 bool slash = (path[plen - 1] ==
'/');
272 if (((rc == 0) && !S_ISDIR(st.st_mode)) || ((rc == -1) && !slash))
284 namer(folder, hcfile);
297#ifdef USE_HCACHE_COMPRESSION
299 const char *cm = c_header_cache_compress_method;
326 if (!realpath(folder, p))
370 if (!hc || !ops || !data || !*data)
393 unsigned char charval[16];
426#ifdef USE_HCACHE_COMPRESSION
428 if (c_header_cache_compress_method)
433 hc->
cctx = cops->
open(c_header_cache_compress_level);
448 if (!path || (path[0] ==
'\0'))
496#ifdef USE_HCACHE_COMPRESSION
498 if (c_header_cache_compress_method)
521 void *to_free = data;
536 assert((
size_t) off == hlen);
542#ifdef USE_HCACHE_COMPRESSION
544 if (c_header_cache_compress_method)
548 void *dblob = cops->
decompress(hc->cctx, (
char *) data + hlen, dlen - hlen);
553 data = (
char *) dblob - hlen;
575 size_t keylen,
void *dst,
size_t dstlen)
579 void *src =
fetch_raw(hc, key, keylen, &srclen);
580 if (src && srclen == dstlen)
582 memcpy(dst, src, dstlen);
604 void *data =
fetch_raw(hc, key, keylen, &dlen);
617 struct Email *e, uint32_t uidvalidity)
623 char *data =
dump_email(hc, e, &dlen, uidvalidity);
625#ifdef USE_HCACHE_COMPRESSION
627 if (c_header_cache_compress_method)
637 void *cdata = cops->
compress(hc->
cctx, data + hlen, dlen - hlen, &clen);
645 memcpy(whole, data, hlen);
646 memcpy(whole + hlen, cdata, clen);
675 size_t keylen,
void *data,
size_t dlen)
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
void buf_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
struct Buffer buf_make(size_t size)
Make a new buffer on the stack.
size_t buf_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
const struct ComprOps * compress_get_ops(const char *compr)
Get the API functions for a compress backend.
API for the header cache compression.
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
struct Body * mutt_body_new(void)
Create a new Body.
struct Email * email_new(void)
Create a new Email.
struct ReplaceList SpamList
List of regexes to match subscribed mailing lists.
struct RegexList NoSpamList
List of regexes and patterns to match spam emails.
Structs that make up an email.
struct Envelope * mutt_env_new(void)
Create a new Envelope.
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
#define mutt_debug(LEVEL,...)
void(* hcache_namer_t)(const char *path, struct Buffer *dest)
static struct RealKey * realkey(const char *key, size_t keylen)
Compute the real key used in the backend, taking into account the compression method.
static unsigned int HcacheVer
Header Cache version.
bool mutt_hcache_fetch_obj_(struct HeaderCache *hc, const char *key, size_t keylen, void *dst, size_t dstlen)
Fetch a message's header from the cache into a destination object.
int mutt_hcache_store(struct HeaderCache *hc, const char *key, size_t keylen, struct Email *e, uint32_t uidvalidity)
Multiplexor for StoreOps::store.
void mutt_hcache_close(struct HeaderCache *hc)
Multiplexor for StoreOps::close.
static struct Email * restore_email(const unsigned char *d)
Restore an Email from data retrieved from the cache.
struct HeaderCache * mutt_hcache_open(const char *path, const char *folder, hcache_namer_t namer)
Multiplexor for StoreOps::open.
static bool create_hcache_dir(const char *path)
Create parent dirs for the hcache database.
int mutt_hcache_delete_record(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
static void free_raw(struct HeaderCache *hc, void **data)
Multiplexor for StoreOps::free.
int mutt_hcache_store_raw(struct HeaderCache *hc, const char *key, size_t keylen, void *data, size_t dlen)
Store a key / data pair.
static void * dump_email(struct HeaderCache *hc, const struct Email *e, int *off, uint32_t uidvalidity)
Serialise an Email object.
static void * fetch_raw(struct HeaderCache *hc, const char *key, size_t keylen, size_t *dlen)
Fetch a message's header from the cache.
struct HCacheEntry mutt_hcache_fetch(struct HeaderCache *hc, const char *key, size_t keylen, uint32_t uidvalidity)
Multiplexor for StoreOps::fetch.
char * mutt_hcache_fetch_str(struct HeaderCache *hc, const char *key, size_t keylen)
Fetch a string from the cache.
static size_t header_size(void)
Compute the size of the header with uuid validity and crc.
static void hcache_per_folder(struct Buffer *hcpath, const char *path, const char *folder, hcache_namer_t namer)
Generate the hcache pathname.
static char * get_foldername(const char *folder)
Where should the cache be stored?
@ LL_DEBUG3
Log at debug level 3.
void * mutt_md5(const char *str, void *buf)
Calculate the MD5 hash of a NULL-terminated string.
void mutt_md5_process_bytes(const void *buf, size_t buflen, struct Md5Ctx *md5ctx)
Process a block of data.
void mutt_md5_process(const char *str, struct Md5Ctx *md5ctx)
Process a NULL-terminated string.
void mutt_md5_init_ctx(struct Md5Ctx *md5ctx)
Initialise the MD5 computation.
void * mutt_md5_finish_ctx(struct Md5Ctx *md5ctx, void *resbuf)
Process the remaining bytes in the buffer.
void mutt_md5_toascii(const void *digest, char *resbuf)
Convert a binary MD5 digest into ASCII Hexadecimal.
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
bool CharsetIsUtf8
Is the user's current character set utf-8?
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Convenience wrapper for the library headers.
char * mutt_strn_dup(const char *begin, size_t len)
Duplicate a sub-string.
char * mutt_str_dup(const char *str)
Copy a string, safely.
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
void mutt_encode_path(struct Buffer *buf, const char *src)
Convert a path to 'us-ascii'.
Some miscellaneous functions.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
#define STAILQ_INIT(head)
#define STAILQ_FOREACH(var, head, field)
void serial_restore_tags(struct TagList *tags, const unsigned char *d, int *off)
Unpack a TagList from a binary blob.
void serial_restore_envelope(struct Envelope *env, const unsigned char *d, int *off, bool convert)
Unpack an Envelope from a binary blob.
unsigned char * serial_dump_uint32_t(uint32_t s, unsigned char *d, int *off)
Pack a uint32_t into a binary blob.
unsigned char * serial_dump_int(unsigned int i, unsigned char *d, int *off)
Pack an integer into a binary blob.
void lazy_realloc(void *ptr, size_t size)
Reallocate some memory.
unsigned char * serial_dump_envelope(struct Envelope *env, unsigned char *d, int *off, bool convert)
Pack an Envelope into a binary blob.
unsigned char * serial_dump_body(struct Body *c, unsigned char *d, int *off, bool convert)
Pack an Body into a binary blob.
void serial_restore_body(struct Body *c, const unsigned char *d, int *off, bool convert)
Unpack a Body from a binary blob.
void serial_restore_int(unsigned int *i, const unsigned char *d, int *off)
Unpack an integer from a binary blob.
unsigned char * serial_dump_tags(const struct TagList *tags, unsigned char *d, int *off)
Pack a TagList into a binary blob.
void serial_restore_uint32_t(uint32_t *s, const unsigned char *d, int *off)
Unpack an uint32_t from a binary blob.
const struct StoreOps * store_get_backend_ops(const char *str)
Get the API functions for an store backend.
String manipulation buffer.
char * data
Pointer to data.
void(* close)(void **cctx)
void *(* open)(short level)
void *(* decompress)(void *cctx, const char *cbuf, size_t clen)
void *(* compress)(void *cctx, const char *data, size_t dlen, size_t *clen)
const char * name
Compression name.
The envelope/body of an email.
bool searched
Email has been searched.
bool matched
Search matches this Email.
bool visible
Is this message part of the view?
bool recip_valid
Is_recipient is valid.
bool attach_valid
true when the attachment count is valid
struct Envelope * env
Envelope information.
void * edata
Driver-specific data.
bool collapsed
Is this message part of a collapsed thread?
struct Body * body
List of MIME parts.
char * tree
Character string to print thread tree.
size_t num_hidden
Number of hidden messages in this view (only valid when collapsed is set)
struct AttrColor * attr_color
Color-pair to use when displaying in the index.
bool changed
Email has been edited.
bool threaded
Used for threading.
struct ListHead chain
Mixmaster chain.
struct TagList tags
For drivers that support server tagging.
struct Notify * notify
Notifications: NotifyEmail, EventEmail.
char * path
Path of Email (for local Mailboxes)
size_t sequence
Sequence number assigned on creation.
short recipient
User_is_recipient()'s return value, cached.
bool tagged
Email is tagged.
struct MuttThread * thread
Thread of Emails.
Wrapper for Email retrieved from the header cache.
uint32_t uidvalidity
IMAP-specific UIDVALIDITY.
struct Email * email
Retrieved email.
unsigned int crc
CRC of Email/Body/etc structs.
Cursor for the MD5 hashing.
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.
Hcache key name (including compression method)
List of regular expressions.
struct Regex * regex
Regex containing a regular expression.
char * pattern
printable version
List of regular expressions.
char * templ
Template to match.
struct Regex * regex
Regex containing a regular expression.
void *(* fetch)(void *store, const char *key, size_t klen, size_t *vlen)
void(* free)(void *store, void **ptr)
int(* delete_record)(void *store, const char *key, size_t klen)
const char * name
Store name.
int(* store)(void *store, const char *key, size_t klen, void *value, size_t vlen)
void *(* open)(const char *path)
void(* close)(void **ptr)