Commit 8b9c3a90 authored by Barry Warsaw's avatar Barry Warsaw

Members and subscriptions.

parent 4ef8888b
......@@ -37,6 +37,16 @@ from urlparse import urljoin
from mailman.client import __version__
def _member_key(member_dict):
"""Return the keys for sorting a member.
:param member_dict: The JSON dictionary for a member.
:return: 2-tuple of (fqdn_listname, address)
return (member_dict['fqdn_listname'], member_dict['address'])
class _Connection:
"""A connection to the REST client."""
......@@ -148,6 +158,15 @@ class Client:
for entry in sorted(content['entries'],
def members(self):
response, content ='members')
if 'entries' not in content:
return []
return [_Member(self._connection, entry['self_link'])
for entry in sorted(content['entries'],
def create_domain(self, email_host, base_url=None,
description=None, contact_address=None):
data = dict(email_host=email_host)
......@@ -252,3 +271,46 @@ class _List:
def real_name(self):
return self._info['real_name']
def subscribe(self, address, real_name=None):
"""Subscribe an email address to a mailing list.
:param address: Email address to subscribe to the list.
:type address: str
:param real_name: The real name of the new member.
:type real_name: str
data = dict(
response, content ='members', data)
return _Member(self._connection, response['location'])
class _Member:
def __init__(self, connection, url):
self._connection = connection
self._url = url
self._info = None
def __repr__(self):
return '<Member "{0}" on "{1}">'.format(
self.address, self.fqdn_listname)
def _get_info(self):
if self._info is None:
response, content =
self._info = content
def fqdn_listname(self):
return self._info['fqdn_listname']
def address(self):
return self._info['address']
......@@ -111,10 +111,49 @@ And you can print all the known mailing lists.
<List "">
>>> example.create_list('test-three')
<List "">
>>> for mlist in client.lists:
... print mlist
<List "">
<List "">
<List "">
<List "">
Email addresses can subscribe to existing mailing lists, becoming members of
that list. The address is a unique id for a specific user in the system, and
a member is a user that is subscribed to a mailing list. Email addresses need
not be pre-registered, though the auto-registered user will be unique for each
email address.
The system starts out with no members.
>>> client.members
New members can be easily added; users are automatically registered.
>>> test_two = client.get_list('')
>>> test_one.subscribe('', 'Anna')
<Member "" on "">
>>> test_one.subscribe('', 'Bill')
<Member "" on "">
>>> test_two.subscribe('')
<Member "" on "">
>>> test_two.subscribe('', 'Cris')
<Member "" on "">
We can retrieve all known memberships. These are sorted first by mailing list
name, then by email address.
>>> for member in client.members:
... print member
<Member "" on "">
<Member "" on "">
<Member "" on "">
<Member "" on "">
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