From: Brendan Cully Date: Wed, 11 Apr 2007 03:22:06 +0000 (-0700) Subject: Add $message_cache_clean option to prune message cache on sync X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=61ecfbf48cbb0eee54b12a3e9eeb1b9009be2c55;p=neomutt Add $message_cache_clean option to prune message cache on sync --- diff --git a/ChangeLog b/ChangeLog index 4e51651e3..0541c2ea8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,8 @@ -2007-04-10 19:19 -0700 Brendan Cully (ddd38b4cf15c) +2007-04-10 19:28 -0700 Brendan Cully (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 diff --git a/UPDATING b/UPDATING index f37d8982e..42dcfc144 100644 --- 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) diff --git a/imap/imap.c b/imap/imap.c index 4030c9131..29c5f8f17 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -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); diff --git a/imap/imap_private.h b/imap/imap_private.h index 98adc8b2c..75f1429fc 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -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 diff --git a/imap/message.c b/imap/message.c index 0cd3e50e2..10ebd0fbc 100644 --- a/imap/message.c +++ b/imap/message.c @@ -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 118082567..0801cd1aa 100644 --- 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 90cacf97b..5930e1454 100644 --- 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,