]> granicus.if.org Git - neomutt/commitdiff
Don't mangle atime/mtime for mbox folders without new mail upon sync. Closes #1362...
authorRocco Rutte <pdmef@gmx.net>
Fri, 19 Jun 2009 17:27:37 +0000 (19:27 +0200)
committerRocco Rutte <pdmef@gmx.net>
Fri, 19 Jun 2009 17:27:37 +0000 (19:27 +0200)
ChangeLog
mbox.c

index 32f9cc4bbc651f91ac2e8a9b2cc781d4ed014d99..61862adbb0660086076a13af8c459b4c03c50d90 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2009-06-19 19:23 +0200  Rocco Rutte  <pdmef@gmx.net>  (0fd362c870b8)
+
+       * doc/manual.xml.head: Manual: Add note and example for type
+       conversions with my_vars
+
+2009-06-19 18:49 +0200  Rocco Rutte  <pdmef@gmx.net>  (9656d94b83b2)
+
+       * .hgignore: Ignore files from manual.pdf generation
+
+2009-06-19 18:46 +0200  Rocco Rutte  <pdmef@gmx.net>  (439274e8eca4)
+
+       * sendlib.c: Enforce 998 char length limit on header lines when
+       sending.
+
+2009-06-18 15:06 +0200  Antonio Radici  <antonio@dyne.org>  (c6fe0bb8cf11)
+
+       * .hgignore, ChangeLog, doc/Makefile.am, doc/smime_keys.man: Provide
+       smime_keys(1). Closes #3272.
+
 2009-06-18 14:56 +0200  Rocco Rutte  <pdmef@gmx.net>  (508bfe4a2e23)
 
        * mbox.c: Backout experimental patch
diff --git a/mbox.c b/mbox.c
index 36d496c8048876acce460b36487a22104d0a7def..ecd63f9d12ca5614cab2e96b02389f26ec6243b8 100644 (file)
--- a/mbox.c
+++ b/mbox.c
@@ -681,22 +681,30 @@ int mbox_check_mailbox (CONTEXT *ctx, int *index_hint)
 
 /* if mailbox has at least 1 new message, sets mtime > atime of mailbox
  * so buffy check reports new mail */
-static void reset_atime (CONTEXT *ctx)
+static void reset_atime (CONTEXT *ctx, struct stat *st)
 {
   struct utimbuf utimebuf;
-  int i;
-  time_t now = time (NULL);
+  int i, found = 0;
+  struct stat _st;
 
-  for (i = 0; i < ctx->msgcount; i++)
+  if (!st)
   {
-    if (!ctx->hdrs[i]->deleted && !ctx->hdrs[i]->read && !ctx->hdrs[i]->old)
-    {
-      utimebuf.actime = now - 1;
-      utimebuf.modtime = now;
-      utime (ctx->path, &utimebuf);
+    if (stat (ctx->path, &_st) < 0)
       return;
-    }
+    st = &_st;
   }
+
+  utimebuf.actime = st->st_atime;
+  utimebuf.modtime = st->st_mtime;
+
+  for (i = 0; !found && i < ctx->msgcount; i++)
+    if (!ctx->hdrs[i]->deleted && !ctx->hdrs[i]->read && !ctx->hdrs[i]->old)
+      found = 1;
+
+  if (found && utimebuf.actime >= utimebuf.modtime)
+    utimebuf.actime = utimebuf.modtime - 1;
+
+  utime (ctx->path, &utimebuf);
 }
 
 /* return values:
@@ -712,6 +720,7 @@ int mbox_sync_mailbox (CONTEXT *ctx, int *index_hint)
   int need_sort = 0; /* flag to resort mailbox if new mail arrives */
   int first = -1;      /* first message to be written */
   LOFF_T offset;       /* location in mailbox to write changed messages */
+  struct stat statbuf;
   struct m_update_t *newOffset = NULL;
   struct m_update_t *oldOffset = NULL;
   FILE *fp = NULL;
@@ -903,6 +912,15 @@ int mbox_sync_mailbox (CONTEXT *ctx, int *index_hint)
   }
   fp = NULL;
 
+  /* Save the state of this folder. */
+  if (stat (ctx->path, &statbuf) == -1)
+  {
+    mutt_perror (ctx->path);
+    mutt_sleep (5);
+    unlink (tempfile);
+    goto bail;
+  }
+
   if ((fp = fopen (tempfile, "r")) == NULL)
   {
     mutt_unblock_signals ();
@@ -972,6 +990,9 @@ int mbox_sync_mailbox (CONTEXT *ctx, int *index_hint)
     return (-1);
   }
 
+  /* Restore the previous access/modification times */
+  reset_atime (ctx, &statbuf);
+
   /* reopen the mailbox in read-only mode */
   if ((ctx->fp = fopen (ctx->path, "r")) == NULL)
   {
@@ -998,11 +1019,6 @@ int mbox_sync_mailbox (CONTEXT *ctx, int *index_hint)
   unlink (tempfile); /* remove partial copy of the mailbox */
   mutt_unblock_signals ();
 
-  /* if mailbox has new mail, mangle atime+mtime to make buffy check
-   * report new mail for it */
-  if (!option (OPTCHECKMBOXSIZE))
-    reset_atime (ctx);
-
   return (0); /* signal success */
 
 bail:  /* Come here in case of disaster */