50#include "hcache/hcversion.h"
54#if !(defined(HAVE_BDB) || defined(HAVE_GDBM) || defined(HAVE_KC) || \
55 defined(HAVE_LMDB) || defined(HAVE_QDBM) || defined(HAVE_ROCKSDB) || \
56 defined(HAVE_TC) || defined(HAVE_TDB))
57#error "No hcache backend defined"
81 size_t keylen,
bool compress)
87#ifdef USE_HCACHE_COMPRESSION
129 return sizeof(int) +
sizeof(uint32_t);
170 e->
security = (packed & ((1 << 16) - 1));
171 e->
expired = (packed & (1 << 16));
172 e->
flagged = (packed & (1 << 17));
173 e->
mime = (packed & (1 << 18));
174 e->
old = (packed & (1 << 19));
175 e->
read = (packed & (1 << 20));
176 e->
replied = (packed & (1 << 21));
178 e->
trash = (packed & (1 << 23));
210 e->
zhours = (packed & ((1 << 5) - 1));
211 e->
zminutes = ((packed >> 5) & ((1 << 6) - 1));
273 off +=
sizeof(uint32_t);
274 off +=
sizeof(
unsigned int);
292 unsigned int num = 0;
318 char *p = strrchr(dir,
'/');
329 mutt_error(
_(
"Can't create %s: %s"), dir, strerror(errno));
359 struct stat st = { 0 };
362 int rc = stat(path, &st);
363 bool slash = (path[plen - 1] ==
'/');
365 if (((rc == 0) && !S_ISDIR(st.st_mode)) || ((rc == -1) && !slash))
377 namer(hc->
folder, hcfile);
386#ifdef USE_HCACHE_COMPRESSION
414 if (!realpath(folder, p))
436 unsigned char charval[16];
439 struct Md5Ctx md5ctx = { 0 };
444 unsigned int ver = HCACHEVER;
465 return digest.intval;
474 if (!path || (path[0] ==
'\0'))
493#ifdef USE_HCACHE_COMPRESSION
495 if (c_header_cache_compress_method)
549#ifdef USE_HCACHE_COMPRESSION
571 void *data = hc->store_ops->fetch(hc->store_handle, rk->
key, rk->
keylen, &dlen);
572 void *to_free = data;
587 ASSERT((
size_t) off == hlen);
588 if ((hce.
crc != hc->
crc) || ((uidvalidity != 0) && (uidvalidity != hce.
uidvalidity)))
593#ifdef USE_HCACHE_COMPRESSION
596 void *dblob = hc->compr_ops->decompress(hc->compr_handle,
597 (
char *) data + hlen, dlen - hlen);
602 data = (
char *) dblob - hlen;
624 size_t keylen,
void *dst,
size_t dstlen)
632 if (src && (srclen == dstlen))
634 memcpy(dst, src, dstlen);
671 struct Email *e, uint32_t uidvalidity)
677 char *data =
dump_email(hc, e, &dlen, uidvalidity);
679#ifdef USE_HCACHE_COMPRESSION
696 memcpy(whole, data, hlen);
697 memcpy(whole + hlen, cdata, clen);
725 void *data,
size_t dlen)
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
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,...)
static unsigned int HcacheVer
Header Cache version.
static struct Email * restore_email(const unsigned char *d)
Restore an Email from data retrieved from the cache.
static void hcache_free(struct HeaderCache **ptr)
Free a header cache.
static struct HeaderCache * hcache_new(void)
Create a new header cache.
static void email_unpack_flags(struct Email *e, uint32_t packed)
Unpack the Email flags from a uint32_t.
static bool create_hcache_dir(const char *path)
Create parent dirs for the hcache database.
struct HeaderCache * hcache_open(const char *path, const char *folder, hcache_namer_t namer, bool create)
Multiplexor for StoreOps::open.
static void email_unpack_timezone(struct Email *e, uint32_t packed)
Unpack the Email timezone from a uint32_t.
int hcache_delete_email(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
void hcache_close(struct HeaderCache **ptr)
Multiplexor for StoreOps::close.
static void free_raw(struct HeaderCache *hc, void **data)
Multiplexor for StoreOps::free.
static void * dump_email(struct HeaderCache *hc, const struct Email *e, int *off, uint32_t uidvalidity)
Serialise an Email object.
struct HCacheEntry hcache_fetch_email(struct HeaderCache *hc, const char *key, size_t keylen, uint32_t uidvalidity)
Multiplexor for StoreOps::fetch.
static uint32_t email_pack_flags(const struct Email *e)
Pack the Email flags into a uint32_t.
static unsigned int generate_hcachever(void)
Calculate hcache version from dynamic configuration.
static uint32_t email_pack_timezone(const struct Email *e)
Pack the Email timezone into a uint32_t.
int hcache_store_email(struct HeaderCache *hc, const char *key, size_t keylen, struct Email *e, uint32_t uidvalidity)
Multiplexor for StoreOps::store.
char * hcache_fetch_raw_str(struct HeaderCache *hc, const char *key, size_t keylen)
Fetch a string from the cache.
bool hcache_fetch_raw_obj_full(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 hcache_delete_raw(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
static struct RealKey * realkey(struct HeaderCache *hc, const char *key, size_t keylen, bool compress)
Compute the real key used in the backend, taking into account the compression method.
static size_t header_size(void)
Compute the size of the header with uuid validity and crc.
int hcache_store_raw(struct HeaderCache *hc, const char *key, size_t keylen, void *data, size_t dlen)
Store a key / data pair.
static void hcache_per_folder(struct HeaderCache *hc, struct Buffer *hcpath, const char *path, hcache_namer_t namer)
Generate the hcache pathname.
static char * get_foldername(const char *folder)
Where should the cache be stored?
void(* hcache_namer_t)(const char *path, struct Buffer *dest)
@ 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.
#define MUTT_MEM_CALLOC(n, type)
#define MUTT_MEM_MALLOC(n, type)
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_FOREACH(var, head, field)
unsigned char * serial_dump_body(const struct Body *b, unsigned char *d, int *off, bool convert)
Pack an Body into a binary blob.
unsigned char * serial_dump_tags(const struct TagList *tl, unsigned char *d, int *off)
Pack a TagList into a binary blob.
void serial_restore_tags(struct TagList *tl, const unsigned char *d, int *off)
Unpack a TagList from a binary blob.
unsigned char * serial_dump_uint64_t(const uint64_t s, unsigned char *d, int *off)
Pack a uint64_t into a binary blob.
unsigned char * serial_dump_int(const unsigned int i, unsigned char *d, int *off)
Pack an integer into 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_envelope(const struct Envelope *env, unsigned char *d, int *off, bool convert)
Pack an Envelope into a binary blob.
void serial_restore_uint64_t(uint64_t *s, const unsigned char *d, int *off)
Unpack an uint64_t from a binary blob.
void serial_restore_body(struct Body *b, const unsigned char *d, int *off, bool convert)
Unpack a Body from a binary blob.
unsigned char * serial_dump_uint32_t(const uint32_t s, unsigned char *d, int *off)
Pack a uint32_t into a binary blob.
void serial_restore_int(unsigned int *i, const unsigned char *d, int *off)
Unpack an integer from 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.
ComprHandle *(* open)(short level)
const char * name
Compression name.
void *(* compress)(ComprHandle *handle, const char *data, size_t dlen, size_t *clen)
void(* close)(ComprHandle **ptr)
The envelope/body of an email.
unsigned int zminutes
Minutes away from UTC.
struct Envelope * env
Envelope information.
bool mime
Has a MIME-Version header?
int lines
How many lines in the body of this message?
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib....
struct Body * body
List of MIME parts.
bool old
Email is seen, but unread.
bool zoccident
True, if west of UTC, False if east.
bool flagged
Marked important?
unsigned int zhours
Hours away from UTC.
time_t date_sent
Time when the message was sent (UTC)
bool replied
Email has been replied to.
bool expired
Already expired?
struct TagList tags
For drivers that support server tagging.
char * path
Path of Email (for local Mailboxes)
bool trash
Message is marked as trashed on disk (used by the maildir_trash option)
bool superseded
Got superseded?
time_t received
Time when the message was placed in the mailbox.
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)
size_t keylen
Length of key.
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(* close)(StoreHandle **ptr)
int(* store)(StoreHandle *store, const char *key, size_t klen, void *value, size_t vlen)
const char * name
Store name.
int(* delete_record)(StoreHandle *store, const char *key, size_t klen)
StoreHandle *(* open)(const char *path, bool create)
void *(* fetch)(StoreHandle *store, const char *key, size_t klen, size_t *vlen)
void(* free)(StoreHandle *store, void **ptr)