Ejemplo n.º 1
0
 def testAnywhereInThread(self):
     refs = emailfmt.GetReferences('*****@*****.**', 'hi', 0,
                                   emailfmt.NoReplyAddress())
     self.assertTrue(len(refs))
     self.assertTrue(refs.startswith('<0='))
Ejemplo n.º 2
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("'", '&#39;')
    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)
Ejemplo n.º 3
0
 def testNotPartOfThread(self):
     refs = emailfmt.GetReferences('*****@*****.**', 'hi', None,
                                   emailfmt.NoReplyAddress())
     self.assertEqual(0, len(refs))
Ejemplo n.º 4
0
                     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("'", '&#39;')
    template = HTML_BODY_WITH_GMAIL_ACTION_TEMPLATE
    if user and not 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')),
    }