def test_multipart(self):
   # Text first
   msg = MIMEMultipart('alternative')
   msg['Subject'] = 'subject (issue%s)' % self.issue.key.id()
   msg['From'] = '*****@*****.**'
   msg.attach(MIMEText('body', 'plain'))
   msg.attach(MIMEText('ignore', 'html'))
   views._process_incoming_mail(msg.as_string(), '*****@*****.**')
   imsg = models.Message.query(ancestor=self.issue.key).get()
   self.assertEqual(imsg.text, 'body')
   imsg.key.delete()
   # HTML first
   msg = MIMEMultipart('alternative')
   msg['Subject'] = 'subject (issue%s)' % self.issue.key.id()
   msg['From'] = '*****@*****.**'
   msg.attach(MIMEText('ignore', 'html'))
   msg.attach(MIMEText('body', 'plain'))
   views._process_incoming_mail(msg.as_string(), '*****@*****.**')
   imsg = models.Message.query(ancestor=self.issue.key).get()
   self.assertEqual(imsg.text, 'body')
   imsg.key.delete()
   # no text at all
   msg = MIMEMultipart('alternative')
   msg['Subject'] = 'subject (issue%s)' % self.issue.key.id()
   msg['From'] = '*****@*****.**'
   msg.attach(MIMEText('ignore', 'html'))
   self.assertRaises(views.InvalidIncomingEmailError,
                     views._process_incoming_mail, msg.as_string(),
                     '*****@*****.**')
 def test_multipart(self):
     # Text first
     msg = MIMEMultipart("alternative")
     msg["Subject"] = "subject (issue%s)" % self.issue.key().id()
     msg["From"] = "*****@*****.**"
     msg.attach(MIMEText("body", "plain"))
     msg.attach(MIMEText("ignore", "html"))
     views._process_incoming_mail(msg.as_string(), "*****@*****.**")
     imsg = models.Message.all().ancestor(self.issue).get()
     self.assertEqual(imsg.text, "body")
     imsg.delete()
     # HTML first
     msg = MIMEMultipart("alternative")
     msg["Subject"] = "subject (issue%s)" % self.issue.key().id()
     msg["From"] = "*****@*****.**"
     msg.attach(MIMEText("ignore", "html"))
     msg.attach(MIMEText("body", "plain"))
     views._process_incoming_mail(msg.as_string(), "*****@*****.**")
     imsg = models.Message.all().ancestor(self.issue).get()
     self.assertEqual(imsg.text, "body")
     imsg.delete()
     # no text at all
     msg = MIMEMultipart("alternative")
     msg["Subject"] = "subject (issue%s)" % self.issue.key().id()
     msg["From"] = "*****@*****.**"
     msg.attach(MIMEText("ignore", "html"))
     self.assertRaises(
         views.InvalidIncomingEmailError, views._process_incoming_mail, msg.as_string(), "*****@*****.**"
     )
Beispiel #3
0
 def test_multipart(self):
     # Text first
     msg = MIMEMultipart('alternative')
     msg['Subject'] = 'subject (issue{0!s})'.format(self.issue.key.id())
     msg['From'] = '*****@*****.**'
     msg.attach(MIMEText('body', 'plain'))
     msg.attach(MIMEText('ignore', 'html'))
     views._process_incoming_mail(msg.as_string(), '*****@*****.**')
     imsg = models.Message.query(ancestor=self.issue.key).get()
     self.assertEqual(imsg.text, 'body')
     imsg.key.delete()
     # HTML first
     msg = MIMEMultipart('alternative')
     msg['Subject'] = 'subject (issue{0!s})'.format(self.issue.key.id())
     msg['From'] = '*****@*****.**'
     msg.attach(MIMEText('ignore', 'html'))
     msg.attach(MIMEText('body', 'plain'))
     views._process_incoming_mail(msg.as_string(), '*****@*****.**')
     imsg = models.Message.query(ancestor=self.issue.key).get()
     self.assertEqual(imsg.text, 'body')
     imsg.key.delete()
     # no text at all
     msg = MIMEMultipart('alternative')
     msg['Subject'] = 'subject (issue{0!s})'.format(self.issue.key.id())
     msg['From'] = '*****@*****.**'
     msg.attach(MIMEText('ignore', 'html'))
     self.assertRaises(views.InvalidIncomingEmailError,
                       views._process_incoming_mail, msg.as_string(),
                       '*****@*****.**')
 def test_huge_body_is_truncated(self):  # see issue325
   msg = Message()
   msg['subject'] = 'subject (issue%s)' % self.issue.key.id()
   msg['From'] = '*****@*****.**'
   msg.set_payload('1' * 600 * 1024)
   views._process_incoming_mail(msg.as_string(), '*****@*****.**')
   imsg = models.Message.query(ancestor=self.issue.key).get()
   self.assertEqual(len(imsg.text), 500 * 1024)
   self.assert_(imsg.text.endswith('... (message truncated)'))
 def test_long_subjects(self):
   # multi-line subjects should be collapsed into a single line
   msg = Message()
   msg['Subject'] = ('foo '*30)+' (issue%s)' % self.issue.key.id()
   msg['From'] = '*****@*****.**'
   msg.set_payload('body')
   views._process_incoming_mail(msg.as_string(), '*****@*****.**')
   imsg = models.Message.query(ancestor=self.issue.key).get()
   self.assertEqual(len(imsg.subject.splitlines()), 1)
Beispiel #6
0
 def test_huge_body_is_truncated(self):  # see issue325
     msg = Message()
     msg['subject'] = 'subject (issue{0!s})'.format(self.issue.key.id())
     msg['From'] = '*****@*****.**'
     msg.set_payload('1' * 600 * 1024)
     views._process_incoming_mail(msg.as_string(), '*****@*****.**')
     imsg = models.Message.query(ancestor=self.issue.key).get()
     self.assertEqual(len(imsg.text), 500 * 1024)
     self.assert_(imsg.text.endswith('... (message truncated)'))
 def test_long_subjects(self):
     # multi-line subjects should be collapsed into a single line
     msg = Message()
     msg["Subject"] = ("foo " * 30) + " (issue%s)" % self.issue.key().id()
     msg["From"] = "*****@*****.**"
     msg.set_payload("body")
     views._process_incoming_mail(msg.as_string(), "*****@*****.**")
     imsg = models.Message.all().ancestor(self.issue).get()
     self.assertEqual(len(imsg.subject.splitlines()), 1)
 def test_long_subjects(self):
     # multi-line subjects should be collapsed into a single line
     msg = Message()
     msg['Subject'] = ('foo ' * 30) + ' (issue%s)' % self.issue.key().id()
     msg['From'] = '*****@*****.**'
     msg.set_payload('body')
     views._process_incoming_mail(msg.as_string(), '*****@*****.**')
     imsg = models.Message.all().ancestor(self.issue).get()
     self.assertEqual(len(imsg.subject.splitlines()), 1)
 def test_huge_body_is_truncated(self):  # see issue325
     msg = Message()
     msg["subject"] = "subject (issue%s)" % self.issue.key().id()
     msg["From"] = "*****@*****.**"
     msg.set_payload("1" * 600 * 1024)
     views._process_incoming_mail(msg.as_string(), "*****@*****.**")
     imsg = models.Message.all().ancestor(self.issue).get()
     self.assertEqual(len(imsg.text), 500 * 1024)
     self.assert_(imsg.text.endswith("... (message truncated)"))
Beispiel #10
0
 def test_charset(self):
   # make sure that incoming mails with non-ascii chars are handled correctly
   # see related http://code.google.com/p/googleappengine/issues/detail?id=2326
   jtxt = '\x1b$B%O%m!<%o!<%k%I!*\x1b(B'
   jcode = 'iso-2022-jp'
   msg = Message()
   msg.set_payload(jtxt, jcode)
   msg['Subject'] = 'subject (issue%s)' % self.issue.key.id()
   msg['From'] = '*****@*****.**'
   views._process_incoming_mail(msg.as_string(), '*****@*****.**')
   imsg = models.Message.query(ancestor=self.issue.key).get()
   self.assertEqual(imsg.text.encode(jcode), jtxt)
 def test_charset(self):
     # make sure that incoming mails with non-ascii chars are handled correctly
     # see related http://code.google.com/p/googleappengine/issues/detail?id=2326
     jtxt = "\x1b$B%O%m!<%o!<%k%I!*\x1b(B"
     jcode = "iso-2022-jp"
     msg = Message()
     msg.set_payload(jtxt, jcode)
     msg["Subject"] = "subject (issue%s)" % self.issue.key().id()
     msg["From"] = "*****@*****.**"
     views._process_incoming_mail(msg.as_string(), "*****@*****.**")
     imsg = models.Message.all().ancestor(self.issue).get()
     self.assertEqual(imsg.text.encode(jcode), jtxt)
Beispiel #12
0
 def test_charset(self):
     # make sure that incoming mails with non-ascii chars are handled correctly
     # see related http://code.google.com/p/googleappengine/issues/detail?id=2326
     jtxt = '\x1b$B%O%m!<%o!<%k%I!*\x1b(B'
     jcode = 'iso-2022-jp'
     msg = Message()
     msg.set_payload(jtxt, jcode)
     msg['Subject'] = 'subject (issue{0!s})'.format(self.issue.key.id())
     msg['From'] = '*****@*****.**'
     views._process_incoming_mail(msg.as_string(), '*****@*****.**')
     imsg = models.Message.query(ancestor=self.issue.key).get()
     self.assertEqual(imsg.text.encode(jcode), jtxt)
Beispiel #13
0
 def test_encoding(self):
     # make sure that incoming mails with 8bit encoding are handled correctly.
     # see realted http://code.google.com/p/googleappengine/issues/detail?id=2383
     jtxt = '\x1b$B%O%m!<%o!<%k%I!*\x1b(B'
     jcode = 'iso-2022-jp'
     msg = Message()
     msg.set_payload(jtxt, jcode)
     msg['Subject'] = 'subject (issue{0!s})'.format(self.issue.key.id())
     msg['From'] = '*****@*****.**'
     del msg['Content-Transfer-Encoding']  # replace 7bit encoding
     msg['Content-Transfer-Encoding'] = '8bit'
     views._process_incoming_mail(msg.as_string(), '*****@*****.**')
     imsg = models.Message.query(ancestor=self.issue.key).get()
     self.assertEqual(imsg.text.encode(jcode), jtxt)
Beispiel #14
0
 def test_encoding(self):
   # make sure that incoming mails with 8bit encoding are handled correctly.
   # see realted http://code.google.com/p/googleappengine/issues/detail?id=2383
   jtxt = '\x1b$B%O%m!<%o!<%k%I!*\x1b(B'
   jcode = 'iso-2022-jp'
   msg = Message()
   msg.set_payload(jtxt, jcode)
   msg['Subject'] = 'subject (issue%s)' % self.issue.key.id()
   msg['From'] = '*****@*****.**'
   del msg['Content-Transfer-Encoding']  # replace 7bit encoding
   msg['Content-Transfer-Encoding'] = '8bit'
   views._process_incoming_mail(msg.as_string(), '*****@*****.**')
   imsg = models.Message.query(ancestor=self.issue.key).get()
   self.assertEqual(imsg.text.encode(jcode), jtxt)
Beispiel #15
0
 def test_senders_becomes_reviewer(self):
     msg = Message()
     msg['From'] = '*****@*****.**'
     msg['Subject'] = 'subject (issue{0!s})'.format(self.issue.key.id())
     msg.set_payload('body')
     views._process_incoming_mail(msg.as_string(), '*****@*****.**')
     issue = models.Issue.get_by_id(self.issue.key.id())  # re-fetch issue
     self.assertEqual(issue.reviewers, ['*****@*****.**'])
     issue.reviewers = []
     issue.put()
     # try again with sender that has an account
     # we do this to handle CamelCase emails correctly
     models.Account.get_account_for_user(User('*****@*****.**'))
     views._process_incoming_mail(msg.as_string(), '*****@*****.**')
     issue = models.Issue.get_by_id(self.issue.key.id())
     self.assertEqual(issue.reviewers, ['*****@*****.**'])
 def test_senders_becomes_reviewer(self):
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Subject"] = "subject (issue%s)" % self.issue.key().id()
     msg.set_payload("body")
     views._process_incoming_mail(msg.as_string(), "*****@*****.**")
     issue = models.Issue.get_by_id(self.issue.key().id())  # re-fetch issue
     self.assertEqual(issue.reviewers, ["*****@*****.**"])
     issue.reviewers = []
     issue.put()
     # try again with sender that has an account
     # we do this to handle CamelCase emails correctly
     models.Account.get_account_for_user(User("*****@*****.**"))
     views._process_incoming_mail(msg.as_string(), "*****@*****.**")
     issue = models.Issue.get_by_id(self.issue.key().id())
     self.assertEqual(issue.reviewers, ["*****@*****.**"])
Beispiel #17
0
 def test_senders_becomes_reviewer(self):
   msg = Message()
   msg['From'] ='*****@*****.**'
   msg['Subject'] = 'subject (issue%s)' % self.issue.key.id()
   msg.set_payload('body')
   views._process_incoming_mail(msg.as_string(), '*****@*****.**')
   issue = models.Issue.get_by_id(self.issue.key.id())  # re-fetch issue
   self.assertEqual(issue.reviewers, ['*****@*****.**'])
   issue.reviewers = []
   issue.put()
   # try again with sender that has an account
   # we do this to handle CamelCase emails correctly
   models.Account.get_account_for_user(User('*****@*****.**'))
   views._process_incoming_mail(msg.as_string(), '*****@*****.**')
   issue = models.Issue.get_by_id(self.issue.key.id())
   self.assertEqual(issue.reviewers, ['*****@*****.**'])
Beispiel #18
0
 def test_missing_encoding(self):
     # make sure that incoming mails with missing encoding and
     # charset are handled correctly.
     body = 'Âfoo'
     msg = ('From: [email protected]',
            'Subject: subject (issue%s)' % self.issue.key().id(), '', body)
     views._process_incoming_mail('\r\n'.join(msg), '*****@*****.**')
     imsg = models.Message.all().ancestor(self.issue).get()
     self.assertEqual(imsg.text, u'Âfoo')
     imsg.delete()
     body = '\xf6'
     msg = ('From: [email protected]',
            'Subject: subject (issue%s)' % self.issue.key().id(), '', body)
     views._process_incoming_mail('\r\n'.join(msg), '*****@*****.**')
     imsg = models.Message.all().ancestor(self.issue).get()
     self.assertEqual(imsg.text, u'\ufffd')
Beispiel #19
0
 def test_missing_encoding(self):
   # make sure that incoming mails with missing encoding and
   # charset are handled correctly.
   body = 'Âfoo'
   msg = ('From: [email protected]',
          'Subject: subject (issue%s)' % self.issue.key.id(),
          '',
          body)
   views._process_incoming_mail('\r\n'.join(msg), '*****@*****.**')
   imsg = models.Message.query(ancestor=self.issue.key).get()
   self.assertEqual(imsg.text, u'Âfoo')
   imsg.key.delete()
   body = '\xf6'
   msg = ('From: [email protected]',
          'Subject: subject (issue%s)' % self.issue.key.id(),
          '',
          body)
   views._process_incoming_mail('\r\n'.join(msg), '*****@*****.**')
   imsg = models.Message.query(ancestor=self.issue.key).get()
   self.assertEqual(imsg.text, u'\ufffd')