def processMail(self):
        # XXX we need to go through pending interfaces ... maybe named adapters?
        # right now we are hard coding the annotations that we are using
        pend_list = self._get_a_s_pending_list()

        message = self.request.get('Mail')
        (header, body) = MailBoxerTools.splitMail(message)

        # get email-address
        sender = decode_header(header.get('from',''))
        (name, email) = MailBoxerTools.parseaddr(sender)
        email = email.encode('ascii', 'replace').lower()

        # get subject
        subject = decode_header(header.get('subject', ''))

        # if the user is already an allowed sender, we don't need to validate
        if IMembershipList(self.context).is_allowed_sender(email):
            return

        # check to see if the pin matches
        policy = getAdapter(self.context, IUserEmailMembershipPolicy)
        fake_request = dict(subject=subject, email=email)
        command_email = policy._get_email_for_pin(fake_request, pend_list)
        
        if not policy._check_pin(fake_request, pend_list):
            mail_sender = ISendMail(self.context)
            mail_sender.user_pin_mismatch(email, name)
            return

        if pend_list.is_pending(command_email):
            self.add_allowed_sender(email)
            pend_list.remove(command_email)
            if email != command_email:
                self._send_pending_posts(command_email)
        else:
            # XXX why are we getting in here?
            pass
예제 #2
0
    def processMail(self):
        # XXX we need to go through pending interfaces ... maybe named adapters?
        # right now we are hard coding the annotations that we are using
        pend_list = self._get_a_s_pending_list()

        message = self.request.get('Mail')
        (header, body) = MailBoxerTools.splitMail(message)

        # get email-address
        sender = decode_header(header.get('from', ''))
        (name, email) = MailBoxerTools.parseaddr(sender)
        email = email.encode('ascii', 'replace').lower()

        # get subject
        subject = decode_header(header.get('subject', ''))

        # if the user is already an allowed sender, we don't need to validate
        if IMembershipList(self.context).is_allowed_sender(email):
            return

        # check to see if the pin matches
        policy = getAdapter(self.context, IUserEmailMembershipPolicy)
        fake_request = dict(subject=subject, email=email)
        command_email = policy._get_email_for_pin(fake_request, pend_list)

        if not policy._check_pin(fake_request, pend_list):
            mail_sender = ISendMail(self.context)
            mail_sender.user_pin_mismatch(email, name)
            return

        if pend_list.is_pending(command_email):
            self.add_allowed_sender(email)
            pend_list.remove(command_email)
            if email != command_email:
                self._send_pending_posts(command_email)
        else:
            # XXX why are we getting in here?
            pass
예제 #3
0
 def __init__(self, context):
     self.context = context
     annot = IAnnotations(context)
     self.listen_annot = annot.setdefault(PROJECTNAME, OOBTree())
     self.mail_sender = ISendMail(context)
     self.mem_list = IWriteMembershipList(context)
def became_allowed_sender(event):
    """
    This function should ensure that all other pending allowed sender
    lists that the other policy adapters depend on are in sync.

    set up the phony mailing list and policies
    >>> from Products.listen.content.tests import DummyAnnotableList
    >>> from Products.listen.content.tests import DummyMembershipTool
    >>> from Products.listen.extras.tests import TestMailingList
    >>> from Products.listen.content.tests import DummyMember
    >>> from Products.listen.config import POST_DEFERRED, MEMBERSHIP_DEFERRED
    >>> ml = TestMailingList()
    >>> from zope.interface import alsoProvides
    >>> from Products.listen.interfaces import IPublicList
    >>> alsoProvides(ml, IPublicList)
    >>> mails_to_list = []
    >>> def listMail(post):
    ...     mails_to_list.append(post)
    >>> ml.listMail = listMail
    >>> from Products.listen.interfaces import IMailingList
    >>> dtool = DummyMembershipTool('foo')
    >>> dtool.result = None
    >>> ml.portal_membership = dtool
    >>> from Products.listen.content import WriteMembershipList
    >>> mlist = WriteMembershipList(ml)
    >>> from zope.component import getAdapter
    >>> from zope.component import provideAdapter
    >>> from Products.listen.interfaces import IEmailPostPolicy
    >>> from Products.listen.interfaces import IUserEmailMembershipPolicy
    >>> from Products.listen.content import PublicEmailPostPolicy
    >>> from Products.listen.content import UserMembershipPolicy
    >>> postpolicy = getAdapter(ml, IEmailPostPolicy)
    >>> mempolicy = getAdapter(ml, IUserEmailMembershipPolicy)

    send a subscribe email to get on the pending list
    >>> request = dict(email='*****@*****.**',
    ...                subject='subscribe')
    >>> mempolicy.enforce(request) == MEMBERSHIP_DEFERRED
    True

    now submit a post to get on that pending list
    >>> request = dict(email='*****@*****.**',
    ...                post=dict(header={}, body='there is only zul!'))
    >>> postpolicy.enforce(request) == POST_DEFERRED
    True

    now add the email as an allowed sender
    >>> mlist.add_allowed_sender('*****@*****.**')

    make sure he's not on the allowed sender pending list
    >>> from zope.annotation.interfaces import IAnnotations
    >>> annot = IAnnotations(ml)
    >>> listen_annot = annot['listen']
    >>> a_s_list = listen_annot['a_s_pending_sub_email']
    >>> '*****@*****.**' in a_s_list
    False

    verify that the post is no longer pending and has been sent out
    >>> post_list = listen_annot['pending_mod_post']
    >>> '*****@*****.**' in post_list
    False
    >>> 'there is only zul!' in mails_to_list[0]['Mail']
    True

    try with a mem-moderated list policy
    >>> from zope.interface import directlyProvides
    >>> from Products.listen.interfaces import IMembershipModeratedList
    >>> directlyProvides(ml, IMembershipModeratedList)
    >>> postpolicy = getAdapter(ml, IEmailPostPolicy)
    >>> request = dict(email='*****@*****.**',
    ...                post=dict(header={}, body='there is only zui!'))
    >>> postpolicy.enforce(request) == POST_DEFERRED
    True
    >>> mlist.add_allowed_sender('*****@*****.**')
    >>> '*****@*****.**' in post_list
    False
    >>> 'there is only zui!' in mails_to_list[1]['Mail']
    True

    make someone who is pending subscription moderation an allowed sender
    and make sure they get automatically subscribed
    >>> from Products.listen.interfaces import IMembershipPendingList
    >>> sub_mod_pending_list = getAdapter(ml, IMembershipPendingList, 'pending_sub_mod_email')
    >>> sub_mod_pending_list.add('*****@*****.**')
    >>> mlist.add_allowed_sender('*****@*****.**')
    >>> mlist.is_subscribed('*****@*****.**')
    True

    now try subscribing a member who is pending subscription moderation
    >>> sub_mod_pending_list.add('*****@*****.**')
    >>> mlist.subscribe('*****@*****.**')
    >>> mlist.is_subscribed('*****@*****.**')
    True

    """
    
    email = event.email
    context = event.context

    # clean up pending subscription
    pend_list = getAdapter(context, IPostPendingList, 'a_s_pending_sub_email')
    pend_list.remove(email)

    # if member is waiting for moderation to become a subscriber
    # then subscribe member
    sub_pending_list = getAdapter(context, IMembershipPendingList, 'pending_sub_mod_email')
    if sub_pending_list.is_pending(email):
        mlist = IWriteMembershipList(context)
        mail_sender = ISendMail(context)
        sub_pending_list.remove(email)
        mlist.subscribe(email)
        mail_sender.user_welcome(email, email)

    # clean up pending posts
    post_mod_list = getAdapter(context, IPostPendingList, 'pending_mod_post')
    # XXX currently expecting one post,
    # this is not the case for Post Moderated Lists
    # send the post for the user to the list
    posts = post_mod_list.get_posts(email)
    # uniquify posts
    post_dict = {}
    for p in posts:
        post_dict[p['body']] = p['header']
    posts = [dict(header=v, body=k) for k,v in post_dict.iteritems()]
    send_pending_posts(context, posts)
    post_mod_list.remove(email)