From 136b6fd4661b96d13d5ef449a7afcfe220735b6d Mon Sep 17 00:00:00 2001 From: Brendan Cully Date: Tue, 10 Apr 2007 16:07:53 -0700 Subject: [PATCH] Do not hold hcache open while mailbox is open - it can lead to lockups --- ChangeLog | 7 ++++++- imap/imap.c | 24 +++++++++++++++++------- imap/imap_private.h | 3 ++- imap/message.c | 8 ++++++++ imap/util.c | 19 +++++++++++++++---- 5 files changed, 48 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2c43d7bb1..af8e82530 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,9 @@ -2007-04-10 13:46 -0700 Brendan Cully (d3e0d6c60d87) +2007-04-10 15:32 -0700 Brendan Cully (c38765da3fe8) + + * imap/command.c, imap/imap.c, imap/imap_private.h, imap/util.c: Add + imap_hcache_del; minor cleanups + + * main.c: Fix a compiler warning * rfc3676.c: Don't use $indent_string to quote replies to flowed messages (closes #2874). diff --git a/imap/imap.c b/imap/imap.c index aeec066d4..03d7298f2 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -248,6 +248,10 @@ void imap_expunge_mailbox (IMAP_DATA* idata) HEADER* h; int i, cacheno; +#ifdef USE_HCACHE + imap_hcache_open (idata); +#endif + for (i = 0; i < idata->ctx->msgcount; i++) { h = idata->ctx->hdrs[i]; @@ -277,6 +281,10 @@ void imap_expunge_mailbox (IMAP_DATA* idata) } } +#if USE_HCACHE + imap_hcache_close (idata); +#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); @@ -734,9 +742,7 @@ int imap_open_mailbox (CONTEXT* ctx) ctx->hdrs = safe_calloc (count, sizeof (HEADER *)); ctx->v2r = safe_calloc (count, sizeof (int)); ctx->msgcount = 0; -#ifdef USE_HCACHE - idata->hcache = imap_hcache_open (idata, idata->ctx->path); -#endif + if (count && (imap_read_headers (idata, 0, count-1) < 0)) { mutt_error _("Error opening mailbox"); @@ -1139,6 +1145,10 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint) } } +#if USE_HCACHE + imap_hcache_open (idata); +#endif + /* save messages with real (non-flag) changes */ for (n = 0; n < ctx->msgcount; n++) { @@ -1174,6 +1184,10 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint) } } +#if USE_HCACHE + imap_hcache_close (idata); +#endif + /* sync +/- flags for the five flags mutt cares about */ rc = 0; @@ -1307,10 +1321,6 @@ int imap_close_mailbox (CONTEXT* ctx) } } -#ifdef USE_HCACHE - mutt_hcache_close (idata->hcache); - idata->hcache = NULL; -#endif mutt_bcache_close (&idata->bcache); return 0; diff --git a/imap/imap_private.h b/imap/imap_private.h index b28e5ae30..410f6bff0 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -259,7 +259,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); +int imap_hcache_open (IMAP_DATA* idata); +void imap_hcache_close (IMAP_DATA* idata); HEADER* imap_hcache_get (IMAP_DATA* idata, unsigned int uid); int imap_hcache_put (IMAP_DATA* idata, HEADER* h); int imap_hcache_del (IMAP_DATA* idata, unsigned int uid); diff --git a/imap/message.c b/imap/message.c index 2b8f2c46c..d2fe9890d 100644 --- a/imap/message.c +++ b/imap/message.c @@ -119,6 +119,8 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) idata->newMailCount = 0; #if USE_HCACHE + imap_hcache_open (idata); + if (idata->hcache && !msgbegin) { uid_validity = mutt_hcache_fetch_raw (idata->hcache, "/UIDVALIDITY", imap_hcache_keylen); @@ -199,6 +201,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) { if (h.data) imap_free_header_data ((void**) (void*) &h.data); + imap_hcache_close (idata); fclose (fp); return -1; } @@ -300,6 +303,9 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) { if (h.data) imap_free_header_data ((void**) (void*) &h.data); +#if USE_HCACHE + imap_hcache_close (idata); +#endif fclose (fp); return -1; } @@ -329,6 +335,8 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) if (idata->uidnext > 1) mutt_hcache_store_raw (idata->hcache, "/UIDNEXT", &idata->uidnext, sizeof (idata->uidnext), imap_hcache_keylen); + + imap_hcache_close (idata); #endif /* USE_HCACHE */ fclose(fp); diff --git a/imap/util.c b/imap/util.c index c62414685..2a278704e 100644 --- a/imap/util.c +++ b/imap/util.c @@ -71,21 +71,32 @@ int imap_expand_path (char* path, size_t len) } #ifdef USE_HCACHE -header_cache_t* imap_hcache_open (IMAP_DATA* idata, const char* path) +int imap_hcache_open (IMAP_DATA* idata) { IMAP_MBOX mx; ciss_url_t url; char cachepath[LONG_STRING]; - if (imap_parse_path (path, &mx) < 0) - return NULL; + if (imap_parse_path (idata->ctx->path, &mx) < 0) + return -1; mutt_account_tourl (&idata->conn->account, &url); url.path = mx.mbox; url_ciss_tostring (&url, cachepath, sizeof (cachepath), 0); FREE (&mx.mbox); - return mutt_hcache_open (HeaderCache, cachepath); + idata->hcache = mutt_hcache_open (HeaderCache, cachepath); + + return idata->hcache != NULL ? 0 : -1; +} + +void imap_hcache_close (IMAP_DATA* idata) +{ + if (!idata->hcache) + return; + + mutt_hcache_close (idata->hcache); + idata->hcache = NULL; } HEADER* imap_hcache_get (IMAP_DATA* idata, unsigned int uid) -- 2.50.1