]> granicus.if.org Git - mutt/commitdiff
use a separate flag for mutt_hcache_store() to signal that the gettimeofday() value...
authorMichael Elkins <me@sigpipe.org>
Thu, 17 Jan 2013 02:43:41 +0000 (02:43 +0000)
committerMichael Elkins <me@sigpipe.org>
Thu, 17 Jan 2013 02:43:41 +0000 (02:43 +0000)
closes #3501

hcache.c
hcache.h
imap/util.c
mh.c
pop.c

index f6e091b09534e3c4d65122b037d3d1b23f0e8ff3..af17932dc3f3a7c399f95880e4784a07ad4d8a2e 100644 (file)
--- a/hcache.c
+++ b/hcache.c
@@ -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);
index aab263bc6e086812add3690e88063eab5e024fd5..62eaa18b93a91d23ee527b71024bec618ce6a442 100644 (file)
--- a/hcache.h
+++ b/hcache.h
@@ -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));
index 7515088b6c187852266870a5574ca37f40cdb83c..657a2fb92b5a002ab8c28ca02fcbaa2f959fb277 100644 (file)
@@ -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)
diff --git a/mh.c b/mh.c
index 21f516bb2c8ca8361f2ae75d8f9df24b98ce3eb2..7a8d7756f09c923de27ccf466a31dd73f4272acb 100644 (file)
--- a/mh.c
+++ b/mh.c
@@ -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
 
diff --git a/pop.c b/pop.c
index 9fa655432ba8484be368d454be038df19f4c65d0..85c34d1d65cebaf09b98c3f4b13e3077e0d03777 100644 (file)
--- a/pop.c
+++ b/pop.c
@@ -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