From 329b11d8b7d8d11368e88a9d3b168c4cb2c22532 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Wed, 4 Dec 2013 10:39:41 +0100 Subject: [PATCH] imapt : add -l/--list parameter --- imapt | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/imapt b/imapt index a14e9c3..f557c5a 100755 --- a/imapt +++ b/imapt @@ -91,6 +91,13 @@ parser.add_option('-v', action="store_true", dest="verbose") +parser.add_option('-l', + '--list', + action="store_true", + dest="list", + help="List mailboxes", + default=False) + (options, args) = parser.parse_args() if options.verbose: @@ -141,14 +148,20 @@ if options.user: sys.exit(3) try: - logging.debug("Select mailbox") - ret = server.select(options.mailbox) - if len(ret)>0 and ret[0]=='OK': - logging.info("Mailbox %s content %s message(s)" % (options.mailbox,ret[1][0])) + if options.list: + logging.info('List mailbox') + (status,l) = server.list() + for d in l: + logging.info(' "%s"' % d) else: - logging.error("Selecting return incorrected : %s" % ret) + logging.debug("Select mailbox") + ret = server.select(options.mailbox) + if len(ret)>0 and ret[0]=='OK': + logging.info("Mailbox %s content %s message(s)" % (options.mailbox,ret[1][0])) + else: + logging.error("Selecting return incorrected : %s" % ret) + server.close() except Exception as e: logging.critical('Error selecting mailbox %s : %s' % (option.mailbox,e)) finally: - server.close() server.logout()