def members(self): response, content = self._connection.call('members') if 'entries' not in content: return [] return [ Member(self._connection, entry['self_link'], entry) for entry in content['entries'] ]
def members(self): url = 'lists/{0}/roster/member'.format(self.fqdn_listname) response, content = self._connection.call(url) if 'entries' not in content: return [] return [ Member(self._connection, entry['self_link'], entry) for entry in sorted(content['entries'], key=itemgetter('address')) ]
def nonmembers(self): url = 'members/find' data = {'role': 'nonmember', 'list_id': self.list_id} response, content = self._connection.call(url, data) if 'entries' not in content: return [] return [ Member(self._connection, entry['self_link'], entry) for entry in sorted(content['entries'], key=itemgetter('address')) ]
def get_member(self, email): """Get a membership. :param address: The email address of the member for this list. :return: A member proxy object. """ # In order to get the member object we query the REST API for # the member. Incase there is no matching subscription, an # HTTPError is returned instead. try: path = 'lists/{0}/member/{1}'.format(self.list_id, email) response, content = self._connection.call(path) return Member(self._connection, content['self_link'], content) except HTTPError: raise ValueError('%s is not a member address of %s' % (email, self.fqdn_listname))
def subscriptions(self): from mailmanclient.restobjects.member import Member if self._subscriptions is None: subscriptions = [] for address in self.addresses: response, content = self._connection.call( 'members/find', data={'subscriber': address}) try: for entry in content['entries']: subscriptions.append( Member(self._connection, entry['self_link'], entry)) except KeyError: pass self._subscriptions = subscriptions return self._subscriptions
def find_members(self, address, role='member', page=None, count=50): data = { 'subscriber': address, 'role': role, 'list_id': self.list_id, } url = 'members/find?{}'.format(urlencode(data, doseq=True)) if page is None: response, content = self._connection.call(url, data) if 'entries' not in content: return [] return [ Member(self._connection, entry['self_link'], entry) for entry in content['entries'] ] else: return Page(self._connection, url, Member, count, page)
def subscribe(self, address, display_name=None, pre_verified=False, pre_confirmed=False, pre_approved=False): """Subscribe an email address to a mailing list. :param address: Email address to subscribe to the list. :type address: str :param display_name: The real name of the new member. :param pre_verified: True if the address has been verified. :type pre_verified: bool :param pre_confirmed: True if membership has been approved by the user. :type pre_confirmed: bool :param pre_approved: True if membership is moderator-approved. :type pre_approved: bool :type display_name: str :return: A member proxy object. """ data = dict( list_id=self.list_id, subscriber=address, display_name=display_name, ) if pre_verified: data['pre_verified'] = True if pre_confirmed: data['pre_confirmed'] = True if pre_approved: data['pre_approved'] = True response, content = self._connection.call('members', data) # If a member is not immediately subscribed (i.e. verificatoin, # confirmation or approval need), the response content is returned. if response.status == 202: return content # I the subscription is executed immediately, a member object # is returned. return Member(self._connection, response['location'])