def handle_SubscriptionEvent(event):
    if not isinstance(event, SubscriptionEvent):
        return
    member = event.member
    # Only send notifications if a member (as opposed to a moderator,
    # non-member, or owner) is being subscribed.
    if member.role is not MemberRole.member:
        return
    mlist = member.mailing_list
    # Maybe send the list administrators a notification.
    if mlist.admin_notify_mchanges:
        subscriber = member.subscriber
        if IAddress.providedBy(subscriber):
            address = subscriber.email
            display_name = subscriber.display_name
        else:
            assert IUser.providedBy(subscriber)
            address = subscriber.preferred_address.email
            display_name = subscriber.display_name
        send_admin_subscription_notice(mlist, address, display_name)
    # Maybe send a welcome message to the new member. The event's flag
    # overrides the mailinglist's configuration, iff it is non-None.
    if ((event.send_welcome_message is None and mlist.send_welcome_message)
            or event.send_welcome_message):
        send_welcome_message(mlist, member, member.preferred_language)
Example #2
0
def handle_SubscriptionEvent(event):
    if not isinstance(event, SubscriptionEvent):
        return
    # Only send a notification message if the mailing list is configured to do
    # so, and the member being added is a list member (as opposed to a
    # moderator, non-member, or owner).
    member = event.member
    if member.role is not MemberRole.member:
        return
    mlist = member.mailing_list
    if not mlist.send_welcome_message:
        return
    send_welcome_message(mlist, member, member.preferred_language)
Example #3
0
def handle_SubscriptionEvent(event):
    if not isinstance(event, SubscriptionEvent):
        return
    # Only send a notification message if the mailing list is configured to do
    # so, and the member being added is a list member (as opposed to a
    # moderator, non-member, or owner).
    member = event.member
    if member.role is not MemberRole.member:
        return
    mlist = member.mailing_list
    if not mlist.send_welcome_message:
        return
    send_welcome_message(mlist, member, member.preferred_language)
Example #4
0
 def test_more_specific_welcome_message_nonenglish(self):
     # mlist.welcome_message_uri can contain placeholders for the fqdn list
     # name and language.
     self._mlist.welcome_message_uri = "mailman:///$listname/$language/welcome.txt"
     # Add the xx language and subscribe Anne using it.
     manager = getUtility(ILanguageManager)
     xx = manager.add("xx", "us-ascii", "Xlandia")
     add_member(self._mlist, "*****@*****.**", "Anne Person", "password", DeliveryMode.regular, "xx")
     send_welcome_message(self._mlist, "*****@*****.**", xx, DeliveryMode.regular)
     # Now there's one message in the virgin queue.
     messages = get_queue_messages("virgin")
     self.assertEqual(len(messages), 1)
     message = messages[0].msg
     self.assertEqual(str(message["subject"]), 'Welcome to the "Test List" mailing list')
     self.assertEqual(message.get_payload(), "You just joined the Test List mailing list!")
Example #5
0
def handle_subscription(mlist, id, action, comment=None):
    requestdb = IListRequests(mlist)
    if action is Action.defer:
        # Nothing to do.
        return
    elif action is Action.discard:
        # Nothing to do except delete the request from the database.
        pass
    elif action is Action.reject:
        key, data = requestdb.get_request(id)
        _refuse(mlist, _('Subscription request'),
                data['address'],
                comment or _('[No reason given]'),
                lang=getUtility(ILanguageManager)[data['language']])
    elif action is Action.accept:
        key, data = requestdb.get_request(id)
        enum_value = data['delivery_mode'].split('.')[-1]
        delivery_mode = DeliveryMode(enum_value)
        address = data['address']
        display_name = data['display_name']
        language = getUtility(ILanguageManager)[data['language']]
        password = data['password']
        try:
            add_member(mlist, address, display_name, password,
                       delivery_mode, language)
        except AlreadySubscribedError:
            # The address got subscribed in some other way after the original
            # request was made and accepted.
            pass
        else:
            if mlist.send_welcome_message:
                send_welcome_message(mlist, address, language, delivery_mode)
            if mlist.admin_notify_mchanges:
                send_admin_subscription_notice(
                    mlist, address, display_name, language)
        slog.info('%s: new %s, %s %s', mlist.fqdn_listname,
                  delivery_mode, formataddr((display_name, address)),
                  'via admin approval')
    else:
        raise AssertionError('Unexpected action: {0}'.format(action))
    # Delete the request from the database.
    requestdb.delete_request(id)
Example #6
0
 def test_more_specific_welcome_message_nonenglish(self):
     # mlist.welcome_message_uri can contain placeholders for the fqdn list
     # name and language.
     self._mlist.welcome_message_uri = (
         'mailman:///$listname/$language/welcome.txt')
     # Add the xx language and subscribe Anne using it.
     manager = getUtility(ILanguageManager)
     xx = manager.add('xx', 'us-ascii', 'Xlandia')
     add_member(self._mlist, '*****@*****.**', 'Anne Person',
                'password', DeliveryMode.regular, 'xx')
     send_welcome_message(self._mlist, '*****@*****.**', xx,
                          DeliveryMode.regular)
     # Now there's one message in the virgin queue.
     messages = get_queue_messages('virgin')
     self.assertEqual(len(messages), 1)
     message = messages[0].msg
     self.assertEqual(str(message['subject']),
                      'Welcome to the "Test List" mailing list')
     self.assertEqual(message.get_payload(),
                      'You just joined the Test List mailing list!')
Example #7
0
    def test_welcome_message(self):
        en = getUtility(ILanguageManager).get('en')
        add_member(self._mlist, '*****@*****.**', 'Anne Person',
                   'password', DeliveryMode.regular, 'en')
        send_welcome_message(self._mlist, '*****@*****.**', en,
                             DeliveryMode.regular)
        # Now there's one message in the virgin queue.
        messages = get_queue_messages('virgin')
        self.assertEqual(len(messages), 1)
        message = messages[0].msg
        self.assertEqual(str(message['subject']),
                         'Welcome to the "Test List" mailing list')
        self.assertMultiLineEqual(message.get_payload(), """\
Welcome to the Test List mailing list.

    Posting address: [email protected]
    Help and other requests: [email protected]
    Your name: Anne Person
    Your address: [email protected]
    Your options: http://example.com/[email protected]
""")
Example #8
0
    def test_welcome_message(self):
        en = getUtility(ILanguageManager).get("en")
        add_member(self._mlist, "*****@*****.**", "Anne Person", "password", DeliveryMode.regular, "en")
        send_welcome_message(self._mlist, "*****@*****.**", en, DeliveryMode.regular)
        # Now there's one message in the virgin queue.
        messages = get_queue_messages("virgin")
        self.assertEqual(len(messages), 1)
        message = messages[0].msg
        self.assertEqual(str(message["subject"]), 'Welcome to the "Test List" mailing list')
        self.eq(
            message.get_payload(),
            """\
Welcome to the Test List mailing list.

    Posting address: [email protected]
    Help and other requests: [email protected]
    Your name: Anne Person
    Your address: [email protected]
    Your options: http://example.com/[email protected]
""",
        )
Example #9
0
def handle_SubscriptionEvent(event):
    if not isinstance(event, SubscriptionEvent):
        return
    member = event.member
    # Only send notifications if a member (as opposed to a moderator,
    # non-member, or owner) is being subscribed.
    if member.role is not MemberRole.member:
        return
    mlist = member.mailing_list
    # Maybe send the list administrators a notification.
    if mlist.admin_notify_mchanges:
        subscriber = member.subscriber
        if IAddress.providedBy(subscriber):
            address = subscriber.email
            display_name = subscriber.display_name
        else:
            assert IUser.providedBy(subscriber)
            address = subscriber.preferred_address.email
            display_name = subscriber.display_name
        send_admin_subscription_notice(mlist, address, display_name)
    # Maybe send a welcome message to the new member.
    if mlist.send_welcome_message:
        send_welcome_message(mlist, member, member.preferred_language)
Example #10
0
 def confirm(self, token):
     """See `IUserRegistrar`."""
     # For convenience
     pendable = getUtility(IPendings).confirm(token)
     if pendable is None:
         return False
     missing = object()
     email = pendable.get("email", missing)
     display_name = pendable.get("display_name", missing)
     list_name = pendable.get("list_name", missing)
     pended_delivery_mode = pendable.get("delivery_mode", "regular")
     try:
         delivery_mode = DeliveryMode[pended_delivery_mode]
     except ValueError:
         log.error("Invalid pended delivery_mode for {0}: {1}", email, pended_delivery_mode)
         delivery_mode = DeliveryMode.regular
     if pendable.get("type") != PendableRegistration.PEND_KEY:
         # It seems like it would be very difficult to accurately guess
         # tokens, or brute force an attack on the SHA1 hash, so we'll just
         # throw the pendable away in that case.  It's possible we'll need
         # to repend the event or adjust the API to handle this case
         # better, but for now, the simpler the better.
         return False
     # We are going to end up with an IAddress for the verified address
     # and an IUser linked to this IAddress.  See if any of these objects
     # currently exist in our database.
     user_manager = getUtility(IUserManager)
     address = user_manager.get_address(email) if email is not missing else None
     user = user_manager.get_user(email) if email is not missing else None
     # If there is neither an address nor a user matching the confirmed
     # record, then create the user, which will in turn create the address
     # and link the two together
     if address is None:
         assert user is None, "How did we get a user but not an address?"
         user = user_manager.create_user(email, display_name)
         # Because the database changes haven't been flushed, we can't use
         # IUserManager.get_address() to find the IAddress just created
         # under the hood.  Instead, iterate through the IUser's addresses,
         # of which really there should be only one.
         for address in user.addresses:
             if address.email == email:
                 break
         else:
             raise AssertionError("Could not find expected IAddress")
     elif user is None:
         user = user_manager.create_user()
         user.display_name = display_name
         user.link(address)
     else:
         # The IAddress and linked IUser already exist, so all we need to
         # do is verify the address.
         pass
     address.verified_on = now()
     # If this registration is tied to a mailing list, subscribe the person
     # to the list right now, and possibly send a welcome message.
     list_name = pendable.get("list_name")
     if list_name is not None:
         mlist = getUtility(IListManager).get(list_name)
         if mlist:
             member = mlist.subscribe(address, MemberRole.member)
             member.preferences.delivery_mode = delivery_mode
             if mlist.send_welcome_message:
                 send_welcome_message(mlist, address.email, mlist.preferred_language, delivery_mode)
     return True