summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2014-12-30 11:17:34 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2014-12-30 11:18:26 +0100
commit955f76c530b43fc9703a2879b63215c2673e08db (patch)
tree559022428e9a4fa72005ad546c3cb33b9a6e5450
parent97d457b5774a2d6d77cc12d3e5923b2d10b25ca9 (diff)
downloadpykolab-955f76c530b43fc9703a2879b63215c2673e08db.tar.gz
Add an option --dry-run to kolab mailbox-cleanup
-rw-r--r--pykolab/cli/cmd_mailbox_cleanup.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/pykolab/cli/cmd_mailbox_cleanup.py b/pykolab/cli/cmd_mailbox_cleanup.py
index 8dee38b..c2e38ef 100644
--- a/pykolab/cli/cmd_mailbox_cleanup.py
+++ b/pykolab/cli/cmd_mailbox_cleanup.py
@@ -33,6 +33,16 @@ conf = pykolab.getConf()
def __init__():
commands.register('mailbox_cleanup', execute, description=description())
+def cli_options():
+ my_option_group = conf.add_cli_parser_option_group(_("CLI Options"))
+ my_option_group.add_option(
+ '--dry-run',
+ dest = "dryrun",
+ action = "store_true",
+ default = False,
+ help = _("Do not actually delete mailboxes, but report what mailboxes would have been deleted.")
+ )
+
def description():
return _("Clean up mailboxes that do no longer have an owner.")
@@ -49,7 +59,7 @@ def execute(*args, **kw):
folders = []
- for domain,aliases in domains:
+ for domain in domains.keys():
folders.extend(imap.lm("user/%%@%s" % (domain)))
for folder in folders:
@@ -58,8 +68,11 @@ def execute(*args, **kw):
recipient = auth.find_recipient(user)
if len(recipient) == 0 or recipient == []:
- log.info(_("Deleting folder 'user/%s'") % (user))
- try:
- imap.dm(folder)
- except:
- pass \ No newline at end of file
+ if conf.dryrun:
+ log.info(_("Would have deleting folder 'user/%s' (dryrun)") % (user))
+ else:
+ log.info(_("Deleting folder 'user/%s'") % (user))
+ try:
+ imap.dm(folder)
+ except:
+ log.error(_("Error deleting folder 'user/%s'") 5 (user))