]> granicus.if.org Git - mutt/commitdiff
Add $message_cache_clean option to prune message cache on sync
authorBrendan Cully <brendan@kublai.com>
Wed, 11 Apr 2007 03:22:06 +0000 (20:22 -0700)
committerBrendan Cully <brendan@kublai.com>
Wed, 11 Apr 2007 03:22:06 +0000 (20:22 -0700)
ChangeLog
UPDATING
imap/imap.c
imap/imap_private.h
imap/message.c
init.h
mutt.h

index 4e51651e300d7298ff774e2294f0bbf98f707ed8..0541c2ea844b30f5e38653ab76aebcd5e53c374c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,8 @@
-2007-04-10 19:19 -0700  Brendan Cully  <brendan@kublai.com>  (ddd38b4cf15c)
+2007-04-10 19:28 -0700  Brendan Cully  <brendan@kublai.com>  (d12143e1a610)
+
+       * hcache.c: Try to unlink old header cache if open fails
+
+       * bcache.c, imap/imap.c, imap/util.c, lib.c: Fix some warnings
 
        * hcache.c: Refactor mutt_hcache_open to share more code
 
index f37d8982e548a17c425136411e2b78946c8bafd8..42dcfc14452ace8e30a2ff057f5d08e96817f10f 100644 (file)
--- a/UPDATING
+++ b/UPDATING
@@ -4,6 +4,8 @@ mutt. Please read this file carefully when upgrading your installation.
 The keys used are:
   !: modified feature, -: deleted feature, +: new feature
 
+  + $message_cache_clean (clean cache on sync)
+
 1.5.15 (2007-04-06)
 
   - $imap_home_namespace (useless clutter)
index 4030c913113a8bd038030004177cc9b19c441248..29c5f8f178a715c39849701c7590a368f0cc9378 100644 (file)
@@ -1261,7 +1261,11 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint)
     idata->state = IMAP_AUTHENTICATED;
   }
 
+  if (option (OPTMESSAGECACHECLEAN))
+    imap_cache_clean (idata);
+
   rc = 0;
+
  out:
   if (cmd.data)
     FREE (&cmd.data);
index 98adc8b2ced029fbbcec6771d476b871aac6769e..75f1429fc9a32621192fd3740c4a1a8f517f9886 100644 (file)
@@ -256,6 +256,7 @@ void imap_free_header_data (void** data);
 int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend);
 char* imap_set_flags (IMAP_DATA* idata, HEADER* h, char* s);
 int imap_cache_del (IMAP_DATA* idata, HEADER* h);
+int imap_cache_clean (IMAP_DATA* idata);
 
 /* util.c */
 #ifdef USE_HCACHE
index 0cd3e50e220884be36e85fe26d6df9fb1655c7cc..10ebd0fbc3e87b6e0128707364172d56bc02c434 100644 (file)
@@ -906,6 +906,37 @@ int imap_cache_del (IMAP_DATA* idata, HEADER* h)
   return mutt_bcache_del (idata->bcache, id);
 }
 
+static int msg_cache_clean_cb (const char* id, body_cache_t* bcache, void* data)
+{
+  unsigned int uv, uid, n;
+  IMAP_DATA* idata = (IMAP_DATA*)data;
+
+  if (sscanf (id, "%u-%u", &uv, &uid) != 2)
+    return 0;
+
+  /* bad UID */
+  if (uv != idata->uid_validity)
+    mutt_bcache_del (bcache, id);
+
+  /* TODO: presort UIDs, walk in order */
+  for (n = 0; n < idata->ctx->msgcount; n++)
+  {
+    if (uid == HEADER_DATA(idata->ctx->hdrs[n])->uid)
+      return 0;
+  }
+  mutt_bcache_del (bcache, id);
+
+  return 0;
+}
+
+int imap_cache_clean (IMAP_DATA* idata)
+{
+  idata->bcache = msg_cache_open (idata);
+  mutt_bcache_list (idata->bcache, msg_cache_clean_cb, idata);
+
+  return 0;
+}
+
 /* imap_add_keywords: concatenate custom IMAP tags to list, if they
  *   appear in the folder flags list. Why wouldn't they? */
 void imap_add_keywords (char* s, HEADER* h, LIST* mailbox_flags, size_t slen)
diff --git a/init.h b/init.h
index 1180825676631f14137ab934dd3b5e8bb47a19ac..0801cd1aaac0f94bb0ad63c5435883926eee3ae9 100644 (file)
--- a/init.h
+++ b/init.h
@@ -1295,6 +1295,13 @@ struct option_t MuttVars[] = {
   ** time, for instance if stale entries accumulate because you have
   ** deleted messages with another mail client.
   */
+  { "message_cache_clean", DT_BOOL, R_NONE, OPTMESSAGECACHECLEAN, 0 },
+  /*
+  ** .pp
+  ** If set, mutt will clean out obsolete entries from the cache when
+  ** the mailbox is synchronized. You probably only want to set it
+  ** every once in a while, since it can be a little slow.
+  */
 #endif
   { "message_format",  DT_STR,  R_NONE, UL &MsgFmt, UL "%s" },
   /*
diff --git a/mutt.h b/mutt.h
index 90cacf97b7a13419ac81e9445e09187b157920e1..5930e145433b5f0feb5b9caf47d20eb8e89a2d6f 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -400,6 +400,9 @@ enum
   OPTMARKOLD,
   OPTMENUSCROLL,       /* scroll menu instead of implicit next-page */
   OPTMENUMOVEOFF,      /* allow menu to scroll past last entry */
+#if defined(USE_IMAP) || defined(USE_POP)
+  OPTMESSAGECACHECLEAN,
+#endif
   OPTMETAKEY,          /* interpret ALT-x as ESC-x */
   OPTMETOO,
   OPTMHPURGE,