Commit 3908f509 authored by Rafael Ostertag's avatar Rafael Ostertag
Browse files

Added 'set' operation.

parent ac9499ad
......@@ -38,27 +38,50 @@ class EmailList(managementagent.RabbitModule):
zmprov.communicate(input="".join(zmprov_lines))
def _create_members_set_command(self, list_name, members):
return_value = ""
operation = "zimbraMailForwardingAddress"
for member in members:
return_value += "modifyDistributionList %s %s %s\n" % (list_name, operation, member)
# if there is no '+' in front of zimbraMailForwardingAddress, it is the first iteration and we switch
# to '+zimbraMailForwardingAddress for subsequent iterations, in order to append entries to the list,
# instead of setting it the member
if operation[0] != '+':
operation = "+" + operation
return return_value
def _create_members_add_command(self, list_name, members):
return self._create_command("addDistributionListMember", list_name, members)
def _create_members_remove_command(self, list_name, members):
return self._create_command("removeDistributionListMember", list_name, members)
def _create_command(self, command, list_name, members):
return_value = ""
for member in members:
return_value += "%s %s %s\n" % (command, list_name, member)
return return_value
def _process_members_operations(self, members_operations):
zmprov = subprocess.Popen(EmailList.ZIMBRA_ZMPROV, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
zmprov_lines = list()
commands = ""
for operation in members_operations:
op = ""
if operation['operation'] == 'add':
op = 'addDistributionListMember'
commands += self._create_members_add_command(operation['name'], operation['entries'])
if operation['operation'] == 'remove':
op = 'removeDistributionListMember'
commands += self._create_members_remove_command(operation['name'], operation['entries'])
if operation['operation'] == 'set':
commands += self._create_members_set_command(operation['name'], operation['entries'])
if op == "":
continue
list_name = operation['name']
for member in operation['entries']:
zmprov_lines.append(op + " " + list_name + " " + member + "\n")
zmprov.communicate(input="".join(zmprov_lines))
zmprov.communicate(input=commands)
def process_message(self, message):
instructions = message.body
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment