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)
示例#2
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)
示例#3
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)
        delivery_mode = DeliveryMode[data['delivery_mode']]
        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.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)
示例#4
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)