}
/* This function transforms a header into a char so that it is useable by
- * db_store */
+ * db_store.
+ */
static void *
mutt_hcache_dump(header_cache_t *h, HEADER * header, int *off,
- unsigned int uidvalidity)
+ unsigned int uidvalidity, mutt_hcache_store_flags_t flags)
{
unsigned char *d = NULL;
HEADER nh;
*off = 0;
d = lazy_malloc(sizeof (validate));
- if (uidvalidity)
- memcpy(d, &uidvalidity, sizeof (uidvalidity));
- else
+ if (flags & M_GENERATE_UIDVALIDITY)
{
struct timeval now;
gettimeofday(&now, NULL);
memcpy(d, &now, sizeof (struct timeval));
}
+ else
+ memcpy(d, &uidvalidity, sizeof (uidvalidity));
*off += sizeof (validate);
d = dump_int(h->crc, d, off);
#endif
}
+/*
+ * flags
+ *
+ * M_GENERATE_UIDVALIDITY
+ * ignore uidvalidity param and store gettimeofday() as the value
+ */
int
mutt_hcache_store(header_cache_t *h, const char *filename, HEADER * header,
unsigned int uidvalidity,
- size_t(*keylen) (const char *fn))
+ size_t(*keylen) (const char *fn),
+ mutt_hcache_store_flags_t flags)
{
char* data;
int dlen;
if (!h)
return -1;
- data = mutt_hcache_dump(h, header, &dlen, uidvalidity);
+ data = mutt_hcache_dump(h, header, &dlen, uidvalidity, flags);
ret = mutt_hcache_store_raw (h, filename, data, dlen, keylen);
FREE(&data);
void *mutt_hcache_fetch(header_cache_t *h, const char *filename, size_t (*keylen)(const char *fn));
void *mutt_hcache_fetch_raw (header_cache_t *h, const char *filename,
size_t (*keylen)(const char *fn));
+
+typedef enum {
+ M_GENERATE_UIDVALIDITY = 1 /* use gettimeofday() as value */
+} mutt_hcache_store_flags_t;
+
/* uidvalidity is an IMAP-specific unsigned 32 bit number */
int mutt_hcache_store(header_cache_t *h, const char *filename, HEADER *header,
- unsigned int uidvalidity, size_t (*keylen)(const char *fn));
+ unsigned int uidvalidity, size_t (*keylen)(const char *fn), mutt_hcache_store_flags_t flags_t);
int mutt_hcache_store_raw (header_cache_t *h, const char* filename, void* data,
size_t dlen, size_t(*keylen) (const char* fn));
int mutt_hcache_delete(header_cache_t *h, const char *filename, size_t (*keylen)(const char *fn));
sprintf (key, "/%u", HEADER_DATA (h)->uid);
return mutt_hcache_store (idata->hcache, key, h, idata->uid_validity,
- imap_hcache_keylen);
+ imap_hcache_keylen, 0);
}
int imap_hcache_del (IMAP_DATA* idata, unsigned int uid)
p->header_parsed = 1;
#if USE_HCACHE
if (ctx->magic == M_MH)
- mutt_hcache_store (hc, p->h->path, p->h, 0, strlen);
+ mutt_hcache_store (hc, p->h->path, p->h, 0, strlen, M_GENERATE_UIDVALIDITY);
else
- mutt_hcache_store (hc, p->h->path + 3, p->h, 0, &maildir_hcache_keylen);
+ mutt_hcache_store (hc, p->h->path + 3, p->h, 0, &maildir_hcache_keylen, M_GENERATE_UIDVALIDITY);
#endif
} else
mutt_free_header (&p->h);
{
if (ctx->magic == M_MAILDIR)
mutt_hcache_store (hc, ctx->hdrs[i]->path + 3, ctx->hdrs[i],
- 0, &maildir_hcache_keylen);
+ 0, &maildir_hcache_keylen, M_GENERATE_UIDVALIDITY);
else if (ctx->magic == M_MH)
- mutt_hcache_store (hc, ctx->hdrs[i]->path, ctx->hdrs[i], 0, strlen);
+ mutt_hcache_store (hc, ctx->hdrs[i]->path, ctx->hdrs[i], 0, strlen, M_GENERATE_UIDVALIDITY);
}
#endif
#if USE_HCACHE
else
{
- mutt_hcache_store (hc, ctx->hdrs[i]->data, ctx->hdrs[i], 0, strlen);
+ mutt_hcache_store (hc, ctx->hdrs[i]->data, ctx->hdrs[i], 0, strlen, M_GENERATE_UIDVALIDITY);
}
FREE(&data);
#if USE_HCACHE
if (ctx->hdrs[i]->changed)
{
- mutt_hcache_store (hc, ctx->hdrs[i]->data, ctx->hdrs[i], 0, strlen);
+ mutt_hcache_store (hc, ctx->hdrs[i]->data, ctx->hdrs[i], 0, strlen, M_GENERATE_UIDVALIDITY);
}
#endif