Changeset View
Changeset View
Standalone View
Standalone View
pykolab/cli/cmd_sync_mailhost_attrs.py
Show All 32 Lines | def __init__(): | ||||
commands.register('sync_mailhost_attrs', execute, description=description()) | commands.register('sync_mailhost_attrs', execute, description=description()) | ||||
def description(): | def description(): | ||||
return "Synchronize mailHost attribute values with the actual mailserver in a Cyrus IMAP Murder.\n" | return "Synchronize mailHost attribute values with the actual mailserver in a Cyrus IMAP Murder.\n" | ||||
def cli_options(): | def cli_options(): | ||||
my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) | my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) | ||||
my_option_group.add_option( '--delete', | my_option_group.add_option( '--delete', | ||||
dest = "delete", | dest = "delete", | ||||
Lint: PEP8 E221: multiple spaces before operator | |||||
action = "store_true", | action = "store_true", | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
default = False, | default = False, | ||||
help = _("Delete mailboxes for recipients that do not appear to exist in LDAP.")) | help = _("Delete mailboxes for recipients that do not appear to exist in LDAP.")) | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
my_option_group.add_option( '--dry-run', | my_option_group.add_option( '--dry-run', | ||||
dest = "dry_run", | dest = "dry_run", | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
action = "store_true", | action = "store_true", | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
default = False, | default = False, | ||||
help = _("Display changes, do not apply them.")) | help = _("Display changes, do not apply them.")) | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
my_option_group.add_option( '--server', | my_option_group.add_option( '--server', | ||||
dest = "connect_server", | dest = "connect_server", | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
action = "store", | action = "store", | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
default = None, | default = None, | ||||
metavar = "SERVER", | metavar = "SERVER", | ||||
help = _("List mailboxes on server SERVER only.")) | help = _("List mailboxes on server SERVER only.")) | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
def execute(*args, **kw): | def execute(*args, **kw): | ||||
""" | """ | ||||
Synchronize or display changes | Synchronize or display changes | ||||
""" | """ | ||||
imap = IMAP() | imap = IMAP() | ||||
if not conf.connect_server == None: | if not conf.connect_server == None: | ||||
imap.connect(server=conf.connect_server) | imap.connect(server=conf.connect_server) | ||||
else: | else: | ||||
imap.connect() | imap.connect() | ||||
auth = Auth() | auth = Auth() | ||||
auth.connect() | auth.connect() | ||||
domains = auth.list_domains() | result_attribute = conf.get('cyrus-sasl', 'result_attribute') | ||||
if result_attribute is None: | |||||
result_attribute = 'mail' | |||||
domains = auth.list_domains() | |||||
folders = imap.lm() | folders = imap.lm() | ||||
imap_domains_not_domains = [] | imap_domains_not_domains = [] | ||||
for folder in folders: | for folder in folders: | ||||
if len(folder.split('@')) > 1 and not folder.startswith('DELETED'): | if len(folder.split('@')) > 1 and not folder.startswith('DELETED'): | ||||
_folder_domain = folder.split('@')[-1] | _folder_domain = folder.split('@')[-1] | ||||
if not _folder_domain in list(set(domains.keys() + domains.values())): | if not _folder_domain in list(set(domains.keys() + domains.values())): | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | for primary in list(set(domains.values())): | ||||
for folder in folders: | for folder in folders: | ||||
server = imap.user_mailbox_server(folder) | server = imap.user_mailbox_server(folder) | ||||
r_folder = folder | r_folder = folder | ||||
if folder.startswith('shared/'): | if folder.startswith('shared/'): | ||||
recipient = auth.find_folder_resource(folder) | recipient = auth.find_folder_resource(folder) | ||||
else: | else: | ||||
r_folder = '/'.join(folder.split('/')[1:]) | r_folder = '/'.join(folder.split('/')[1:]) | ||||
recipient = auth.find_recipient(r_folder) | recipient = auth.find_recipient(r_folder, search_attrs=[result_attribute]) | ||||
if (isinstance(recipient, list)): | if (isinstance(recipient, list)): | ||||
if len(recipient) > 1: | if len(recipient) > 1: | ||||
log.warning(_("Multiple recipients for '%s'!") % (r_folder)) | log.warning(_("Multiple recipients for '%s'!") % (r_folder)) | ||||
continue | continue | ||||
elif len(recipient) == 0: | elif len(recipient) == 0: | ||||
if conf.delete: | if conf.delete: | ||||
if conf.dry_run: | if conf.dry_run: | ||||
Show All 31 Lines | def execute(*args, **kw): | ||||
auth.connect() | auth.connect() | ||||
for folder in folders: | for folder in folders: | ||||
server = imap.user_mailbox_server(folder) | server = imap.user_mailbox_server(folder) | ||||
if folder.startswith('shared/'): | if folder.startswith('shared/'): | ||||
recipient = auth.find_folder_resource(folder) | recipient = auth.find_folder_resource(folder) | ||||
else: | else: | ||||
recipient = auth.find_recipient('/'.join(folder.split('/')[1:])) | recipient = auth.find_recipient('/'.join(folder.split('/')[1:]), search_attrs=[result_attribute]) | ||||
print folder, server, recipient | print folder, server, recipient |
multiple spaces before operator