]> granicus.if.org Git - neomutt/commitdiff
Add tmp flag to bcache_put, create bcache_commit.
authorBrendan Cully <brendan@kublai.com>
Sun, 1 Apr 2007 01:50:39 +0000 (18:50 -0700)
committerBrendan Cully <brendan@kublai.com>
Sun, 1 Apr 2007 01:50:39 +0000 (18:50 -0700)
ChangeLog
bcache.c
bcache.h
imap/message.c
pop.c
pop.h

index d2a84401624fa88620f96fe82b3b95ac98d875cb..e874f1e21a989912c2607f782f1148d78963bb74 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-03-31 16:07 -0700  Brendan Cully  <brendan@kublai.com>  (bf208df92829)
+
+       * imap/command.c, imap/imap.c: Allow IMAP FCC to reconnect if
+       append fails (closes: #890)
+
+       * mh.c: Always set up data pointer in mh_read_dir, not just when
+       allocating context
+
 2007-03-30 21:26 -0700  Daniel Burrows  <dburrows@debian.org>  (d5ab883ef90a)
 
        * hcache.c: Fix handling of DB4 hcache open failure. (closes: #2714)
index fd52365c4a615d03dcfa212612188423389ca32e..5b6d63ee6ad360a51177c3bf89486e508fe5ccb2 100644 (file)
--- a/bcache.c
+++ b/bcache.c
@@ -131,7 +131,7 @@ FILE* mutt_bcache_get(body_cache_t *bcache, const char *id)
   return fp;
 }
 
-FILE* mutt_bcache_put(body_cache_t *bcache, const char *id)
+FILE* mutt_bcache_put(body_cache_t *bcache, const char *id, int tmp)
 {
   char path[_POSIX_PATH_MAX];
   FILE* fp;
@@ -141,9 +141,8 @@ FILE* mutt_bcache_put(body_cache_t *bcache, const char *id)
   if (!id || !*id || !bcache)
     return NULL;
 
-  path[0] = '\0';
-  safe_strncat (path, sizeof (path), bcache->path, bcache->pathlen);
-  safe_strncat (path, sizeof (path), id, mutt_strlen (id));
+  snprintf (path, sizeof (path), "%s%s%s", bcache->path, id,
+            tmp ? ".tmp" : "");
 
   s = strchr (path + 1, '/');
   while (!(fp = safe_fopen (path, "w+")) && errno == ENOENT && s)
@@ -161,6 +160,15 @@ FILE* mutt_bcache_put(body_cache_t *bcache, const char *id)
   return fp;
 }
 
+int mutt_bcache_commit(body_cache_t* bcache, const char* id)
+{
+  char tmpid[_POSIX_PATH_MAX];
+
+  snprintf (tmpid, sizeof (tmpid), "%s.tmp", id);
+
+  return mutt_bcache_move (bcache, tmpid, id);
+}
+
 int mutt_bcache_move(body_cache_t* bcache, const char* id, const char* newid)
 {
   char path[_POSIX_PATH_MAX];
index d061a6ae70a5f7b9955940d202de7f5d62bf1e2a..35586e9110dba78a9e6416dd8d8b1ab64565f3bc 100644 (file)
--- a/bcache.h
+++ b/bcache.h
@@ -48,7 +48,10 @@ void mutt_bcache_close (body_cache_t **bcache);
  */
 
 FILE* mutt_bcache_get(body_cache_t *bcache, const char *id);
-FILE* mutt_bcache_put(body_cache_t *bcache, const char *id);
+/* tmp: the returned FILE* is in a temporary location.
+ *      if set, use mutt_bcache_commit to put it into place */
+FILE* mutt_bcache_put(body_cache_t *bcache, const char *id, int tmp);
+int mutt_bcache_commit(body_cache_t *bcache, const char *id);
 int mutt_bcache_move(body_cache_t *bcache, const char *id, const char *newid);
 int mutt_bcache_del(body_cache_t *bcache, const char *id);
 int mutt_bcache_exists(body_cache_t *bcache, const char *id);
index a25c17386d16ae7ce0ab0c10292e1479e405b5d5..3f3b234748bd33f6cfa27f4c5d619b3945839d8d 100644 (file)
@@ -903,23 +903,21 @@ static FILE* msg_cache_put (IMAP_DATA* idata, HEADER* h)
     return NULL;
 
   idata->bcache = msg_cache_open (idata);
-  snprintf (id, sizeof (id), "%u-%u.tmp", idata->uid_validity, HEADER_DATA(h)->uid);
-  return mutt_bcache_put (idata->bcache, id);
+  snprintf (id, sizeof (id), "%u-%u", idata->uid_validity, HEADER_DATA(h)->uid);
+  return mutt_bcache_put (idata->bcache, id, 1);
 }
 
 static int msg_cache_commit (IMAP_DATA* idata, HEADER* h)
 {
   char id[_POSIX_PATH_MAX];
-  char newid[_POSIX_PATH_MAX];
 
   if (!idata || !h)
     return -1;
 
   idata->bcache = msg_cache_open (idata);
-  snprintf (id, sizeof (id), "%u-%u.tmp", idata->uid_validity, HEADER_DATA(h)->uid);
-  snprintf (newid, sizeof (newid), "%u-%u", idata->uid_validity, HEADER_DATA(h)->uid);
+  snprintf (id, sizeof (id), "%u-%u", idata->uid_validity, HEADER_DATA(h)->uid);
 
-  return mutt_bcache_move (idata->bcache, id, newid);
+  return mutt_bcache_commit (idata->bcache, id);
 }
 
 int imap_cache_del (IMAP_DATA* idata, HEADER* h)
diff --git a/pop.c b/pop.c
index f84ec80c6402f4107f2623acb5be17ef66c87f94..9fc4369c72b067ba20b388d1b6d956be41eb6820 100644 (file)
--- a/pop.c
+++ b/pop.c
@@ -428,12 +428,12 @@ static void pop_clear_cache (POP_DATA *pop_data)
 }
 
 /* close POP mailbox */
-void pop_close_mailbox (CONTEXT *ctx)
+int pop_close_mailbox (CONTEXT *ctx)
 {
   POP_DATA *pop_data = (POP_DATA *)ctx->data;
 
   if (!pop_data)
-    return;
+    return 0;
 
   pop_logout (ctx);
 
@@ -450,7 +450,7 @@ void pop_close_mailbox (CONTEXT *ctx)
 
   mutt_bcache_close (&pop_data->bcache);
 
-  return;
+  return 0;
 }
 
 /* fetch message from POP server */
@@ -514,7 +514,7 @@ int pop_fetch_message (MESSAGE* msg, CONTEXT* ctx, int msgno)
                        M_PROGRESS_SIZE, NetInc, h->content->length + h->content->offset - 1);
 
     /* see if we can put in body cache; use our cache as fallback */
-    if (!(msg->fp = mutt_bcache_put (pop_data->bcache, h->data)))
+    if (!(msg->fp = mutt_bcache_put (pop_data->bcache, h->data, 1)))
     {
       /* no */
       bcache = 0;
@@ -538,9 +538,7 @@ int pop_fetch_message (MESSAGE* msg, CONTEXT* ctx, int msgno)
     /* if RETR failed (e.g. connection closed), be sure to remove either
      * the file in bcache or from POP's own cache since the next iteration
      * of the loop will re-attempt to put() the message */
-    if (bcache)
-      mutt_bcache_del (pop_data->bcache, h->data);
-    else
+    if (!bcache)
       unlink (path);
 
     if (ret == -2)
@@ -561,7 +559,9 @@ int pop_fetch_message (MESSAGE* msg, CONTEXT* ctx, int msgno)
   /* Update the header information.  Previously, we only downloaded a
    * portion of the headers, those required for the main display.
    */
-  if (!bcache)
+  if (bcache)
+    mutt_bcache_commit (pop_data->bcache, h->data);
+  else
   {
     cache->index = h->index;
     cache->path = safe_strdup (path);
diff --git a/pop.h b/pop.h
index 13bd1212ff8d376b8f5a38acdf36bf21cb1a2c9e..efa6d9e3bcfb9e687e2109272b9189ae2a308b8f 100644 (file)
--- a/pop.h
+++ b/pop.h
@@ -109,7 +109,7 @@ int pop_check_mailbox (CONTEXT *, int *);
 int pop_open_mailbox (CONTEXT *);
 int pop_sync_mailbox (CONTEXT *, int *);
 int pop_fetch_message (MESSAGE *, CONTEXT *, int);
-void pop_close_mailbox (CONTEXT *);
+int pop_close_mailbox (CONTEXT *);
 void pop_fetch_mail (void);
 
 #endif