summaryrefslogtreecommitdiffstats
path: root/pykolab
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-08-02 11:28:55 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-08-02 11:28:55 +0100
commita3ed0383ff97f0ab5c03ba26426ea65e4a31f4e6 (patch)
treec871380260a0219e4bd2a38bf3a826f7c641a5b2 /pykolab
parentc97a99192dd74dcf67fca1d35f03042d84cd5fa3 (diff)
downloadpykolab-a3ed0383ff97f0ab5c03ba26426ea65e4a31f4e6.tar.gz
Add a command to list mailboxes for a specific domain including its alias domains (for they may be different realms)
Diffstat (limited to 'pykolab')
-rw-r--r--pykolab/cli/cmd_list_domain_mailboxes.py83
1 files changed, 83 insertions, 0 deletions
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) <vanmeeuwen a kolabsys.com>
+#
+# 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