]> granicus.if.org Git - neomutt/commitdiff
IMAP header cache API improvements.
authorBrendan Cully <brendan@kublai.com>
Fri, 6 Apr 2007 01:03:05 +0000 (18:03 -0700)
committerBrendan Cully <brendan@kublai.com>
Fri, 6 Apr 2007 01:03:05 +0000 (18:03 -0700)
imap/imap_private.h
imap/message.c
imap/util.c

index d7bde1d9b8e50a4c9e8dc53f522b9ee48daa75e7..efa6ea77caafa9908f55614575dce6a750c6a60a 100644 (file)
@@ -260,6 +260,8 @@ int imap_cache_del (IMAP_DATA* idata, HEADER* h);
 /* util.c */
 #ifdef USE_HCACHE
 header_cache_t* imap_hcache_open (IMAP_DATA* idata, const char* path);
+HEADER* imap_hcache_get (IMAP_DATA* idata, unsigned int uid);
+int imap_hcache_put (IMAP_DATA* idata, HEADER* h);
 #endif
 
 int imap_continue (const char* msg, const char* resp);
index 83d9b7773efaeecab830eefc7454ff4c7111e0bc..c034393f9e396103dee03f3cf4b3de1d4c38914e 100644 (file)
@@ -78,7 +78,6 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
   unsigned int *uid_validity = NULL;
   unsigned int *uidnext = NULL;
   int evalhc = 0;
-  char uid_buf[64];
 #endif /* USE_HCACHE */
 
   ctx = idata->ctx;
@@ -168,12 +167,9 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
        }
 
         idx = h.sid - 1;
-        sprintf(uid_buf, "/%u", h.data->uid); /* XXX --tg 21:41 04-07-11 */
-        uid_validity = (unsigned int*)mutt_hcache_fetch (idata->hcache, uid_buf, &imap_hcache_keylen);
-
-        if (uid_validity != NULL && *uid_validity == idata->uid_validity)
+        ctx->hdrs[idx] = imap_hcache_get (idata, h.data->uid);
+        if (ctx->hdrs[idx])
         {
-         ctx->hdrs[idx] = mutt_hcache_restore((unsigned char *) uid_validity, 0);
          ctx->hdrs[idx]->index = idx;
          /* messages which have not been expunged are ACTIVE (borrowed from mh 
           * folders) */
@@ -194,8 +190,6 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
          /* bad header in the cache, we'll have to refetch.
           * TODO: consider the possibility of a holey cache. */
           imap_free_header_data((void**) &h.data);
-  
-        FREE(&uid_validity);
       }
       while (rc != IMAP_CMD_OK && mfhrc == -1);
       if (rc == IMAP_CMD_OK)
@@ -293,8 +287,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
       ctx->size += h.content_length;
 
 #if USE_HCACHE
-      sprintf(uid_buf, "/%u", h.data->uid);
-      mutt_hcache_store(idata->hcache, uid_buf, ctx->hdrs[idx], idata->uid_validity, &imap_hcache_keylen);
+      imap_hcache_put (idata, ctx->hdrs[idx]);
 #endif /* USE_HCACHE */
 
       ctx->msgcount++;
index 9499c176c38ce88f3b67f6040dca249ace7a13e6..e55c7bb3709bbca1b37e59ad2332d83bea42ce93 100644 (file)
@@ -28,6 +28,7 @@
 #include "imap_private.h"
 #include "mutt_ssl.h"
 #ifdef USE_HCACHE
+#include "message.h"
 #include "hcache.h"
 #endif
 
@@ -86,6 +87,34 @@ header_cache_t* imap_hcache_open (IMAP_DATA* idata, const char* path)
 
   return mutt_hcache_open (HeaderCache, cachepath);
 }
+
+HEADER* imap_hcache_get (IMAP_DATA* idata, unsigned int uid)
+{
+  char key[16];
+  unsigned int* uv;
+  HEADER* h = NULL;
+
+  sprintf(key, "/%u", uid);
+  uv = (unsigned int*)mutt_hcache_fetch (idata->hcache, key,
+                                         imap_hcache_keylen);
+  if (uv)
+  {
+    if (*uv == idata->uid_validity)
+      h = mutt_hcache_restore ((unsigned char*)uv, NULL);
+    FREE (&uv);
+  }
+
+  return h;
+}
+
+int imap_hcache_put (IMAP_DATA* idata, HEADER* h)
+{
+  char key[16];
+
+  sprintf(key, "/%u", HEADER_DATA (h)->uid);
+  return mutt_hcache_store (idata->hcache, key, h, idata->uid_validity,
+                            imap_hcache_keylen);
+}
 #endif
 
 /* imap_parse_path: given an IMAP mailbox name, return host, port