52#include "hcache/hcversion.h"
57#if !(defined(HAVE_GDBM) || defined(HAVE_LMDB) || defined(HAVE_ROCKSDB) || defined(HAVE_TDB))
58#error "No hcache backend defined"
79 size_t keylen,
bool compress)
88#ifdef USE_HCACHE_COMPRESSION
132 return sizeof(int) +
sizeof(uint32_t);
173 e->
security = (packed & ((1 << 16) - 1));
174 e->
expired = (packed & (1 << 16));
175 e->
flagged = (packed & (1 << 17));
176 e->
mime = (packed & (1 << 18));
177 e->
old = (packed & (1 << 19));
178 e->
read = (packed & (1 << 20));
179 e->
replied = (packed & (1 << 21));
181 e->
trash = (packed & (1 << 23));
213 e->
zhours = (packed & ((1 << 5) - 1));
214 e->
zminutes = ((packed >> 5) & ((1 << 6) - 1));
276 off +=
sizeof(uint32_t);
277 off +=
sizeof(
unsigned int);
295 unsigned int num = 0;
321 char *p = strrchr(dir,
'/');
332 mutt_error(
_(
"Can't create %s: %s"), dir, strerror(errno));
362 struct stat st = { 0 };
365 int rc = stat(path, &st);
366 bool slash = (path[plen - 1] ==
'/');
368 if (((rc == 0) && !S_ISDIR(st.st_mode)) || ((rc == -1) && !slash))
389#ifdef USE_HCACHE_COMPRESSION
417 if (!realpath(folder, p))
439 unsigned char charval[16];
442 struct Md5Ctx md5ctx = { 0 };
447 unsigned int ver = HCACHEVER;
471 return digest.intval;
480 if (!path || (path[0] ==
'\0'))
500#ifdef USE_HCACHE_COMPRESSION
502 if (c_header_cache_compress_method)
556#ifdef USE_HCACHE_COMPRESSION
578 void *data = hc->store_ops->fetch(hc->store_handle, rk->
key, rk->
keylen, &dlen);
579 void *to_free = data;
594 ASSERT((
size_t) off == hlen);
595 if ((hce.
crc != hc->
crc) || ((uidvalidity != 0) && (uidvalidity != hce.
uidvalidity)))
600#ifdef USE_HCACHE_COMPRESSION
603 void *dblob = hc->compr_ops->decompress(hc->compr_handle,
604 (
char *) data + hlen, dlen - hlen);
609 data = (
char *) dblob - hlen;
631 size_t keylen,
void *dst,
size_t dstlen)
642 if (src && (srclen == dstlen))
644 memcpy(dst, src, dstlen);
684 struct Email *e, uint32_t uidvalidity)
690 char *data =
dump_email(hc, e, &dlen, uidvalidity);
692#ifdef USE_HCACHE_COMPRESSION
709 memcpy(whole, data, hlen);
710 memcpy(whole + hlen, cdata, clen);
738 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.
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 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?
Header cache multiplexor.
void(* hcache_namer_t)(const struct StoreOps *store_ops, const char *path, struct Buffer *dest)
Hcache private Module data.
@ LL_DEBUG3
Log at debug level 3.
void * mutt_md5(const char *str, void *buf)
Calculate the MD5 hash of a NUL-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 NUL-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 FREE(x)
Free memory and set the pointer to NULL.
#define MIN(a, b)
Return the minimum of two values.
#define MUTT_MEM_CALLOC(n, type)
#define MUTT_MEM_MALLOC(n, type)
@ MODULE_ID_EMAIL
ModuleEmail, Email code
@ MODULE_ID_HCACHE
ModuleHcache, Email Header Cache
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.
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
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)
Email private Module data.
struct ReplaceList spam
Regexes and patterns to match spam emails.
struct RegexList no_spam
Regexes to identify non-spam emails.
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.
Hcache private Module data.
unsigned int hcache_ver
Header Cache version.
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)