From 9eabd58a82096e3f1635d2888576a174329d6319 Mon Sep 17 00:00:00 2001
From: Rocco Rutte <pdmef@gmx.net>
Date: Tue, 11 Dec 2007 14:58:31 +0100
Subject: [PATCH] POP: Name hcache the way IMAP does. Place the file under
 $header_cache/<url>/mutt.hcache. For now ignore that this may break if hcache
 == bcache and a message's uid is "mutt.hcache" (extremely unlikely) in which
 case the user will loose only the hcache file.

---
 ChangeLog | 13 +++++++++++++
 pop.c     | 36 ++++++++++++++++++++++++++++++++++--
 2 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3c019e54..0f92f148 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2007-12-11 14:50 +0100  Rocco Rutte  <pdmef@gmx.net>  (f19984dcfacb)
+
+	* pop.c: POP: Respect $message_cache_clean
+
+2007-12-11 14:49 +0100  Rocco Rutte  <pdmef@gmx.net>  (2707a97e0deb)
+
+	* doc/manual.xml.head: Manual: mention $time_inc in tuning chapter
+
+2007-12-11 13:12 +0100  Rocco Rutte  <pdmef@gmx.net>  (9709d244c64b)
+
+	* ChangeLog, enter.c, history.h: Maintain different history lists for
+	files and mailboxes. Closes #2999.
+
 2007-12-11 13:08 +0100  Rocco Rutte  <pdmef@gmx.net>  (35d778452444)
 
 	* history.c: Do not trust history file and mutt code about history
diff --git a/pop.c b/pop.c
index 273bbf5b..255369c2 100644
--- a/pop.c
+++ b/pop.c
@@ -34,6 +34,11 @@
 #include <string.h>
 #include <unistd.h>
 
+#ifdef USE_HCACHE
+#define HC_FNAME	"mutt"		/* filename for hcache as POP lacks paths */
+#define HC_FEXT		"hcache"	/* extension for hcache as POP lacks paths */
+#endif
+
 /* write line to file */
 static int fetch_message (char *line, void *file)
 {
@@ -173,6 +178,12 @@ static int msg_cache_check (const char *id, body_cache_t *bcache, void *data)
   if (!(pop_data = (POP_DATA *)ctx->data))
     return -1;
 
+#ifdef USE_HCACHE
+  /* keep hcache file if hcache == bcache */
+  if (strcmp (HC_FNAME "." HC_FEXT, id) == 0)
+    return 0;
+#endif
+
   for (i = 0; i < ctx->msgcount; i++)
     /* if the id we get is known for a header: done (i.e. keep in cache) */
     if (ctx->hdrs[i]->data && mutt_strcmp (ctx->hdrs[i]->data, id) == 0)
@@ -184,6 +195,27 @@ static int msg_cache_check (const char *id, body_cache_t *bcache, void *data)
   return mutt_bcache_del (bcache, id);
 }
 
+#ifdef USE_HCACHE
+static int pop_hcache_namer (const char *path, char *dest, size_t destlen)
+{
+  return snprintf (dest, destlen, "%s." HC_FEXT, path);
+}
+
+static header_cache_t *pop_hcache_open (POP_DATA *pop_data, const char *path)
+{
+  ciss_url_t url;
+  char p[LONG_STRING];
+
+  if (!pop_data || !pop_data->conn)
+    return mutt_hcache_open (HeaderCache, path, NULL);
+
+  mutt_account_tourl (&pop_data->conn->account, &url);
+  url.path = HC_FNAME;
+  url_ciss_tostring (&url, p, sizeof (p), U_PATH);
+  return mutt_hcache_open (HeaderCache, p, pop_hcache_namer);
+}
+#endif
+
 /*
  * Read headers
  * returns:
@@ -203,7 +235,7 @@ static int pop_fetch_headers (CONTEXT *ctx)
   header_cache_t *hc = NULL;
   void *data;
 
-  hc = mutt_hcache_open (HeaderCache, ctx->path, NULL);
+  hc = pop_hcache_open (pop_data, ctx->path);
 #endif
 
   time (&pop_data->check_time);
@@ -614,7 +646,7 @@ int pop_sync_mailbox (CONTEXT *ctx, int *index_hint)
 			M_PROGRESS_MSG, WriteInc, ctx->deleted);
 
 #if USE_HCACHE
-    hc = mutt_hcache_open (HeaderCache, ctx->path, NULL);
+    hc = pop_hcache_open (pop_data, ctx->path);
 #endif
 
     for (i = 0, j = 0, ret = 0; ret == 0 && i < ctx->msgcount; i++)
-- 
2.40.0