2 This is the header cache patch by Thomas Glanzmann
3 <sithglan@stud.uni-erlangen.de>.
5 The home page for this patch is:
7 http://wwwcip.informatik.uni-erlangen.de/~sithglan/mutt/
9 * Patch last synced with upstream:
11 - File: http://wwwcip.informatik.uni-erlangen.de/~sithglan/mutt/mutt-cvs-header-cache.28
16 diff -Nru a/PATCHES b/PATCHES
20 +mutt-cvs-header-cache.28
21 diff -Nru a/init.h b/init.h
22 --- a/init.h 2005-01-27 20:54:24 +01:00
23 +++ b/init.h 2005-01-28 15:12:41 +01:00
24 @@ -1032,6 +1032,13 @@
25 ** global header cache for all folders is used. Per default it is unset and so
26 ** no header caching will be used.
28 + { "maildir_header_cache_verify", DT_BOOL, R_NONE, OPTHCACHEVERIFY, 1 },
31 + ** Check for Maildir unaware programs other than mutt having modified maildir
32 + ** files when the header cache is in use. This incurs one stat(2) per
33 + ** message every time the folder is opened.
35 { "header_cache_pagesize", DT_STR, R_NONE, UL &HeaderCachePageSize, UL "16384" },
38 diff -Nru a/mh.c b/mh.c
39 --- a/mh.c 2005-01-27 20:45:37 +01:00
40 +++ b/mh.c 2005-02-03 09:09:50 +01:00
46 +static size_t maildir_hcache_keylen (const char *fn)
48 + const char * p = strrchr (fn, ':');
49 + return p ? (size_t) (p - fn) : mutt_strlen(fn);
55 * Merge two maildir lists according to the inode numbers.
57 * This function does the second parsing pass for a maildir-style
61 void maildir_delayed_parsing (CONTEXT * ctx, struct maildir *md)
64 char fn[_POSIX_PATH_MAX];
70 + struct timeval *when = NULL;
71 + struct stat lastchanged;
74 + hc = mutt_hcache_open (HeaderCache, ctx->path);
77 for (p = md, count = 0; p; p = p->next, count++)
78 - if (p && p->h && !p->header_parsed)
80 - if (!ctx->quiet && ReadInc && ((count % ReadInc) == 0 || count == 1))
81 - mutt_message (_("Reading %s... %d"), ctx->path, count);
82 - snprintf (fn, sizeof (fn), "%s/%s", ctx->path, p->h->path);
83 - if (maildir_parse_message (ctx->magic, fn, p->h->old, p->h))
84 - p->header_parsed = 1;
86 - mutt_free_header (&p->h);
90 + if (! (p && p->h && !p->header_parsed))
93 + if (!ctx->quiet && ReadInc && ((count % ReadInc) == 0 || count == 1))
94 + mutt_message (_("Reading %s... %d"), ctx->path, count);
97 + data = mutt_hcache_fetch (hc, p->h->path + 3, &maildir_hcache_keylen);
98 + when = (struct timeval *) data;
101 + snprintf (fn, sizeof (fn), "%s/%s", ctx->path, p->h->path);
104 + if (option(OPTHCACHEVERIFY))
105 + ret = stat(fn, &lastchanged);
107 + lastchanged.st_mtime = 0;
111 + if (data != NULL && !ret && lastchanged.st_mtime <= when->tv_sec)
113 + p->h = mutt_hcache_restore ((unsigned char *)data, &p->h);
114 + maildir_parse_flags (p->h, fn);
117 + if (maildir_parse_message (ctx->magic, fn, p->h->old, p->h))
119 + p->header_parsed = 1;
121 + mutt_hcache_store (hc, p->h->path + 3, p->h, 0, &maildir_hcache_keylen);
124 + mutt_free_header (&p->h);
130 + mutt_hcache_close (hc);
134 /* Read a MH/maildir style mailbox.
136 @@ -1399,6 +1447,9 @@
138 char path[_POSIX_PATH_MAX], tmp[_POSIX_PATH_MAX];
142 +#endif /* USE_HCACHE */
144 if (ctx->magic == M_MH)
145 i = mh_check_mailbox (ctx, index_hint);
146 @@ -1408,6 +1459,11 @@
151 + if (ctx->magic == M_MAILDIR)
152 + hc = mutt_hcache_open(HeaderCache, ctx->path);
153 +#endif /* USE_HCACHE */
155 for (i = 0; i < ctx->msgcount; i++)
157 if (ctx->hdrs[i]->deleted
158 @@ -1416,7 +1472,13 @@
159 snprintf (path, sizeof (path), "%s/%s", ctx->path, ctx->hdrs[i]->path);
160 if (ctx->magic == M_MAILDIR
161 || (option (OPTMHPURGE) && ctx->magic == M_MH))
164 + if (ctx->magic == M_MAILDIR)
165 + mutt_hcache_delete (hc, ctx->hdrs[i]->path + 3, &maildir_hcache_keylen);
166 +#endif /* USE_HCACHE */
169 else if (ctx->magic == M_MH)
171 /* MH just moves files out of the way when you delete them */
172 @@ -1438,16 +1500,21 @@
173 if (ctx->magic == M_MAILDIR)
175 if (maildir_sync_message (ctx, i) == -1)
181 if (mh_sync_message (ctx, i) == -1)
189 + if (ctx->magic == M_MAILDIR)
190 + mutt_hcache_close (hc);
191 +#endif /* USE_HCACHE */
193 if (ctx->magic == M_MH)
194 mh_update_sequences (ctx);
196 @@ -1468,6 +1535,13 @@
203 + if (ctx->magic == M_MAILDIR)
204 + mutt_hcache_close (hc);
205 +#endif /* USE_HCACHE */
209 static char *maildir_canon_filename (char *dest, const char *src, size_t l)
210 diff -Nru a/mutt.h b/mutt.h
211 --- a/mutt.h 2005-01-27 20:54:24 +01:00
212 +++ b/mutt.h 2005-01-28 15:12:54 +01:00