Issue 1575506: Mailbox will not lock properly after flush() (original) (raw)

The _singlefileMailbox class will try to lock the wrong file object after a flush(), resulting into an operation on a closed file object.

The following code should illustrate the bug. See also the attached patch.

import mailbox

box = mailbox.mbox('mbox') msg = "Subject: sub\n\nbody\n" box.add(msg) 0 box.flush() box.close()

box = mailbox.mbox('mbox') box.lock() box.add(msg) 1 box.flush() Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.5/mailbox.py", line 581, in flush _lock_file(new_file, dotlock=False) File "/usr/lib/python2.5/mailbox.py", line 1847, in _lock_file fcntl.lockf(f, fcntl.LOCK_UN) ValueError: I/O operation on closed file