Ejemplo n.º 1
0
 def test_MakeMessage_with_binary_attachment(self):
     """Message should still encode as ascii with non-ascii attachments."""
     ctrl = MailController('*****@*****.**', '*****@*****.**', 'subject',
                           u'Body')
     ctrl.addAttachment('\x00\xffattach')
     message = ctrl.makeMessage()
     self.assertTrue(is_ascii_only(message.as_string()),
                     "Non-ascii message string.")
Ejemplo n.º 2
0
 def test_MakeMessage_with_binary_attachment(self):
     """Message should still encode as ascii with non-ascii attachments."""
     ctrl = MailController(
         '*****@*****.**', '*****@*****.**', 'subject', u'Body')
     ctrl.addAttachment('\x00\xffattach')
     message = ctrl.makeMessage()
     self.assertTrue(
         is_ascii_only(message.as_string()), "Non-ascii message string.")
Ejemplo n.º 3
0
 def test_MakeMessage_with_non_binary_attachment(self):
     """Simple ascii attachments should not be encoded."""
     ctrl = MailController('*****@*****.**', '*****@*****.**', 'subject',
                           u'Body')
     ctrl.addAttachment('Hello, I am ascii')
     message = ctrl.makeMessage()
     body, attachment = message.get_payload()
     self.assertEqual(attachment.get_payload(),
                      attachment.get_payload(decode=True))
Ejemplo n.º 4
0
 def test_MakeMessage_with_non_binary_attachment(self):
     """Simple ascii attachments should not be encoded."""
     ctrl = MailController(
         '*****@*****.**', '*****@*****.**', 'subject', u'Body')
     ctrl.addAttachment('Hello, I am ascii')
     message = ctrl.makeMessage()
     body, attachment = message.get_payload()
     self.assertEqual(
         attachment.get_payload(), attachment.get_payload(decode=True))
Ejemplo n.º 5
0
 def test_MakeMessage_with_specific_attachment(self):
     """Explicit attachment params should be obeyed."""
     ctrl = MailController(
         '*****@*****.**', '*****@*****.**', 'subject', 'body')
     ctrl.addAttachment(
         'attach', 'text/plain', inline=True, filename='README')
     message = ctrl.makeMessage()
     attachment = message.get_payload()[1]
     self.assertEqual('attach', attachment.get_payload(decode=True))
     self.assertEqual(
         'text/plain', attachment['Content-Type'])
     self.assertEqual(
         'inline; filename="README"', attachment['Content-Disposition'])
Ejemplo n.º 6
0
 def test_MakeMessage_with_specific_attachment(self):
     """Explicit attachment params should be obeyed."""
     ctrl = MailController('*****@*****.**', '*****@*****.**', 'subject',
                           'body')
     ctrl.addAttachment('attach',
                        'text/plain',
                        inline=True,
                        filename='README')
     message = ctrl.makeMessage()
     attachment = message.get_payload()[1]
     self.assertEqual('attach', attachment.get_payload(decode=True))
     self.assertEqual('text/plain', attachment['Content-Type'])
     self.assertEqual('inline; filename="README"',
                      attachment['Content-Disposition'])
Ejemplo n.º 7
0
 def test_MakeMessage_unicode_body_with_attachment(self):
     # A message with an attachment with a unicode body gets sent as
     # UTF-8 encoded MIME text, and the message as a whole can be flattened
     # to a string with Unicode errors.
     ctrl = MailController('*****@*****.**', '*****@*****.**', 'subject',
                           u'Bj\xf6rn')
     ctrl.addAttachment('attach')
     message = ctrl.makeMessage()
     # Make sure that the message can be flattened to a string as sendmail
     # does without raising a UnicodeEncodeError.
     message.as_string()
     body, attachment = message.get_payload()
     self.assertEqual('Bj\xc3\xb6rn', body.get_payload(decode=True))
     self.assertTrue(is_ascii_only(message.as_string()))
Ejemplo n.º 8
0
 def test_MakeMessage_unicode_body_with_attachment(self):
     # A message with an attachment with a unicode body gets sent as
     # UTF-8 encoded MIME text, and the message as a whole can be flattened
     # to a string with Unicode errors.
     ctrl = MailController(
         '*****@*****.**', '*****@*****.**', 'subject', u'Bj\xf6rn')
     ctrl.addAttachment('attach')
     message = ctrl.makeMessage()
     # Make sure that the message can be flattened to a string as sendmail
     # does without raising a UnicodeEncodeError.
     message.as_string()
     body, attachment = message.get_payload()
     self.assertEqual('Bj\xc3\xb6rn', body.get_payload(decode=True))
     self.assertTrue(is_ascii_only(message.as_string()))
Ejemplo n.º 9
0
 def test_MakeMessage_with_attachment(self):
     """A message with an attachment should be multipart."""
     ctrl = MailController('*****@*****.**', '*****@*****.**', 'subject',
                           'body')
     ctrl.addAttachment('attach')
     message = ctrl.makeMessage()
     self.assertEqual('*****@*****.**', message['From'])
     self.assertEqual('*****@*****.**', message['To'])
     self.assertEqual('subject', message['Subject'])
     body, attachment = message.get_payload()
     self.assertEqual('body', body.get_payload(decode=True))
     self.assertEqual('attach', attachment.get_payload(decode=True))
     self.assertEqual('application/octet-stream',
                      attachment['Content-Type'])
     self.assertEqual('attachment', attachment['Content-Disposition'])
Ejemplo n.º 10
0
 def test_MakeMessage_with_attachment(self):
     """A message with an attachment should be multipart."""
     ctrl = MailController(
         '*****@*****.**', '*****@*****.**', 'subject', 'body')
     ctrl.addAttachment('attach')
     message = ctrl.makeMessage()
     self.assertEqual('*****@*****.**', message['From'])
     self.assertEqual('*****@*****.**', message['To'])
     self.assertEqual('subject', message['Subject'])
     body, attachment = message.get_payload()
     self.assertEqual('body', body.get_payload(decode=True))
     self.assertEqual('attach', attachment.get_payload(decode=True))
     self.assertEqual(
         'application/octet-stream', attachment['Content-Type'])
     self.assertEqual('attachment', attachment['Content-Disposition'])
Ejemplo n.º 11
0
 def test_addAttachment(self):
     """addAttachment should add a part to the list of attachments."""
     ctrl = MailController('*****@*****.**', '*****@*****.**', 'subject',
                           'body')
     ctrl.addAttachment('content1')
     attachment = ctrl.attachments[0]
     self.assertEqual('application/octet-stream',
                      attachment['Content-Type'])
     self.assertEqual('attachment', attachment['Content-Disposition'])
     self.assertEqual('content1', attachment.get_payload(decode=True))
     ctrl.addAttachment('content2',
                        'text/plain',
                        inline=True,
                        filename='name1')
     attachment = ctrl.attachments[1]
     self.assertEqual('text/plain', attachment['Content-Type'])
     self.assertEqual('inline; filename="name1"',
                      attachment['Content-Disposition'])
     self.assertEqual('content2', attachment.get_payload(decode=True))
     ctrl.addAttachment('content2',
                        'text/plain',
                        inline=True,
                        filename='name1')
Ejemplo n.º 12
0
 def test_addAttachment(self):
     """addAttachment should add a part to the list of attachments."""
     ctrl = MailController(
         '*****@*****.**', '*****@*****.**', 'subject', 'body')
     ctrl.addAttachment('content1')
     attachment = ctrl.attachments[0]
     self.assertEqual(
         'application/octet-stream', attachment['Content-Type'])
     self.assertEqual(
         'attachment', attachment['Content-Disposition'])
     self.assertEqual(
         'content1', attachment.get_payload(decode=True))
     ctrl.addAttachment(
         'content2', 'text/plain', inline=True, filename='name1')
     attachment = ctrl.attachments[1]
     self.assertEqual(
         'text/plain', attachment['Content-Type'])
     self.assertEqual(
         'inline; filename="name1"', attachment['Content-Disposition'])
     self.assertEqual(
         'content2', attachment.get_payload(decode=True))
     ctrl.addAttachment(
         'content2', 'text/plain', inline=True, filename='name1')