mailbox.Maildir question/problem
Ross Ridge
rridge at caffeine.csclub.uwaterloo.ca
Thu Dec 13 17:40:35 EST 2007
<tinnews at isbd.co.uk> wrote:
>Is there *any* way I can get python to access maildirs
>which are not named using this (IMHO stupid) convention?
Well, the mailbox module doesn't support deleting mailboxes, so I'm not
sure why you want to use it. Since you also seem to have a better idea
of what your maildirs look like, why not just use the lower level file
functions directly? Something like:
def remove_empty_maildir(dirname):
expected = set(["cur", "new", "tmp"])
ents = set(os.listdir(dirname))
if ents != expected:
if expected.issubset(ents):
raise error, "unexpected subdirs in maildir"
raise error, "not a maildir"
subdirs = [os.path.join(dirname, d)
for d in expected]
for d in subdirs:
if len(os.listdir(d)) != 0:
return False
for d in subdirs:
os.rmdir(d)
os.rmdir(dirname)
return True
Your case is presumably different somehow, so you'll have to update and
fix this completely untested code if you want to use it.
Ross Ridge
--
l/ // Ross Ridge -- The Great HTMU
[oo][oo] rridge at csclub.uwaterloo.ca
-()-/()/ http://www.csclub.uwaterloo.ca/~rridge/
db //
More information about the Python-list
mailing list