summaryrefslogtreecommitdiffstats
path: root/pykolab
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-08-03 20:09:03 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-08-03 20:09:03 +0100
commit90c83a2e762943e0c8180b65b1426dfe1b6301bf (patch)
tree412584fc8fc4949aaa5e6d03b2ce96b50f740983 /pykolab
parent553e2c82142f405e772f480ecfc446ff91da17b7 (diff)
downloadpykolab-90c83a2e762943e0c8180b65b1426dfe1b6301bf.tar.gz
List deleted mailboxes with the deletion date
Diffstat (limited to 'pykolab')
-rw-r--r--pykolab/cli/cmd_list_deleted_mailboxes.py42
1 files changed, 40 insertions, 2 deletions
diff --git a/pykolab/cli/cmd_list_deleted_mailboxes.py b/pykolab/cli/cmd_list_deleted_mailboxes.py
index 79c253e..305a129 100644
--- a/pykolab/cli/cmd_list_deleted_mailboxes.py
+++ b/pykolab/cli/cmd_list_deleted_mailboxes.py
@@ -17,10 +17,14 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
+import datetime
+
import commands
import pykolab
+from pykolab import imap_utf7
+from pykolab.auth import Auth
from pykolab.imap import IMAP
from pykolab.translate import _
@@ -30,14 +34,48 @@ 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."))
+
def execute(*args, **kw):
"""
List deleted mailboxes
"""
imap = IMAP()
imap.connect()
- folders = imap.lm("DELETED/*")
+
+ auth = Auth()
+ auth.connect()
+
+ domains = auth.list_domains()
+
+ folders = []
+ for primary,secondaries in domains:
+ folders.extend(imap.lm("DELETED/*@%s" % (primary)))
+ for secondary in secondaries:
+ folders.extend(imap.lm("DELETED/*@%s" % (secondary)))
+
+ folders.extend(imap.lm("DELETED/*"))
+
print "Deleted folders:"
+
for folder in folders:
- print folder
+ mbox_parts = imap.parse_mailfolder(folder)
+
+ if not conf.raw:
+ print "%s (Deleted at %s)" % (imap_utf7.decode(folder), datetime.datetime.fromtimestamp(int(mbox_parts['hex_timestamp'], 16)))
+ else:
+ print "%s (Deleted at %s)" % (folder, datetime.datetime.fromtimestamp(int(mbox_parts['hex_timestamp'], 16)))