#3475: New mail not detected in current maildir folder
--------------------+-------------------------------------------------------
 Reporter:  vinc17  |       Owner:  mutt-dev
     Type:  defect  |      Status:  new     
 Priority:  major   |   Milestone:          
Component:  mutt    |     Version:          
 Keywords:          |  
--------------------+-------------------------------------------------------

Comment(by vinc17):

 The problem occurred once again! I've looked at the code in
 maildir_check_mailbox from mh.c and it seems incorrect:
 {{{
   /* determine which subdirectories need to be scanned */
   if (st_new.st_mtime > ctx->mtime)
     changed = 1;
   if (st_cur.st_mtime > data->mtime_cur)
     changed |= 2;

   if (!changed)
     return 0;                   /* nothing to do */

   /* update the modification times on the mailbox */
   data->mtime_cur = st_cur.st_mtime;
   ctx->mtime = st_new.st_mtime;
 }}}
 This seems to be subject to race condition, in particular if new mail
 arrives at about the same time the mailbox is synchronized (I think this
 is what happens in my case). I don't think it is possible to avoid a race
 condition when considering only the timestamp of the new subdirectory. But
 for instance, a full check (scan) of the new subdirectory could be done
 systematically several seconds after the latest change (due to
 synchronization or new mail). I don't think it is useful to do the same
 thing for the cur subdirectory.

 What could be done is to have a new field ctx->rescan that would be set to
 1 after a change (synchronization or new mail). Near the beginning of
 maildir_check_mailbox: if ctx->rescan is non-zero, a scan would be done,
 and if the timestamps have not changed, ctx->rescan would be reset to 0.
 Something like that (not tested):
 {{{
   /* determine which subdirectories need to be scanned */
   if (st_new.st_mtime > ctx->mtime)
   {
     ctx->mtime = st_new.st_mtime;
     changed = 1;
     ctx->rescan = 1;
   }
   else if (ctx->rescan)
   {
     changed = 1;
     ctx->rescan = 0;
   }
   if (st_cur.st_mtime > data->mtime_cur)
   {
     data->mtime_cur = st_cur.st_mtime;
     changed |= 2;
   }

   if (!changed)
     return 0;                   /* nothing to do */
 }}}
 This is incomplete: some other functions would need to set ctx->rescan
 too. And if maildir_check_mailbox can be called too often, ctx->rescan
 should contain a time-based value.

-- 
Ticket URL: <http://dev.mutt.org/trac/ticket/3475#comment:4>
Mutt <http://www.mutt.org/>
The Mutt mail user agent

Reply via email to