summaryrefslogtreecommitdiffstats
path: root/pykolab
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-10-15 12:06:38 +0200
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-10-15 12:06:38 +0200
commit9d1c8edc7060d161eb3f1fd1e87a33dd2568e78f (patch)
treec7674e318eba7170f4c6c63b3ea83cb8083ac4a1 /pykolab
parent52fff7eda260080a9feacdcde80bc5243f922393 (diff)
downloadpykolab-9d1c8edc7060d161eb3f1fd1e87a33dd2568e78f.tar.gz
Make sure mailboxes that are in a domain in IMAP actually have the equivalent domain entry in LDAP
Diffstat (limited to 'pykolab')
-rw-r--r--pykolab/cli/cmd_sync_mailhost_attrs.py49
1 files changed, 47 insertions, 2 deletions
diff --git a/pykolab/cli/cmd_sync_mailhost_attrs.py b/pykolab/cli/cmd_sync_mailhost_attrs.py
index 0f2e4d9..c5d2081 100644
--- a/pykolab/cli/cmd_sync_mailhost_attrs.py
+++ b/pykolab/cli/cmd_sync_mailhost_attrs.py
@@ -73,7 +73,49 @@ def execute(*args, **kw):
domains = auth.list_domains()
- for primary,secondaries in domains:
+ folders = imap.lm()
+
+ imap_domains_not_domains = []
+
+ for folder in folders:
+ if len(folder.split('@')) > 1 and not folder.startswith('DELETED'):
+ _folder_domain = folder.split('@')[-1]
+ if not _folder_domain in list(set(domains.keys() + domains.values())):
+ imap_domains_not_domains.append(folder.split('@')[-1])
+
+ imap_domains_not_domains = list(set(imap_domains_not_domains))
+
+ log.debug(_("Domains in IMAP not in LDAP: %r") % (imap_domains_not_domains), level=8)
+
+ if len(imap_domains_not_domains) > 0:
+ for domain in imap_domains_not_domains:
+ folders = []
+
+ folders.extend(imap.lm('shared/%%@%s' % (domain)))
+ folders.extend(imap.lm('user/%%@%s' % (domain)))
+
+ for folder in folders:
+ if conf.delete:
+ if conf.dry_run:
+ if not folder.split('/')[0] == 'shared':
+ log.warning(_("No recipients for '%s' (would have deleted the mailbox if not for --dry-run)!") % ('/'.join(folder.split('/')[1:])))
+ else:
+ continue
+ else:
+ if not '/'.join(folder.split('/')[0]) == 'shared':
+ log.info(_("Deleting mailbox '%s' because it has no recipients") % (folder))
+ try:
+ imap.dm(folder)
+ except Exception, errmsg:
+ log.error(_("An error occurred removing mailbox %r: %r") % (folder, errmsg))
+ else:
+ log.info(_("Not automatically deleting shared folder '%s'") % (folder))
+ else:
+ log.warning(_("No recipients for '%s' (use --delete to delete)!") % ('/'.join(folder.split('/')[1:])))
+
+ for primary in list(set(domains.values())):
+ secondaries = [x for x in domains.keys() if domains[x] == primary]
+
folders = []
folders.extend(imap.lm('shared/%%@%s' % (primary)))
@@ -103,7 +145,10 @@ def execute(*args, **kw):
else:
if not '/'.join(folder.split('/')[0]) == 'shared':
log.info(_("Deleting mailbox '%s' because it has no recipients") % (folder))
- imap.dm(folder)
+ try:
+ imap.dm(folder)
+ except Exception, errmsg:
+ log.error(_("An error occurred removing mailbox %r: %r") % (folder, errmsg))
else:
log.info(_("Not automatically deleting shared folder '%s'") % (folder))
else: