[issue20328] mailbox:

Jonathan Dowland report at bugs.python.org
Fri Jan 31 13:21:48 CET 2014


Jonathan Dowland added the comment:

Hi David, thanks for replying!

On Tue, Jan 21, 2014 at 03:08:04PM +0000, R. David Murray wrote:
> Conceptually the problem with this is that if you use the object to
> delete the folder, you now have an object with no folder...that is, an
> invalid object.

You're absolutely right, and it turns out that this library already has
this problem, because the mailbox.Maildir class has a remove_folder
method, which can delete nested Maildirs. The following python code is
enough to expose this problem:

> import mailbox, os
> 
> # create foo/{cur,new,tmp,.bar{,/{cur,new,tmp}}}
> for d in "foo foo/.bar".split():
>   os.mkdir(d)
>   for d2 in "cur new tmp".split():
>     os.mkdir(os.path.join(d,d2))
> 
> mb1 = mailbox.Maildir("foo")
> mb2 = mb1.get_folder("bar")
> mb1.remove_folder("bar")
> print mb2.items()

Of course, if someone is using this module in any real environment where
folders might come and go due to other processes (e.g. an IMAPd - quite
a realistic prospect if you ask me), any mailbox.* object could become
invalid at any time.

Note that mailbox class has a 'lock/unlock' method, but this is a no-op
for mailbox.Maildir.

> Do we have any other stdlib examples of objects with a 'delete()'
> method...looks like bdb has a deleteMe on breakpoint objects, but it
> isn't clear that it tries to deal with what happens if a breakpoint
> object that has been deleted is accessed again.  There are also some
> in idlelib/tk, which I haven't looked at.

That's a very good question. I don't know, I will have to do some
research. I wonder if it's worth looking outside of the python ecosystem
too.

> So, I guess the issue is to work out what the semantics of the object
> would be if delete has been called, and make sure it actually makes
> sense to have a delete method.

Yes. My gut feeling is the module needs to gracefully handle situations
where objects are not valid anymore, to allow inter-operation with other
processes deleting or creating mailboxes outside of Python's control,
but I suppose the first step is the research.

If the consensus is that delete doesn't make sense, I think we need to
address the existing delete_folder methods.

Thanks for your interest,

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20328>
_______________________________________


More information about the Python-bugs-list mailing list