Exemple #1
0
    def testReplyInvitation(self):
        """We include a footer about replying that is appropriate for that user."""
        email_task = notify_helpers._MakeEmailWorkItem(
            notify_reasons.AddrPerm(True, '*****@*****.**', self.member,
                                    REPLY_NOT_ALLOWED), ['reason'], self.issue,
            'body non', 'body mem', self.project, 'example.com',
            self.commenter_view, self.detail_url)
        self.assertEqual(emailfmt.NoReplyAddress(), email_task['reply_to'])
        self.assertNotIn('Reply to this email', email_task['body'])

        email_task = notify_helpers._MakeEmailWorkItem(
            notify_reasons.AddrPerm(True, '*****@*****.**', self.member,
                                    REPLY_MAY_COMMENT), ['reason'], self.issue,
            'body non', 'body mem', self.project, 'example.com',
            self.commenter_view, self.detail_url)
        self.assertEqual(
            '%s@%s' % (self.project.project_name, emailfmt.MailDomain()),
            email_task['reply_to'])
        self.assertIn('Reply to this email to add a comment',
                      email_task['body'])
        self.assertNotIn('make changes', email_task['body'])

        email_task = notify_helpers._MakeEmailWorkItem(
            notify_reasons.AddrPerm(True, '*****@*****.**', self.member,
                                    REPLY_MAY_UPDATE), ['reason'], self.issue,
            'body non', 'body mem', self.project, 'example.com',
            self.commenter_view, self.detail_url)
        self.assertEqual(
            '%s@%s' % (self.project.project_name, emailfmt.MailDomain()),
            email_task['reply_to'])
        self.assertIn('Reply to this email to add a comment',
                      email_task['body'])
        self.assertIn('make updates', email_task['body'])
    def testValidateReferencesHeader(self):
        project = project_pb2.Project()
        project.project_name = 'open-open'
        subject = 'slipped disk'
        expected = emailfmt.MakeMessageID(
            '*****@*****.**', subject,
            '%s@%s' % (project.project_name, emailfmt.MailDomain()))
        self.assertTrue(
            emailfmt.ValidateReferencesHeader(expected, project,
                                              '*****@*****.**', subject))

        self.assertFalse(
            emailfmt.ValidateReferencesHeader(expected, project,
                                              '*****@*****.**',
                                              'something else'))

        self.assertFalse(
            emailfmt.ValidateReferencesHeader(expected, project,
                                              '*****@*****.**',
                                              subject))

        project.project_name = 'other-project'
        self.assertFalse(
            emailfmt.ValidateReferencesHeader(expected, project,
                                              '*****@*****.**', subject))
 def testTrivialCases(self):
     self.assertEqual('testbed-test.appspotmail.com', emailfmt.MailDomain())
Exemple #4
0
def _MakeEmailWorkItem(addr_perm,
                       reasons,
                       issue,
                       body_for_non_members,
                       body_for_members,
                       project,
                       hostport,
                       commenter_view,
                       detail_url,
                       seq_num=None,
                       subject_prefix=None,
                       compact_subject_prefix=None):
    """Make one email task dict for one user, includes a detailed reason."""
    subject_format = ((subject_prefix or 'Issue ') +
                      '%(local_id)d in %(project_name)s: %(summary)s')
    if addr_perm.user and addr_perm.user.email_compact_subject:
        subject_format = ((compact_subject_prefix or '') +
                          '%(project_name)s:%(local_id)d: %(summary)s')

    subject = subject_format % {
        'local_id': issue.local_id,
        'project_name': issue.project_name,
        'summary': issue.summary,
    }

    footer = _MakeNotificationFooter(reasons, addr_perm.reply_perm, hostport)
    if isinstance(footer, unicode):
        footer = footer.encode('utf-8')
    if addr_perm.is_member:
        logging.info('got member %r, sending body for members',
                     addr_perm.address)
        body = _TruncateBody(body_for_members) + footer
    else:
        logging.info('got non-member %r, sending body for non-members',
                     addr_perm.address)
        body = _TruncateBody(body_for_non_members) + footer
    logging.info('sending message footer:\n%r', footer)

    can_reply_to = (addr_perm.reply_perm != notify_reasons.REPLY_NOT_ALLOWED
                    and project.process_inbound_email)
    from_addr = emailfmt.FormatFromAddr(project,
                                        commenter_view=commenter_view,
                                        reveal_addr=addr_perm.is_member,
                                        can_reply_to=can_reply_to)
    if can_reply_to:
        reply_to = '%s@%s' % (project.project_name, emailfmt.MailDomain())
    else:
        reply_to = emailfmt.NoReplyAddress()
    refs = emailfmt.GetReferences(
        addr_perm.address, subject, seq_num,
        '%s@%s' % (project.project_name, emailfmt.MailDomain()))
    # We use markup to display a convenient link that takes users directly to the
    # issue without clicking on the email.
    html_body = None
    # cgi.escape the body and additionally escape single quotes which are
    # occassionally used to contain HTML attributes and event handler
    # definitions.
    html_escaped_body = cgi.escape(body, quote=1).replace("'", ''')
    template = HTML_BODY_WITH_GMAIL_ACTION_TEMPLATE
    if addr_perm.user and not addr_perm.user.email_view_widget:
        template = HTML_BODY_WITHOUT_GMAIL_ACTION_TEMPLATE
    html_body = template % {
        'url': detail_url,
        'body': _AddHTMLTags(html_escaped_body.decode('utf-8')),
    }
    return dict(to=addr_perm.address,
                subject=subject,
                body=body,
                html_body=html_body,
                from_addr=from_addr,
                reply_to=reply_to,
                references=refs)
Exemple #5
0
        logging.info('got member %r, sending body for members', to_addr)
        body = _TruncateBody(body_for_members) + footer
    else:
        logging.info('got non-member %r, sending body for non-members',
                     to_addr)
        body = _TruncateBody(body_for_non_members) + footer
    logging.info('sending message footer:\n%r', footer)

    can_reply_to = (reply_perm != notify_reasons.REPLY_NOT_ALLOWED
                    and project.process_inbound_email)
    from_addr = emailfmt.FormatFromAddr(project,
                                        commenter_view=commenter_view,
                                        reveal_addr=recipient_is_member,
                                        can_reply_to=can_reply_to)
    if can_reply_to:
        reply_to = '%s@%s' % (project.project_name, emailfmt.MailDomain())
    else:
        reply_to = emailfmt.NoReplyAddress()
    refs = emailfmt.GetReferences(
        to_addr, subject, seq_num,
        '%s@%s' % (project.project_name, emailfmt.MailDomain()))
    # We use markup to display a convenient link that takes users directly to the
    # issue without clicking on the email.
    html_body = None
    # cgi.escape the body and additionally escape single quotes which are
    # occassionally used to contain HTML attributes and event handler
    # definitions.
    html_escaped_body = cgi.escape(body, quote=1).replace("'", ''')
    template = HTML_BODY_WITH_GMAIL_ACTION_TEMPLATE
    if user and not user.email_view_widget:
        template = HTML_BODY_WITHOUT_GMAIL_ACTION_TEMPLATE