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 testObscuredCommenter(self): commenter_view = framework_views.StuffUserView(111, '*****@*****.**', True) self.assertEqual( u'u\u2026 via monorail ' '<*****@*****.**>', emailfmt.NoReplyAddress(commenter_view=commenter_view, reveal_addr=False))
def testInboundEmailDisabled(self): """We don't invite replies if they are disabled for this project.""" self.project.process_inbound_email = False 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(emailfmt.NoReplyAddress(), email_task['reply_to'])
def testBodySelection_NonMember(self): """We send non-members the email body that is indented for non-members.""" email_task = notify_helpers._MakeEmailWorkItem( notify_reasons.AddrPerm(False, '*****@*****.**', self.member, REPLY_NOT_ALLOWED, user_pb2.UserPrefs()), ['reason'], self.issue, 'body link-only', 'body non', 'body mem', self.project, 'example.com', self.commenter_view, self.detail_url) self.assertEqual('*****@*****.**', email_task['to']) self.assertEqual('Issue 1234 in proj1: summary', email_task['subject']) self.assertIn('body non', email_task['body']) self.assertEqual( emailfmt.FormatFromAddr(self.project, commenter_view=self.commenter_view, can_reply_to=False), email_task['from_addr']) self.assertEqual(emailfmt.NoReplyAddress(), email_task['reply_to'])
def _MakeErrorMessageReplyTask( project_addr, sender_addr, template, **callers_page_data): """Return a new task to send an error message email. Args: project_addr: string email address that the inbound email was delivered to. sender_addr: string email address of user who sent the email that we could not process. template: EZT template used to generate the email error message. The first line of this generated text will be used as the subject line. callers_page_data: template data dict for body of the message. Returns: A list with a single Email task that can be enqueued to actually send the email. Raises: ValueError: if the template does begin with a "Subject:" line. """ email_data = { 'project_addr': project_addr, 'sender_addr': sender_addr } email_data.update(callers_page_data) generated_lines = template.GetResponse(email_data) subject, body = generated_lines.split('\n', 1) if subject.startswith('Subject: '): subject = subject[len('Subject: '):] else: raise ValueError('Email template does not begin with "Subject:" line.') email_task = dict(to=sender_addr, subject=subject, body=body, from_addr=emailfmt.NoReplyAddress()) logging.info('sending email error reply: %r', email_task) return [email_task]
def testAnywhereInThread(self): refs = emailfmt.GetReferences('*****@*****.**', 'hi', 0, emailfmt.NoReplyAddress()) self.assertTrue(len(refs)) self.assertTrue(refs.startswith('<0='))
def testNotPartOfThread(self): refs = emailfmt.GetReferences('*****@*****.**', 'hi', None, emailfmt.NoReplyAddress()) self.assertEqual(0, len(refs))
def testNoCommenter(self): self.assertEqual('*****@*****.**', emailfmt.NoReplyAddress())
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)
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 html_body = template % { 'url': detail_url,