diff -Nru a/hcache.c b/hcache.c --- a/hcache.c 2004-09-02 14:27:26 +02:00 +++ b/hcache.c 2004-09-18 13:03:39 +02:00 @@ -37,6 +37,7 @@ #include "mime.h" #include "mx.h" #include "lib.h" +#include "md5.h" #if HAVE_GDBM static struct @@ -412,7 +413,7 @@ SPAM_LIST *sp = SpamList; RX_LIST *rx = NoSpamList; - crc = crc32(crc, (unsigned char const *) "sithglan@stud.uni-erlangen.de|hcache.c|20040902122726|65256", mutt_strlen("sithglan@stud.uni-erlangen.de|hcache.c|20040902122726|65256")); + crc = crc32(crc, (unsigned char const *) "sithglan@stud.uni-erlangen.de|hcache.c|20040918110339|18700", mutt_strlen("sithglan@stud.uni-erlangen.de|hcache.c|20040918110339|18700")); #if HAVE_LANGINFO_CODESET crc = crc32(crc, (unsigned char const *) Charset, mutt_strlen(Charset)); @@ -487,6 +488,45 @@ return d; } +/* Append md5sumed folder to path if path is a directory. */ + +static const char * +mutt_hcache_per_folder(const char *path, const char *folder) +{ + static char mutt_hcache_per_folder_path[_POSIX_PATH_MAX]; + struct stat path_stat; + MD5_CTX md5; + unsigned char md5sum[16]; + int ret; + + ret = stat(path, &path_stat); + if (ret < 0) { + return path; + } + + if (! S_ISDIR(path_stat.st_mode)) { + return path; + } + + MD5Init(&md5); + MD5Update(&md5, (unsigned char *) folder, strlen(folder)); + MD5Final(md5sum, &md5); + + ret = snprintf(mutt_hcache_per_folder_path, _POSIX_PATH_MAX, + "%s/%02x%02x%02x%02x%02x%02x%02x%02x" + "%02x%02x%02x%02x%02x%02x%02x%02x", + path, md5sum[0], md5sum[1], md5sum[2], md5sum[3], + md5sum[4], md5sum[5], md5sum[6], md5sum[7], md5sum[8], + md5sum[9], md5sum[10], md5sum[11], md5sum[12], + md5sum[13], md5sum[14], md5sum[15]); + + if (ret <= 0) { + return path; + } + + return mutt_hcache_per_folder_path; +} + HEADER * mutt_hcache_restore(const unsigned char *d, HEADER **oh) { @@ -537,6 +577,8 @@ return NULL; } + path = mutt_hcache_per_folder(path, folder); + h->db = gdbm_open((char *) path, pagesize, GDBM_WRCREAT, 00600, NULL); if (h->db) { return h; @@ -678,6 +720,8 @@ FREE(& h); return NULL; } + + path = mutt_hcache_per_folder(path, folder); snprintf (h->lockfile, _POSIX_PATH_MAX, "%s-lock-hack", path); diff -Nru a/init.h b/init.h --- a/init.h 2004-08-26 22:31:23 +02:00 +++ b/init.h 2004-09-18 17:57:51 +02:00 @@ -1027,8 +1027,11 @@ { "header_cache", DT_PATH, R_NONE, UL &HeaderCache, 0 }, /* ** .pp - ** Path to the header cache file. If unset no cache will be used. Otherwise - ** the cache will be enabled for Maildir and IMAP mailboxes. + ** The header_cache variable points to the header cache database. If + ** header_cache points to a directory there will be created one header cache + ** database per folder within this directory. If it doesn't point to a directory a + ** global header cache for all folders is used. Per default it is unset and so + ** no header caching will be used. */ { "maildir_header_cache_verify", DT_BOOL, R_NONE, OPTHCACHEVERIFY, 1 }, /*