]> granicus.if.org Git - neomutt/commitdiff
More IMAP header cache cleanup: remove expunged entries from cache, and
authorBrendan Cully <brendan@kublai.com>
Mon, 19 Dec 2005 17:40:02 +0000 (17:40 +0000)
committerBrendan Cully <brendan@kublai.com>
Mon, 19 Dec 2005 17:40:02 +0000 (17:40 +0000)
don't bother checking the cache for mail that's arrived since the mailbox
was opened. TODO: cache UIDNEXT, only check the cache for messages up to
cached value.

imap/imap.c
imap/imap_private.h
imap/message.c

index fc9b57484e9a6bacabb364e58c7d74b09c5917ff..d34baf02303991caaa1935c735ce6a2f5bdfafa4 100644 (file)
@@ -238,6 +238,13 @@ void imap_expunge_mailbox (IMAP_DATA* idata)
   HEADER* h;
   int i, cacheno;
 
+#if USE_HCACHE
+  void* hc;
+  char uidbuf[32];
+  
+  hc = mutt_hcache_open (HeaderCache, idata->ctx->path);
+#endif
+
   for (i = 0; i < idata->ctx->msgcount; i++)
   {
     h = idata->ctx->hdrs[i];
@@ -248,7 +255,15 @@ void imap_expunge_mailbox (IMAP_DATA* idata)
 
       h->active = 0;
 
-      /* free cached body from disk, if neccessary */
+#if USE_HCACHE
+      if (hc)
+      {
+        sprintf (uidbuf, "/%u", HEADER_DATA(h)->uid);
+        mutt_hcache_delete (hc, uidbuf, imap_hcache_keylen);
+      }
+#endif
+
+      /* free cached body from disk, if necessary */
       cacheno = HEADER_DATA(h)->uid % IMAP_CACHE_LEN;
       if (idata->cache[cacheno].uid == HEADER_DATA(h)->uid &&
          idata->cache[cacheno].path)
@@ -261,6 +276,10 @@ void imap_expunge_mailbox (IMAP_DATA* idata)
     }
   }
 
+#if USE_HCACHE
+  mutt_hcache_close (hc);
+#endif
+
   /* We may be called on to expunge at any time. We can't rely on the caller
    * to always know to rethread */
   mx_update_tables (idata->ctx, 0);
index 6bd4cd5da30a917323bfa8732651902163dea530..0d01df5d819920a9c0f0650f6a944de8a6d7f5a5 100644 (file)
@@ -287,4 +287,11 @@ int imap_wordcasecmp(const char *a, const char *b);
 void imap_utf7_encode (char **s);
 void imap_utf7_decode (char **s);
 
+#if USE_HCACHE
+static size_t imap_hcache_keylen (const char *fn)
+{
+  return mutt_strlen(fn);
+}
+#endif /* USE_HCACHE */
+
 #endif
index c95d741749dc41b2c073f9aa32546ae61c9fda81..1aee87851571a4c80dd4593f122a1c001922a620 100644 (file)
@@ -42,10 +42,6 @@ static int msg_fetch_header (CONTEXT* ctx, IMAP_HEADER* h, char* buf,
 static int msg_parse_fetch (IMAP_HEADER* h, char* s);
 static char* msg_parse_flags (IMAP_HEADER* h, char* s);
 
-#if USE_HCACHE
-static size_t imap_hcache_keylen (const char *fn);
-#endif /* USE_HCACHE */
-
 /* imap_read_headers:
  * Changed to read many headers instead of just one. It will return the
  * msgno of the last message read. It will return a value other than
@@ -111,7 +107,8 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
   idata->newMailCount = 0;
 
 #if USE_HCACHE
-  hc = mutt_hcache_open (HeaderCache, ctx->path);
+  if (!msgbegin)
+    hc = mutt_hcache_open (HeaderCache, ctx->path);
 
   if (hc) {
     snprintf (buf, sizeof (buf),
@@ -929,13 +926,6 @@ static int msg_fetch_header (CONTEXT* ctx, IMAP_HEADER* h, char* buf, FILE* fp)
   return rc;
 }
 
-#if USE_HCACHE
-static size_t imap_hcache_keylen (const char *fn)
-{
-  return mutt_strlen(fn);
-}
-#endif /* USE_HCACHE */
-
 /* msg_parse_fetch: handle headers returned from header fetch */
 static int msg_parse_fetch (IMAP_HEADER *h, char *s)
 {