def _get_subscriber(self, store, subscriber, role):
        """Get some information about a user/address.

        Returns a 2-tuple of (member, email) for the given subscriber.  If the
        subscriber is is not an ``IAddress`` or ``IUser``, then a 2-tuple of
        (None, None) is returned.  If the subscriber is not already
        subscribed, then (None, email) is returned.  If the subscriber is an
        ``IUser`` and does not have a preferred address, (member, None) is
        returned.
        """
        member = None
        email = None
        if IAddress.providedBy(subscriber):
            member = store.query(Member).filter(
                Member.role == role,
                Member.list_id == self._list_id,
                Member._address == subscriber).first()
            email = subscriber.email
        elif IUser.providedBy(subscriber):
            if subscriber.preferred_address is None:
                raise MissingPreferredAddressError(subscriber)
            email = subscriber.preferred_address.email
            member = store.query(Member).filter(
                Member.role == role,
                Member.list_id == self._list_id,
                Member._user == subscriber).first()
        return member, email
예제 #2
0
 def subscribe(self, store, subscriber, role=MemberRole.member):
     """See `IMailingList`."""
     if IAddress.providedBy(subscriber):
         member = store.query(Member).filter(
             Member.role == role, Member.list_id == self._list_id,
             Member._address == subscriber).first()
         if member:
             raise AlreadySubscribedError(self.fqdn_listname,
                                          subscriber.email, role)
     elif IUser.providedBy(subscriber):
         if subscriber.preferred_address is None:
             raise MissingPreferredAddressError(subscriber)
         member = store.query(Member).filter(
             Member.role == role, Member.list_id == self._list_id,
             Member._user == subscriber).first()
         if member:
             raise AlreadySubscribedError(
                 self.fqdn_listname, subscriber.preferred_address.email,
                 role)
     else:
         raise ValueError('subscriber must be an address or user')
     member = Member(role=role,
                     list_id=self._list_id,
                     subscriber=subscriber)
     member.preferences = Preferences()
     store.add(member)
     notify(SubscriptionEvent(self, member))
     return member