Submitted by: Damon Harper Date: 2006-08-26, 2007-09-21 Summary: Reset access/mod times after comsatd accesses a mailbox This patch makes comsatd reset the access and modification times on a mailbox after scanning it for new mail. MUAs like mutt depend on the access and modification times to let the user know if there is new mail in a mailbox. comsatd currently causes the access time to be updated, which thwarts this mechanism and makes it look like there is never new mail. There may be a better way to implement this; for example I imagine it would be better to add an option to the various functions used to scan mail, which causes them to reset the access time while the mailbox is still locked. With this patch, there is a race condition that means a legitimate access/modification time not caused by comsat might be clobbered. However for practical purposes this quick hack seems to be just fine. NOTE: This patch applies on top of: mailutils-1.2-comsatd-exec-without-tty-2.patch It will NOT apply cleanly to stock mailutils-1.2. diff -urN mailutils-1.2.orig/comsat/comsat.c mailutils-1.2/comsat/comsat.c --- mailutils-1.2.orig/comsat/comsat.c 2007-06-27 05:07:16.000000000 -0700 +++ mailutils-1.2/comsat/comsat.c 2007-09-21 01:36:22.000000000 -0700 @@ -434,6 +434,9 @@ int status; off_t size; size_t count, n; + int reset_times = 0; + struct stat sb; + struct utimbuf ub; change_user (user); if ((fp = fopen (device, "w")) == NULL) @@ -451,6 +454,10 @@ return; } + /* Store mailbox access and modification times. */ + if (stat (path, &sb) != -1) + reset_times = 1; + if ((status = mu_mailbox_create (&mbox, path)) != 0 || (status = mu_mailbox_open (mbox, MU_STREAM_READ)) != 0) { @@ -504,6 +511,14 @@ run_user_action (msg); if (ttyfp != NULL) fclose (ttyfp); + + /* Now if possible reset the access and modification times, so programs + like mutt will still see new mail in the folder. */ + if (reset_times) { + ub.modtime = sb.st_mtime; + ub.actime = sb.st_atime; + utime (path, &ub); /* Ignore return value - if it fails, too bad. */ + } } /* Search utmp for the local user */ diff -urN mailutils-1.2.orig/comsat/comsat.h mailutils-1.2/comsat/comsat.h --- mailutils-1.2.orig/comsat/comsat.h 2007-06-27 05:07:16.000000000 -0700 +++ mailutils-1.2/comsat/comsat.h 2007-09-21 01:35:43.000000000 -0700 @@ -37,6 +37,7 @@ #include #include #include +#include #ifdef HAVE_PATHS_H # include