コード例 #1
0
ファイル: mailinglist.py プロジェクト: P-EB/mailman3-core
 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
コード例 #2
0
ファイル: mailinglist.py プロジェクト: TommyLike/mailman
 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
コード例 #3
0
ファイル: mailinglist.py プロジェクト: kaushikmit/mailman
 def subscribe(self, subscriber, role=MemberRole.member):
     """See `IMailingList`."""
     store = Store.of(self)
     if IAddress.providedBy(subscriber):
         member = store.find(
             Member,
             Member.role == role,
             Member.mailing_list == self.fqdn_listname,
             Member._address == subscriber).one()
         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.find(
             Member,
             Member.role == role,
             Member.mailing_list == self.fqdn_listname,
             Member._user == subscriber).one()
         if member:
             raise AlreadySubscribedError(
                 self.fqdn_listname, subscriber, role)
     else:
         raise ValueError('subscriber must be an address or user')
     member = Member(role=role,
                     mailing_list=self.fqdn_listname,
                     subscriber=subscriber)
     member.preferences = Preferences()
     store.add(member)
     return member
コード例 #4
0
 def subscribe(self, store, subscriber, role=MemberRole.member):
     """See `IMailingList`."""
     member, email = self._get_subscriber(store, subscriber, role)
     if member is not None:
         raise AlreadySubscribedError(self.fqdn_listname, email, role)
     member = Member(role=role,
                     list_id=self._list_id,
                     subscriber=subscriber)
     member.preferences = Preferences()
     store.add(member)
     notify(SubscriptionEvent(self, member))
     return member
コード例 #5
0
 def test_decorate_user_name_or_address_as_address(self):
     site_dir = os.path.join(config.TEMPLATE_DIR, 'site', 'en')
     os.makedirs(site_dir)
     footer_path = os.path.join(site_dir, 'myfooter.txt')
     with open(footer_path, 'w', encoding='utf-8') as fp:
         print('$user_name_or_address', file=fp)
     getUtility(ITemplateManager).set('list:member:regular:footer', None,
                                      'mailman:///myfooter.txt')
     self._mlist.preferred_language = 'en'
     user = getUtility(IUserManager).make_user('*****@*****.**')
     member = Member(MemberRole.member, self._mlist.list_id, user)
     member.preferences = Preferences()
     member.preferences.preferred_language = 'en'
     msgdata = dict(member=member)
     decorate.process(self._mlist, self._msg, msgdata)
     self.assertIn('*****@*****.**', self._msg.as_string())
コード例 #6
0
 def subscribe(self, store, subscriber, role=MemberRole.member,
               send_welcome_message=None):
     """See `IMailingList`."""
     member, email = self._get_subscriber(store, subscriber, role)
     test_email = email or subscriber.lower()
     # Allow list posting address only for nonmember role.
     if (test_email == self.posting_address and
             role != MemberRole.nonmember):
         raise InvalidEmailAddressError('List posting address not allowed')
     if member is not None:
         raise AlreadySubscribedError(self.fqdn_listname, email, role)
     if IBanManager(self).is_banned(test_email):
         raise MembershipIsBannedError(self, test_email)
     member = Member(role=role,
                     list_id=self._list_id,
                     subscriber=subscriber)
     member.preferences = Preferences()
     store.add(member)
     notify(SubscriptionEvent(
         self, member, send_welcome_message=send_welcome_message))
     return member