From 4c274a02970e78d84eda798e07d2d7dc89cc9589 Mon Sep 17 00:00:00 2001 From: Brendan Cully Date: Tue, 10 Apr 2007 15:32:08 -0700 Subject: [PATCH] Add imap_hcache_del; minor cleanups --- imap/command.c | 3 --- imap/imap.c | 22 +++++----------------- imap/imap_private.h | 1 + imap/util.c | 21 +++++++++++++++++++-- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/imap/command.c b/imap/command.c index 329155208..c67066e0d 100644 --- a/imap/command.c +++ b/imap/command.c @@ -30,9 +30,6 @@ #include "message.h" #include "mx.h" #include "buffy.h" -#if USE_HCACHE -#include "hcache.h" -#endif #include #include diff --git a/imap/imap.c b/imap/imap.c index c68f361eb..aeec066d4 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -248,10 +248,6 @@ void imap_expunge_mailbox (IMAP_DATA* idata) HEADER* h; int i, cacheno; -#if USE_HCACHE - char uidbuf[32]; -#endif - for (i = 0; i < idata->ctx->msgcount; i++) { h = idata->ctx->hdrs[i]; @@ -265,11 +261,7 @@ void imap_expunge_mailbox (IMAP_DATA* idata) imap_cache_del (idata, h); #if USE_HCACHE - if (idata->hcache) - { - sprintf (uidbuf, "/%u", HEADER_DATA(h)->uid); - mutt_hcache_delete (idata->hcache, uidbuf, imap_hcache_keylen); - } + imap_hcache_del (idata, HEADER_DATA(h)->uid); #endif /* free cached body from disk, if necessary */ @@ -1103,9 +1095,6 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint) int deleted; int n; int rc; -#if USE_HCACHE - char uidbuf[32]; -#endif idata = (IMAP_DATA*) ctx->data; @@ -1156,14 +1145,13 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint) h = ctx->hdrs[n]; if (h->deleted) + { imap_cache_del (idata, h); #if USE_HCACHE - if (idata->hcache && h->deleted) - { - sprintf (uidbuf, "/%u", HEADER_DATA(h)->uid); - mutt_hcache_delete (idata->hcache, uidbuf, imap_hcache_keylen); - } + imap_hcache_del (idata, HEADER_DATA(h)->uid); #endif + } + if (h->active && h->changed) { /* if the message has been rethreaded or attachments have been deleted diff --git a/imap/imap_private.h b/imap/imap_private.h index efa6ea77c..b28e5ae30 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -262,6 +262,7 @@ int imap_cache_del (IMAP_DATA* idata, HEADER* h); 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); +int imap_hcache_del (IMAP_DATA* idata, unsigned int uid); #endif int imap_continue (const char* msg, const char* resp); diff --git a/imap/util.c b/imap/util.c index e55c7bb37..c62414685 100644 --- a/imap/util.c +++ b/imap/util.c @@ -94,7 +94,10 @@ HEADER* imap_hcache_get (IMAP_DATA* idata, unsigned int uid) unsigned int* uv; HEADER* h = NULL; - sprintf(key, "/%u", uid); + if (!idata->hcache) + return NULL; + + sprintf (key, "/%u", uid); uv = (unsigned int*)mutt_hcache_fetch (idata->hcache, key, imap_hcache_keylen); if (uv) @@ -111,10 +114,24 @@ int imap_hcache_put (IMAP_DATA* idata, HEADER* h) { char key[16]; - sprintf(key, "/%u", HEADER_DATA (h)->uid); + if (!idata->hcache) + return -1; + + sprintf (key, "/%u", HEADER_DATA (h)->uid); return mutt_hcache_store (idata->hcache, key, h, idata->uid_validity, imap_hcache_keylen); } + +int imap_hcache_del (IMAP_DATA* idata, unsigned int uid) +{ + char key[16]; + + if (!idata->hcache) + return -1; + + sprintf (key, "/%u", uid); + return mutt_hcache_delete (idata->hcache, key, imap_hcache_keylen); +} #endif /* imap_parse_path: given an IMAP mailbox name, return host, port -- 2.40.0