Exemple #1
0
def VALIDATE_EMAIL(parts=None,
                   reply_address_object=None,
                   from_address=None,
                   **kwargs):
    """process the validation email and save
    the email signature
    TODO: go a step further and
    """
    reply_code = reply_address_object.address

    if DEBUG_EMAIL:
        msg = 'Received email validation from %s\n' % from_address
        sys.stderr.write(msg.encode('utf-8'))

    try:
        content, stored_files, signature = mail.process_parts(
            parts, reply_code)

        user = reply_address_object.user

        if signature != user.email_signature:
            user.email_signature = signature

        user.email_isvalid = True
        user.save()

        from askbot.mail.messages import ReWelcomeEmail
        email = ReWelcomeEmail({'recipient_user': user})
        email.send([from_address])

    except ValueError:
        raise ValueError(
            _('Please reply to the welcome email '
              'without editing it'))
def ASK(message, host = None, addr = None):
    """lamson handler for asking by email,
    to the forum in general and to a specific group"""

    #we need to exclude some other emails by prefix
    if addr.startswith('reply-'):
        return
    if addr.startswith('welcome-'):
        return

    parts = get_parts(message)
    from_address = message.From
    #why lamson does not give it normally?
    subject = message['Subject'].strip('\n\t ')
    body_text, stored_files, unused = mail.process_parts(parts)
    if addr == 'ask':
        mail.process_emailed_question(
            from_address, subject, body_text, stored_files
        )
    else:
        #this is the Ask the group branch
        if askbot_settings.GROUP_EMAIL_ADDRESSES_ENABLED == False:
            return
        try:
            group = Group.objects.get(name__iexact=addr)
            mail.process_emailed_question(
                from_address, subject, body_text, stored_files,
                group_id = group.id
            )
        except Group.DoesNotExist:
            #do nothing because this handler will match all emails
            return
        except Tag.MultipleObjectsReturned:
            return
Exemple #3
0
def VALIDATE_EMAIL(parts=None,
                   reply_address_object=None,
                   from_address=None,
                   **kwargs):
    """process the validation email and save
    the email signature
    todo: go a step further and
    """
    reply_code = reply_address_object.address
    try:
        content, stored_files, signature = mail.process_parts(
            parts, reply_code)
        user = reply_address_object.user
        if signature and signature != user.email_signature:
            user.email_signature = signature
        user.email_isvalid = True
        user.save()

        data = {
            'site_name': askbot_settings.APP_SHORT_NAME,
            'site_url': askbot_settings.APP_URL,
            'ask_address': 'ask@' + askbot_settings.REPLY_BY_EMAIL_HOSTNAME
        }
        template = get_template('email/re_welcome_lamson_on.html')

        mail.send_mail(subject_line=_('Re: Welcome to %(site_name)s') % data,
                       body_text=template.render(Context(data)),
                       recipient_list=[
                           from_address,
                       ])
    except ValueError:
        raise ValueError(
            _('Please reply to the welcome email '
              'without editing it'))
Exemple #4
0
def VALIDATE_EMAIL(parts=None, reply_address_object=None, from_address=None, **kwargs):
    """process the validation email and save
    the email signature
    TODO: go a step further and
    """
    reply_code = reply_address_object.address

    if DEBUG_EMAIL:
        msg = 'Received email validation from %s\n' % from_address
        sys.stderr.write(msg.encode('utf-8'))

    try:
        content, stored_files, signature = mail.process_parts(parts, reply_code)

        user = reply_address_object.user

        if signature != user.email_signature:
            user.email_signature = signature

        user.email_isvalid = True
        user.save()

        from askbot.mail.messages import ReWelcomeEmail
        email = ReWelcomeEmail({'recipient_user': user})
        email.send([from_address])

    except ValueError:
        raise ValueError(
            _(
                'Please reply to the welcome email '
                'without editing it'
            )
        )
Exemple #5
0
def ASK(message, host=None, addr=None):
    """lamson handler for asking by email,
    to the forum in general and to a specific group"""

    #we need to exclude some other emails by prefix
    if addr.startswith('reply-'):
        return
    if addr.startswith('welcome-'):
        return

    parts = get_parts(message)
    from_address = message.From
    #why lamson does not give it normally?
    subject = message['Subject'].strip('\n\t ')
    body_text, stored_files, unused = mail.process_parts(parts)
    if addr == 'ask':
        mail.process_emailed_question(from_address, subject, body_text,
                                      stored_files)
    else:
        if askbot_settings.GROUP_EMAIL_ADDRESSES_ENABLED == False:
            return
        try:
            group_tag = Tag.group_tags.get(deleted=False, name__iexact=addr)
            mail.process_emailed_question(from_address,
                                          subject,
                                          body_text,
                                          stored_files,
                                          tags=[
                                              group_tag.name,
                                          ])
        except Tag.DoesNotExist:
            #do nothing because this handler will match all emails
            return
        except Tag.MultipleObjectsReturned:
            return
Exemple #6
0
def VALIDATE_EMAIL(parts=None, reply_address_object=None, from_address=None, **kwargs):
    """process the validation email and save
    the email signature
    todo: go a step further and
    """
    reply_code = reply_address_object.address
    try:
        content, stored_files, signature = mail.process_parts(parts, reply_code)
        user = reply_address_object.user
        if signature and signature != user.email_signature:
            user.email_signature = signature
        user.email_isvalid = True
        user.save()

        data = {
            "site_name": askbot_settings.APP_SHORT_NAME,
            "site_url": askbot_settings.APP_URL,
            "ask_address": "ask@" + askbot_settings.REPLY_BY_EMAIL_HOSTNAME,
        }
        template = get_template("email/re_welcome_lamson_on.html")

        mail.send_mail(
            subject_line=_("Re: Welcome to %(site_name)s") % data,
            body_text=template.render(Context(data)),
            recipient_list=[from_address],
        )
    except ValueError:
        raise ValueError(_("Please reply to the welcome email " "without editing it"))
Exemple #7
0
def ASK(message, host=None, addr=None):
    """lamson handler for asking by email,
    to the forum in general and to a specific group"""

    # we need to exclude some other emails by prefix
    if addr.startswith("reply-"):
        return
    if addr.startswith("welcome-"):
        return

    parts = get_parts(message)
    from_address = message.From
    # why lamson does not give it normally?
    subject = message["Subject"].strip("\n\t ")
    body_text, stored_files, unused = mail.process_parts(parts)
    if addr == "ask":
        mail.process_emailed_question(from_address, subject, body_text, stored_files)
    else:
        if askbot_settings.GROUP_EMAIL_ADDRESSES_ENABLED == False:
            return
        try:
            group_tag = Tag.group_tags.get(deleted=False, name__iexact=addr)
            mail.process_emailed_question(from_address, subject, body_text, stored_files, tags=[group_tag.name])
        except Tag.DoesNotExist:
            # do nothing because this handler will match all emails
            return
        except Tag.MultipleObjectsReturned:
            return
def PROCESS(
    parts = None,
    reply_address_object = None,
    subject_line = None,
    from_address = None,
    **kwargs
):
    """handler to process the emailed message
    and make a post to askbot based on the contents of
    the email, including the text body and the file attachments"""
    #1) get actual email content 
    #   todo: factor this out into the process_reply decorator
    reply_code = reply_address_object.address
    body_text, stored_files, signature = mail.process_parts(parts, reply_code)

    #2) process body text and email signature
    user = reply_address_object.user
    if signature:#if there, then it was stripped
        if signature != user.email_signature:
            user.email_signature = signature
    else:#try to strip signature
        stripped_body_text = user.strip_email_signature(body_text)
        #todo: add test cases for emails without the signature
        if stripped_body_text == body_text and user.email_signature:
            #todo: send an email asking to update the signature
            raise ValueError('email signature changed or unknown')
        body_text = stripped_body_text

    #3) validate email address and save user
    user.email_isvalid = True
    user.save()#todo: actually, saving is not necessary, if nothing changed

    #4) actually make an edit in the forum
    robj = reply_address_object
    add_post_actions = ('post_comment', 'post_answer', 'auto_answer_or_comment')
    if robj.reply_action == 'replace_content':
        robj.edit_post(body_text, title = subject_line)
    elif robj.reply_action == 'append_content':
        robj.edit_post(body_text)#in this case we don't touch the title
    elif robj.reply_action in add_post_actions:
        if robj.was_used:
            robj.edit_post(body_text, edit_response = True)
        else:
            robj.create_reply(body_text)
    elif robj.reply_action == 'validate_email':
        #todo: this is copy-paste - factor it out to askbot.mail.messages
        data = {
            'site_name': askbot_settings.APP_SHORT_NAME,
            'site_url': askbot_settings.APP_URL,
            'ask_address': 'ask@' + askbot_settings.REPLY_BY_EMAIL_HOSTNAME
        }
        template = get_template('email/re_welcome_lamson_on.html')

        mail.send_mail(
            subject_line = _('Re: %s') % subject_line,
            body_text = template.render(Context(data)),
            recipient_list = [from_address,]
        )
Exemple #9
0
def PROCESS(parts=None,
            reply_address_object=None,
            subject_line=None,
            from_address=None,
            **kwargs):
    """handler to process the emailed message
    and make a post to askbot based on the contents of
    the email, including the text body and the file attachments"""
    #1) get actual email content
    #   todo: factor this out into the process_reply decorator
    reply_code = reply_address_object.address
    body_text, stored_files, signature = mail.process_parts(parts, reply_code)

    #2) process body text and email signature
    user = reply_address_object.user
    if signature is not None:  #if there, then it was stripped
        if signature != user.email_signature:
            user.email_signature = signature
    else:  #try to strip signature
        stripped_body_text = user.strip_email_signature(body_text)
        #todo: add test cases for emails without the signature
        if stripped_body_text == body_text and user.email_signature:
            #todo: send an email asking to update the signature
            raise ValueError('email signature changed or unknown')
        body_text = stripped_body_text

    #3) validate email address and save user
    user.email_isvalid = True
    user.save()  #todo: actually, saving is not necessary, if nothing changed

    #4) actually make an edit in the forum
    robj = reply_address_object
    add_post_actions = ('post_comment', 'post_answer',
                        'auto_answer_or_comment')
    if robj.reply_action == 'replace_content':
        robj.edit_post(body_text, title=subject_line)
    elif robj.reply_action == 'append_content':
        robj.edit_post(body_text)  #in this case we don't touch the title
    elif robj.reply_action in add_post_actions:
        if robj.was_used:
            robj.edit_post(body_text, edit_response=True)
        else:
            robj.create_reply(body_text)
    elif robj.reply_action == 'validate_email':
        #todo: this is copy-paste - factor it out to askbot.mail.messages
        data = {
            'site_name': askbot_settings.APP_SHORT_NAME,
            'site_url': askbot_settings.APP_URL,
            'ask_address': 'ask@' + askbot_settings.REPLY_BY_EMAIL_HOSTNAME
        }
        template = get_template('email/re_welcome_lamson_on.html')

        mail.send_mail(
            subject_line=_('Re: %s') % subject_line,
            body_text=template.render(Context(data)),  #todo: set lang
            recipient_list=[
                from_address,
            ])
Exemple #10
0
def PROCESS(parts=None,
            reply_address_object=None,
            subject_line=None,
            from_address=None,
            **kwargs):
    """handler to process the emailed message
    and make a post to askbot based on the contents of
    the email, including the text body and the file attachments"""
    #1) get actual email content
    #   todo: factor this out into the process_reply decorator
    reply_code = reply_address_object.address
    body_text, stored_files, signature = mail.process_parts(
        parts, reply_code, from_address)

    #2) process body text and email signature
    user = reply_address_object.user

    if signature != user.email_signature:
        user.email_signature = signature

    #3) validate email address and save user along with maybe new signature
    user.email_isvalid = True
    user.save()  #todo: actually, saving is not necessary, if nothing changed

    #here we might be in danger of chomping off some of the
    #message is body text ends with a legitimate text coinciding with
    #the user's email signature
    body_text = user.strip_email_signature(body_text)

    #4) actually make an edit in the forum
    robj = reply_address_object
    add_post_actions = ('post_comment', 'post_answer',
                        'auto_answer_or_comment')
    if robj.reply_action == 'replace_content':
        robj.edit_post(body_text, title=subject_line)
    elif robj.reply_action == 'append_content':
        robj.edit_post(body_text)  #in this case we don't touch the title
    elif robj.reply_action in add_post_actions:
        if robj.was_used:
            robj.edit_post(body_text, edit_response=True)
        else:
            robj.create_reply(body_text)
    elif robj.reply_action == 'validate_email':
        #todo: this is copy-paste - factor it out to askbot.mail.messages
        data = {
            'site_name': askbot_settings.APP_SHORT_NAME,
            'site_url': site_url(reverse('questions')),
            'ask_address': 'ask@' + askbot_settings.REPLY_BY_EMAIL_HOSTNAME
        }
        template = get_template('email/re_welcome_lamson_on.html')

        mail.send_mail(
            subject_line=_('Re: %s') % subject_line,
            body_text=template.render(Context(data)),  #todo: set lang
            recipient_list=[
                from_address,
            ])
Exemple #11
0
def PROCESS(parts=None,
            reply_address_object=None,
            subject_line=None,
            from_address=None,
            **kwargs):
    """handler to process the emailed message
    and make a post to askbot based on the contents of
    the email, including the text body and the file attachments"""
    if DEBUG_EMAIL:
        sys.stderr.write(
            (u'Received reply from %s\n' % from_address).encode('utf-8'))
    #1) get actual email content
    #   todo: factor this out into the process_reply decorator
    reply_code = reply_address_object.address
    body_text, stored_files, signature = mail.process_parts(
        parts, reply_code, from_address)

    #2) process body text and email signature
    user = reply_address_object.user

    if signature != user.email_signature:
        user.email_signature = signature

    #3) validate email address and save user along with maybe new signature
    user.email_isvalid = True
    user.save()  #todo: actually, saving is not necessary, if nothing changed

    #here we might be in danger of chomping off some of the
    #message is body text ends with a legitimate text coinciding with
    #the user's email signature
    body_text = user.strip_email_signature(body_text)

    #4) actually make an edit in the forum
    robj = reply_address_object
    add_post_actions = ('post_comment', 'post_answer',
                        'auto_answer_or_comment')
    if robj.reply_action == 'replace_content':
        robj.edit_post(body_text, title=subject_line)
    elif robj.reply_action == 'append_content':
        robj.edit_post(body_text)  #in this case we don't touch the title
    elif robj.reply_action in add_post_actions:
        if robj.was_used:
            robj.edit_post(body_text, edit_response=True)
        else:
            robj.create_reply(body_text)
    elif robj.reply_action == 'validate_email':
        #todo: this is copy-paste - factor it out to askbot.mail.messages
        from askbot.mail.messages import ReWelcomeEmail
        email = ReWelcomeEmail({'recipient_user': robj.user})
        email.send([
            from_address,
        ])

        if DEBUG_EMAIL:
            msg = u'Sending welcome mail to %s\n' % from_address
            sys.stderr.write(msg.encode('utf-8'))
def PROCESS(
    parts = None,
    reply_address_object = None,
    subject_line = None,
    from_address = None,
    **kwargs
):
    """handler to process the emailed message
    and make a post to askbot based on the contents of
    the email, including the text body and the file attachments"""
    #1) get actual email content
    #   todo: factor this out into the process_reply decorator
    reply_code = reply_address_object.address
    body_text, stored_files, signature = mail.process_parts(parts, reply_code)

    #2) process body text and email signature
    user = reply_address_object.user

    if signature != user.email_signature:
        user.email_signature = signature

    #3) validate email address and save user along with maybe new signature
    user.email_isvalid = True
    user.save()#todo: actually, saving is not necessary, if nothing changed

    #here we might be in danger of chomping off some of the 
    #message is body text ends with a legitimate text coinciding with
    #the user's email signature
    body_text = user.strip_email_signature(body_text)

    #4) actually make an edit in the forum
    robj = reply_address_object
    add_post_actions = ('post_comment', 'post_answer', 'auto_answer_or_comment')
    if robj.reply_action == 'replace_content':
        robj.edit_post(body_text, title = subject_line)
    elif robj.reply_action == 'append_content':
        robj.edit_post(body_text)#in this case we don't touch the title
    elif robj.reply_action in add_post_actions:
        if robj.was_used:
            robj.edit_post(body_text, edit_response = True)
        else:
            robj.create_reply(body_text)
    elif robj.reply_action == 'validate_email':
        #todo: this is copy-paste - factor it out to askbot.mail.messages
        data = {
            'site_name': askbot_settings.APP_SHORT_NAME,
            'site_url': site_url(reverse('questions')),
            'ask_address': 'ask@' + askbot_settings.REPLY_BY_EMAIL_HOSTNAME
        }
        template = get_template('email/re_welcome_lamson_on.html')

        mail.send_mail(
            subject_line = _('Re: %s') % subject_line,
            body_text = template.render(Context(data)),#todo: set lang
            recipient_list = [from_address,]
        )
def PROCESS(
    parts = None,
    reply_address_object = None,
    subject_line = None,
    from_address = None,
    **kwargs
):
    """handler to process the emailed message
    and make a post to askbot based on the contents of
    the email, including the text body and the file attachments"""
    if DEBUG_EMAIL:
        sys.stderr.write(
            (u'Received reply from %s\n' % from_address).encode('utf-8')
        )
    #1) get actual email content
    #   todo: factor this out into the process_reply decorator
    reply_code = reply_address_object.address
    body_text, stored_files, signature = mail.process_parts(parts, reply_code, from_address)

    #2) process body text and email signature
    user = reply_address_object.user

    if signature != user.email_signature:
        user.email_signature = signature

    #3) validate email address and save user along with maybe new signature
    user.email_isvalid = True
    user.save()#todo: actually, saving is not necessary, if nothing changed

    #here we might be in danger of chomping off some of the
    #message is body text ends with a legitimate text coinciding with
    #the user's email signature
    body_text = user.strip_email_signature(body_text)

    #4) actually make an edit in the forum
    robj = reply_address_object
    add_post_actions = ('post_comment', 'post_answer', 'auto_answer_or_comment')
    if robj.reply_action == 'replace_content':
        robj.edit_post(body_text, title = subject_line)
    elif robj.reply_action == 'append_content':
        robj.edit_post(body_text)#in this case we don't touch the title
    elif robj.reply_action in add_post_actions:
        if robj.was_used:
            robj.edit_post(body_text, edit_response = True)
        else:
            robj.create_reply(body_text)
    elif robj.reply_action == 'validate_email':
        #todo: this is copy-paste - factor it out to askbot.mail.messages
        from askbot.mail.messages import ReWelcomeEmail
        email = ReWelcomeEmail({'recipient_user': robj.user})
        email.send([from_address,])

        if DEBUG_EMAIL:
            msg = u'Sending welcome mail to %s\n' % from_address
            sys.stderr.write(msg.encode('utf-8'))
def VALIDATE_EMAIL(
    parts = None,
    reply_address_object = None,
    from_address = None,
    **kwargs
):
    """process the validation email and save
    the email signature
    todo: go a step further and
    """
    reply_code = reply_address_object.address

    if DEBUG_EMAIL:
        msg = u'Received email validation from %s\n' % from_address
        sys.stderr.write(msg.encode('utf-8'))

    try:
        content, stored_files, signature = mail.process_parts(parts, reply_code)

        user = reply_address_object.user

        if signature != user.email_signature:
            user.email_signature = signature

        user.email_isvalid = True
        user.save()

        data = {
            'ask_address': 'ask@' + askbot_settings.REPLY_BY_EMAIL_HOSTNAME,
            'can_post_by_email': user.can_post_by_email(),
            'recipient_user': user,
            'site_name': askbot_settings.APP_SHORT_NAME,
            'site_url': site_url(reverse('questions')),
        }
        template = get_template('email/re_welcome_lamson_on.html')

        mail.send_mail(
            subject_line = _('Re: Welcome to %(site_name)s') % data,
            body_text = template.render(Context(data)),#todo: set lang
            recipient_list = [from_address,]
        )
    except ValueError:
        raise ValueError(
            _(
                'Please reply to the welcome email '
                'without editing it'
            )
        )
Exemple #15
0
def VALIDATE_EMAIL(
    parts = None,
    reply_address_object = None,
    from_address = None,
    **kwargs
):
    """process the validation email and save
    the email signature
    todo: go a step further and
    """
    reply_code = reply_address_object.address

    if DEBUG_EMAIL:
        msg = u'Received email validation from %s\n' % from_address
        sys.stderr.write(msg.encode('utf-8'))

    try:
        content, stored_files, signature = mail.process_parts(parts, reply_code)

        user = reply_address_object.user

        if signature != user.email_signature:
            user.email_signature = signature

        user.email_isvalid = True
        user.save()

        data = {
            'site_name': askbot_settings.APP_SHORT_NAME,
            'site_url': site_url(reverse('questions')),
            'ask_address': 'ask@' + askbot_settings.REPLY_BY_EMAIL_HOSTNAME,
            'can_post_by_email': user.can_post_by_email()
        }
        template = get_template('email/re_welcome_lamson_on.html')

        mail.send_mail(
            subject_line = _('Re: Welcome to %(site_name)s') % data,
            body_text = template.render(Context(data)),#todo: set lang
            recipient_list = [from_address,]
        )
    except ValueError:
        raise ValueError(
            _(
                'Please reply to the welcome email '
                'without editing it'
            )
        )
def ASK(message, host = None, addr = None):
    """lamson handler for asking by email,
    to the forum in general and to a specific group"""

    #we need to exclude some other emails by prefix
    if addr.startswith('reply-'):
        return
    if addr.startswith('welcome-'):
        return

    parts = get_parts(message)
    from_address = message.From

    if DEBUG_EMAIL:
        sys.stderr.write(
            (u'Received email from %s\n' % from_address).encode('utf-8')
        )


    #why lamson does not give it normally?
    subject = message['Subject'].strip('\n\t ')
    body_text, stored_files, unused = mail.process_parts(parts)
    if addr == 'ask':
        mail.process_emailed_question(
            from_address, subject, body_text, stored_files
        )
    else:
        #this is the Ask the group branch
        if askbot_settings.GROUP_EMAIL_ADDRESSES_ENABLED == False:
            return
        try:
            group = Group.objects.get(name__iexact=addr)
            mail.process_emailed_question(
                from_address, subject, body_text, stored_files,
                group_id = group.id
            )
        except Group.DoesNotExist:
            #do nothing because this handler will match all emails
            return
        except Tag.MultipleObjectsReturned:
            return