diff options
-rw-r--r-- | hcache.c | 22 | ||||
-rw-r--r-- | hcache.h | 7 | ||||
-rw-r--r-- | imap/util.c | 2 | ||||
-rw-r--r-- | mh.c | 8 | ||||
-rw-r--r-- | pop.c | 4 |
5 files changed, 28 insertions, 15 deletions
@@ -588,10 +588,11 @@ mutt_hcache_per_folder(const char *path, const char *folder, } /* 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; @@ -600,14 +601,14 @@ mutt_hcache_dump(header_cache_t *h, HEADER * header, int *off, *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); @@ -759,10 +760,17 @@ mutt_hcache_fetch_raw (header_cache_t *h, const char *filename, #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; @@ -771,7 +779,7 @@ mutt_hcache_store(header_cache_t *h, const char *filename, HEADER * header, 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); @@ -33,9 +33,14 @@ HEADER *mutt_hcache_restore(const unsigned char *d, HEADER **oh); 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)); diff --git a/imap/util.c b/imap/util.c index 7515088b..657a2fb9 100644 --- a/imap/util.c +++ b/imap/util.c @@ -145,7 +145,7 @@ int imap_hcache_put (IMAP_DATA* idata, HEADER* h) 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) @@ -1080,9 +1080,9 @@ static void maildir_delayed_parsing (CONTEXT * ctx, struct maildir **md, 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); @@ -1714,9 +1714,9 @@ int mh_sync_mailbox (CONTEXT * ctx, int *index_hint) { 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 @@ -324,7 +324,7 @@ static int pop_fetch_headers (CONTEXT *ctx) #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); @@ -693,7 +693,7 @@ int pop_sync_mailbox (CONTEXT *ctx, int *index_hint) #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 |