summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2020-02-23 10:46:05 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2020-02-23 11:03:35 +0100
commiteda247f3517e9ef9b0507c442957e7568e526724 (patch)
tree047aa02cdf7f0795c6106363ab0f9502a63180df
parent176b23c2b5ef24e368c384c4e30e6534e37fe7f6 (diff)
downloadpykolab-eda247f3517e9ef9b0507c442957e7568e526724.tar.gz
Add --server to list-deleted-mailboxes
-rw-r--r--pykolab/cli/cmd_list_deleted_mailboxes.py78
1 files changed, 56 insertions, 22 deletions
diff --git a/pykolab/cli/cmd_list_deleted_mailboxes.py b/pykolab/cli/cmd_list_deleted_mailboxes.py
index 55d90a6..6d07816 100644
--- a/pykolab/cli/cmd_list_deleted_mailboxes.py
+++ b/pykolab/cli/cmd_list_deleted_mailboxes.py
@@ -31,41 +31,75 @@ from pykolab.translate import _
log = pykolab.getLogger('pykolab.cli')
conf = pykolab.getConf()
+
def __init__():
commands.register('list_deleted_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."))
+
+ 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
"""
- imap = IMAP()
- imap.connect()
-
- auth = Auth()
- auth.connect()
-
- domains = auth.list_domains()
folders = []
- for domain in list(set(domains.keys())):
- folders.extend(imap.lm("DELETED/*@%s" % (domain)))
+ searches = []
+
+ imap = IMAP()
- folders.extend(imap.lm("DELETED/*"))
+ if conf.connect_server is not None:
+ imap.connect(server=conf.connect_server)
+ else:
+ imap.connect()
+
+ # See if conf.cli_args components make sense.
+ for arg in conf.cli_args:
+ if arg == '*':
+ searches.append(arg)
+ if arg.startswith('user'):
+ searches.append(arg)
+ if arg.startswith('shared'):
+ searches.append(arg)
+ if arg.startswith('DELETED'):
+ searches.append(arg)
+ if arg.startswith('news'):
+ searches.append(arg)
+
+ if len(searches) == 0:
+ auth = Auth()
+ auth.connect()
+
+ domains = auth.list_domains()
+
+ folders = []
+ for domain in list(set(domains.keys())):
+ folders.extend(imap.lm("DELETED/*@%s" % (domain)))
+
+ folders.extend(imap.lm("DELETED/*"))
+ else:
+ for search in searches:
+ log.debug(_("Appending folder search for %r") % (search), level=8)
+ folders.extend(imap.lm(imap_utf7.encode(search)))
print "Deleted folders:"