mailbox.mbox not locking mbox properly

tinnews at tinnews at
Mon Aug 9 23:52:39 CEST 2010

I'm using the python mailbox class in a script that processes incoming
mail and delivers it to various mbox format mailboxes.  It appears
that, although I am calling the lock method on the destination before
writing to the mbox and calling unlock afterwards the locking isn't
working correctly.

I am reading the mail with mutt, if I deliver the mail direct using
Postfix (i.e. bypassing my python script) mutt works perfectly and
shows new mail arriving in the mailbox as expected with an 'N' flag
beside it.  If I deliver the mail with my python script I get an error
from mutt saying "Mailbox was externally modified. Flags may be
wrong.", or if I'm reading the mbox via NFS I get all sorts of strange
errors (though again it works perfectly if Postfix writes to the mbox).

So it seems that python's mailbox class locking isn't playing nicely
with mutt's mailbox locking whereas postfix's locking does work

Has anyone seen this problem before, and/or do I need to anything more
than the following for the locking to work correctly:-

    # set up the mb for adding the new message, will create if it doesn't exist
    dest = mailbox.mbox(mbName, factory=None)

    dest.add(m)                             # add the new message

Any help/comments most welcome

Chris Green

More information about the Python-list mailing list