[Dovecot] Deleting a mailbox and all its children

micah anderson micah at riseup.net
Wed Nov 16 04:23:47 EET 2011


On Wed, 16 Nov 2011 03:15:02 +0200, Timo Sirainen <tss at iki.fi> wrote:
> On 16.11.2011, at 3.04, Micah Anderson wrote:
> 
> > I'm looking at scripting a mechanism to delete a mailbox, which is easy
> > with 'doveadm mailbox delete' -- however it gets complicated when there
> > are children of arbitrary depth, for example, I may have this:
> > 
> > restored.daily1.INBOX
> > restored.daily1.Sent
> > restored.daily1.Mystuff
> > restored.daily1.Mystuff.foo
> > 
> > I would like to delete the 'restored' mailbox and all its children (and
> > unsubscribe the folders), but the 'doveadm mailbox delete' command wont
> > delete any children.
> > 
> > I'm surprised that there isn't a -r (recursive) option to 'doveadm
> > mailbox delete', but perhaps I am missing the easier way to handle this?
> 
> Well, how about something like:
> 
> doveadm mailbox list 'restored.*' | xargs -1 doveadm mailbox delete
> doveadm mailbox delete restored

That wont work because 'restored.daily1.Mystuff.foo' wont get removed
before 'restored.daily1.Mystuff' is attempted, resulting in the
following:

doveadm mailbox list 'restored.*' | xargs -1 doveadm mailbox delete
doveadm(micah): Error: Can't delete mailbox restored.daily1.Mystuff: Mailbox has children, delete them first

The problem is the subfolders need to be removed first and then walk up
the tree. 

perhaps I can do:

doveadm mailbox list 'restored.*' | sort -r | xargs -n1 doveadm mailbox delete
doveadm mailbox delete restored

although I'm not sure if the reverse sort is going to work in all cases.

micah

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://dovecot.org/pipermail/dovecot/attachments/20111115/66d9d075/attachment-0004.bin>


More information about the dovecot mailing list