From bcbed8b1f40dcb381260e68fbaa3aeb59d9304d3 Mon Sep 17 00:00:00 2001 From: Brendan Cully Date: Thu, 5 Apr 2007 18:03:05 -0700 Subject: [PATCH] IMAP header cache API improvements. --- imap/imap_private.h | 2 ++ imap/message.c | 13 +++---------- imap/util.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/imap/imap_private.h b/imap/imap_private.h index d7bde1d9b..efa6ea77c 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -260,6 +260,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); +HEADER* imap_hcache_get (IMAP_DATA* idata, unsigned int uid); +int imap_hcache_put (IMAP_DATA* idata, HEADER* h); #endif int imap_continue (const char* msg, const char* resp); diff --git a/imap/message.c b/imap/message.c index 83d9b7773..c034393f9 100644 --- a/imap/message.c +++ b/imap/message.c @@ -78,7 +78,6 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) unsigned int *uid_validity = NULL; unsigned int *uidnext = NULL; int evalhc = 0; - char uid_buf[64]; #endif /* USE_HCACHE */ ctx = idata->ctx; @@ -168,12 +167,9 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) } idx = h.sid - 1; - sprintf(uid_buf, "/%u", h.data->uid); /* XXX --tg 21:41 04-07-11 */ - uid_validity = (unsigned int*)mutt_hcache_fetch (idata->hcache, uid_buf, &imap_hcache_keylen); - - if (uid_validity != NULL && *uid_validity == idata->uid_validity) + ctx->hdrs[idx] = imap_hcache_get (idata, h.data->uid); + if (ctx->hdrs[idx]) { - ctx->hdrs[idx] = mutt_hcache_restore((unsigned char *) uid_validity, 0); ctx->hdrs[idx]->index = idx; /* messages which have not been expunged are ACTIVE (borrowed from mh * folders) */ @@ -194,8 +190,6 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) /* bad header in the cache, we'll have to refetch. * TODO: consider the possibility of a holey cache. */ imap_free_header_data((void**) &h.data); - - FREE(&uid_validity); } while (rc != IMAP_CMD_OK && mfhrc == -1); if (rc == IMAP_CMD_OK) @@ -293,8 +287,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) ctx->size += h.content_length; #if USE_HCACHE - sprintf(uid_buf, "/%u", h.data->uid); - mutt_hcache_store(idata->hcache, uid_buf, ctx->hdrs[idx], idata->uid_validity, &imap_hcache_keylen); + imap_hcache_put (idata, ctx->hdrs[idx]); #endif /* USE_HCACHE */ ctx->msgcount++; diff --git a/imap/util.c b/imap/util.c index 9499c176c..e55c7bb37 100644 --- a/imap/util.c +++ b/imap/util.c @@ -28,6 +28,7 @@ #include "imap_private.h" #include "mutt_ssl.h" #ifdef USE_HCACHE +#include "message.h" #include "hcache.h" #endif @@ -86,6 +87,34 @@ header_cache_t* imap_hcache_open (IMAP_DATA* idata, const char* path) return mutt_hcache_open (HeaderCache, cachepath); } + +HEADER* imap_hcache_get (IMAP_DATA* idata, unsigned int uid) +{ + char key[16]; + unsigned int* uv; + HEADER* h = NULL; + + sprintf(key, "/%u", uid); + uv = (unsigned int*)mutt_hcache_fetch (idata->hcache, key, + imap_hcache_keylen); + if (uv) + { + if (*uv == idata->uid_validity) + h = mutt_hcache_restore ((unsigned char*)uv, NULL); + FREE (&uv); + } + + return h; +} + +int imap_hcache_put (IMAP_DATA* idata, HEADER* h) +{ + char key[16]; + + sprintf(key, "/%u", HEADER_DATA (h)->uid); + return mutt_hcache_store (idata->hcache, key, h, idata->uid_validity, + imap_hcache_keylen); +} #endif /* imap_parse_path: given an IMAP mailbox name, return host, port -- 2.50.1