1 upstream test patch to fix the atime issue
2 (See #533439 and upstream #3271)
4 diff --git a/mbox.c b/mbox.c
7 @@ -681,22 +681,32 @@ int mbox_check_mailbox (CONTEXT *ctx, in
9 /* if mailbox has at least 1 new message, sets mtime > atime of mailbox
10 * so buffy check reports new mail */
11 -static void reset_atime (CONTEXT *ctx)
12 +static void reset_atime (CONTEXT *ctx, struct stat *st)
14 struct utimbuf utimebuf;
16 - time_t now = time (NULL);
20 - for (i = 0; i < ctx->msgcount; i++)
23 + if (stat (ctx->path, &_st) < 0)
28 + utimebuf.actime = st->st_atime;
29 + utimebuf.modtime = st->st_mtime;
31 + for (i = 0; !found && i < ctx->msgcount; i++)
32 if (!ctx->hdrs[i]->deleted && !ctx->hdrs[i]->read && !ctx->hdrs[i]->old)
34 - utimebuf.actime = now - 1;
35 - utimebuf.modtime = now;
36 - utime (ctx->path, &utimebuf);
42 + if (found && utimebuf.actime >= utimebuf.modtime)
43 + utimebuf.actime = utimebuf.modtime - 1;
45 + utimebuf.actime = utimebuf.modtime;
47 + utime (ctx->path, &utimebuf);
51 @@ -712,6 +722,7 @@ int mbox_sync_mailbox (CONTEXT *ctx, int
52 int need_sort = 0; /* flag to resort mailbox if new mail arrives */
53 int first = -1; /* first message to be written */
54 LOFF_T offset; /* location in mailbox to write changed messages */
55 + struct stat statbuf;
56 struct m_update_t *newOffset = NULL;
57 struct m_update_t *oldOffset = NULL;
59 @@ -903,6 +914,15 @@ int mbox_sync_mailbox (CONTEXT *ctx, int
63 + /* Save the state of this folder. */
64 + if (stat (ctx->path, &statbuf) == -1)
66 + mutt_perror (ctx->path);
72 if ((fp = fopen (tempfile, "r")) == NULL)
74 mutt_unblock_signals ();
75 @@ -972,6 +992,9 @@ int mbox_sync_mailbox (CONTEXT *ctx, int
79 + /* Restore the previous access/modification times */
80 + reset_atime (ctx, &statbuf);
82 /* reopen the mailbox in read-only mode */
83 if ((ctx->fp = fopen (ctx->path, "r")) == NULL)
85 @@ -998,11 +1021,6 @@ int mbox_sync_mailbox (CONTEXT *ctx, int
86 unlink (tempfile); /* remove partial copy of the mailbox */
87 mutt_unblock_signals ();
89 - /* if mailbox has new mail, mangle atime+mtime to make buffy check
90 - * report new mail for it */
91 - if (!option (OPTCHECKMBOXSIZE))
94 return (0); /* signal success */
96 bail: /* Come here in case of disaster */