Beispiel #1
0
    def GET(self, mail, subscriber):
        """Check whether given subscriber is member of given mailing list."""
        mail = str(mail).lower()
        subscriber = str(subscriber).lower()

        qr = mlmmj.has_subscriber(mail=mail,
                                  subscriber=subscriber,
                                  subscription=None)

        return api_render(qr)
Beispiel #2
0
    def GET(self, subscriber):
        """Get mailing lists which the given subscriber subscribed to.

        :param subscriber: subscriber's email address.

        HTTP form parameters:

        `email_only`: if set to `yes`, return list of email addresses of subscribed lists.
        `query_all_lists`: If set to 'yes', will check all available mailing
                           lists on server. If 'no', check only lists under same
                           domain.
        """
        subscriber = str(subscriber).lower()
        domain = subscriber.split('@', 1)[-1]

        form = web.input()

        email_only = False
        if form.get('email_only') == 'yes':
            email_only = True

        # Get mail addresses of existing accounts
        if form.get('query_all_lists') == 'yes':
            qr = backend.get_existing_maillists(domains=None)
        else:
            qr = backend.get_existing_maillists(domains=[domain])

        if not qr[0]:
            return api_render(qr)

        existing_lists = qr[1]
        if not existing_lists:
            return api_render((True, []))

        subscribed_lists = []
        for i in existing_lists:
            qr = mlmmj.has_subscriber(mail=i,
                                      subscriber=subscriber,
                                      subscription=None)
            if qr:
                if email_only:
                    subscribed_lists.append(i)
                else:
                    subscribed_lists.append({'subscription': qr[1], 'mail': i})

        return api_render((True, list(subscribed_lists)))