Commit 2e7c5da6 authored by Abhilash Raj's avatar Abhilash Raj

Merge branch 'test' into 'master'

Add support to mass unsubscribe members from mailing list.

Closes #43

See merge request !96
parents 2c589ddb e23ce648
Pipeline #54174399 failed with stage
in 1 minute and 37 seconds
......@@ -8,6 +8,7 @@ NEWS for mailmanclient
* Add a ``mail_host`` parameter to ``get_list_page`` and ``find_lists`` to
support filtering the response by a list domain.
* URL encode values in URL which are url unsafe. (Closes #44)
* Add support to mass unsubscribe memebrs from a Mailing List. (Closes #43)
3.2.2 (2019-02-09)
......
......@@ -440,6 +440,30 @@ If you try to unsubscribe an address which is not a member address
...
ValueError: [email protected] is not a member address of [email protected]
If we want to mass unsubscribe users.
>>> print(test_one.subscribe('[email protected]', 'Jack',
... pre_verified=True,
... pre_confirmed=True))
Member "[email protected]" on "test-1.example.com"
>>> print(test_one.subscribe('[email protected]', 'Jill',
... pre_verified=True,
... pre_confirmed=True))
Member "[email protected]" on "test-1.example.com"
>>> print(test_one.subscribe('[email protected]', 'Hans',
... pre_verified=True,
... pre_confirmed=True))
Member "[email protected]" on "test-1.example.com"
>>> email_list = ['[email protected]','[email protected]','[email protected]','[email protected]']
>>> ();test_one.mass_unsubscribe(email_list);() # doctest: +ELLIPSIS
(...)
>>> for member in test_one.members:
... print(member)
Member "[email protected]" on "test-1.example.com"
Non-Members
===========
......@@ -472,6 +496,9 @@ access the clients user property.
Anna
Bill
Cris
Jack
Jill
Hans
The list of users can also be paginated:
......@@ -479,8 +506,7 @@ The list of users can also be paginated:
>>> page.nr
1
>>> page.total_size
5
8
>>> for user in page:
... print(user.display_name)
Unverified
......@@ -497,6 +523,9 @@ You can get the next or previous pages without calling ``get_userpage`` again.
>>> for user in page:
... print(user.display_name)
Cris
Jack
Jill
Hans
>>> page = page.previous
>>> page.nr
......
......@@ -315,9 +315,6 @@ class MailingList(RESTObject):
:param address: The address to unsubscribe.
"""
# In order to get the member object we need to
# iterate over the existing member list
try:
path = 'lists/{0}/member/{1}'.format(self.list_id, email)
self._connection.call(path, method='DELETE')
......@@ -326,6 +323,22 @@ class MailingList(RESTObject):
raise ValueError('%s is not a member address of %s' %
(email, self.fqdn_listname))
def mass_unsubscribe(self, email_list):
"""Unsubscribe a list of emails from a mailing list.
This function return a json of emails mapped to booleans based
on whether they were unsubscribed or not, for whatever reasons
:param email_list: list of emails to unsubscribe
"""
try:
path = 'lists/{}/roster/member'.format(self.list_id)
response, content = self._connection.call(
path, {'emails': email_list}, 'DELETE')
return content
except HTTPError as e:
raise ValueError(str(e))
@property
def bans(self):
from mailmanclient.restobjects.ban import Bans
......
Markdown is supported
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