On Tue, Aug 10, 2010 at 09:28:14AM +0100, Chris G wrote:
> Thanks for all the help so far.  :-)
> 
> I've been thinking (now that's something!) about how mutt interacts
> with mail delivery programs and I'm realising that I don't *really*
> understand how it all works regarding locking etc.
> 
> Take a trivially simple case, mail for user chris is delivered to
> /var/mail/chris by, say, postfix.  I run mutt which looks at
> /var/mail/chris and displays the index of messages there.
> 
> What happens (as regards locks etc.) when mutt is displaying the inbox
> index and postfix wants to deliver another message?  Obviously mutt
> doesn't keep the file /var/mail/chris permanently locked as otherwise
> postfix would never be able to append the new message (if it was
> obeying the locking protocol).
> 
> So what *does* happen?  Does mutt open the file, scan the contents and
> then close it periodically?  This would seem to make sense as it often
> does take a while for mutt to notice that postfix has appended a new
> message. 
> 
> However I don't then understand what's going wrong when my python
> script appends a message to /var/mail/chris (or wherever).  What
> happens (in the non NFS situation) is that mutt complains "Mailbox
> was externally modified. Flags may be wrong."  I can also provoke this
> message if I run another copy of mutt and add/delete messages.  This
> error doesn't seem to relate to locking at all, it seems to be that
> mutt is detecting some *other* change to the mbox file in question.
> 
I now know!  I went and looked at the Python mailbox class.  When it
writes *anything* to an mbox file what it actually does is to create a
new file, copy the contents of the old mbox file to it, adds the new
data and then renames the new mbox file over the old mbox file.

This accounts for the errors I have been seeing.  The problem has
nothing whatsoever to do with locking, it's the replacement of the
file that does it.

There is a sort of logic to what python does, one *might* be deleting
or adding a message into the middle of the mbox in which case the
copy, rename sequence is the only sensible way to do it.  However the
documentation might have told me that and I'd not have wasted lots of
my (and the list's) time trying to work out what was wrong.

I can almost certainly fix the problem by simply not using the Python
mailbox class and by just appending new messages to the mbox using
straightforward file write calls (with appropriate locking of course).


> Can someone tell me what exactly mutt is checking to decide that
> "Mailbox was externally modified. Flags may be wrong."?  Is it a check
> to see if all messages up to the new appended one are unchanged, or is
> it something simpler than this like a simple length check?
> 
> -- 
> Chris Green
> 

-- 
Chris Green

Reply via email to