Mercurial > dovecot > original-hg > dovecot-1.2
changeset 3836:8cd2673e4eb5 HEAD
Keep atime < mtime if mbox has recent messages and we're keeping them. Rely
on this for setting \UnMarked flag for LIST replies.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 07 Jan 2006 02:29:19 +0200 |
parents | 309605c0a7fb |
children | 073d3f73db51 |
files | src/lib-storage/index/mbox/mbox-file.c src/lib-storage/index/mbox/mbox-list.c |
diffstat | 2 files changed, 29 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/mbox/mbox-file.c Sat Jan 07 02:20:56 2006 +0200 +++ b/src/lib-storage/index/mbox/mbox-file.c Sat Jan 07 02:29:19 2006 +0200 @@ -8,6 +8,7 @@ #include "istream-raw-mbox.h" #include <sys/stat.h> +#include <utime.h> int mbox_file_open(struct mbox_mailbox *mbox) { @@ -96,8 +97,35 @@ return 0; } +static void mbox_file_fix_atime(struct mbox_mailbox *mbox) +{ + struct utimbuf buf; + struct stat st; + + if (mbox->ibox.recent_flags_count > 0 && mbox->ibox.keep_recent && + mbox->mbox_fd != -1) { + /* we've seen recent messages which we want to keep recent. + keep file's atime lower than mtime so \Marked status + gets shown while listing */ + if (fstat(mbox->mbox_fd, &st) < 0) { + mbox_set_syscall_error(mbox, "fstat()"); + return; + } + if (st.st_atime >= st.st_mtime) { + buf.modtime = st.st_mtime; + buf.actime = buf.modtime - 1; + if (utime(mbox->path, &buf) < 0) { + mbox_set_syscall_error(mbox, "utimes()"); + return; + } + } + } +} void mbox_file_close_stream(struct mbox_mailbox *mbox) { + /* if we read anything, fix the atime if needed */ + mbox_file_fix_atime(mbox); + if (mbox->mbox_stream != NULL) { i_stream_unref(mbox->mbox_stream); mbox->mbox_stream = NULL;
--- a/src/lib-storage/index/mbox/mbox-list.c Sat Jan 07 02:20:56 2006 +0200 +++ b/src/lib-storage/index/mbox/mbox-list.c Sat Jan 07 02:29:19 2006 +0200 @@ -10,13 +10,9 @@ #include <dirent.h> #include <sys/stat.h> -/* atime < mtime is a reliable way to know that something changed in the file. - atime >= mtime is not however reliable, especially because atime gets - updated whenever we open the mbox file, and STATUS/EXAMINE shouldn't change - \Marked mailbox to \Unmarked.. */ #define STAT_GET_MARKED(st) \ ((st).st_size == 0 ? MAILBOX_UNMARKED : \ - (st).st_atime < (st).st_mtime ? MAILBOX_MARKED : 0) + (st).st_atime < (st).st_mtime ? MAILBOX_MARKED : MAILBOX_UNMARKED) struct list_dir_context { struct list_dir_context *prev;