From a3ed0383ff97f0ab5c03ba26426ea65e4a31f4e6 Mon Sep 17 00:00:00 2001 From: "Jeroen van Meeuwen (Kolab Systems)" Date: Fri, 2 Aug 2013 11:28:55 +0100 Subject: Add a command to list mailboxes for a specific domain including its alias domains (for they may be different realms) --- pykolab/cli/cmd_list_domain_mailboxes.py | 83 ++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 pykolab/cli/cmd_list_domain_mailboxes.py diff --git a/pykolab/cli/cmd_list_domain_mailboxes.py b/pykolab/cli/cmd_list_domain_mailboxes.py new file mode 100644 index 0000000..684f1c8 --- /dev/null +++ b/pykolab/cli/cmd_list_domain_mailboxes.py @@ -0,0 +1,83 @@ +# -*- coding: utf-8 -*- +# Copyright 2010-2013 Kolab Systems AG (http://www.kolabsys.com) +# +# Jeroen van Meeuwen (Kolab Systems) +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 3 or, at your option, any later version +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Library General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +import commands + +import pykolab + +from pykolab import imap_utf7 +from pykolab.auth import Auth +from pykolab.imap import IMAP +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.cli') +conf = pykolab.getConf() + +def __init__(): + commands.register('list_domain_mailboxes', execute) + +def cli_options(): + my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) + my_option_group.add_option( '--raw', + dest = "raw", + action = "store_true", + default = False, + help = _("Display raw IMAP UTF-7 folder names")) + + my_option_group.add_option( '--server', + dest = "connect_server", + action = "store", + default = None, + metavar = "SERVER", + help = _("List mailboxes on server SERVER only.")) + +def execute(*args, **kw): + """ + List deleted mailboxes + """ + + try: + domain = conf.cli_args.pop(0) + except: + domain = utils.ask_question(_("Domain")) + + imap = IMAP() + imap.connect() + + auth = Auth() + auth.connect() + + domains = auth.list_domains() + + folders = [] + for primary,secondaries in domains: + if not domain == primary and not domain in secondaries: + continue + + folders.extend(imap.lm("user/%%@%s" % (primary))) + for secondary in secondaries: + folders.extend(imap.lm("user/%%@%s" % (secondary))) + + print "Deleted folders:" + + for folder in folders: + if not conf.raw: + print imap_utf7.decode(folder) + else: + print folder -- cgit v1.1