def test_encoding_multipart(self): from email.mime import application from email.mime import multipart from email.mime import nonmultipart from repoze.sendmail._compat import b from repoze.sendmail._compat import encodestring from repoze.sendmail._compat import from_octets message = multipart.MIMEMultipart('alternative') utf_8_encoded = b('mo \xe2\x82\xac') utf_8 = utf_8_encoded.decode('utf-8') plain_string = utf_8 plain_part = nonmultipart.MIMENonMultipart('plain', 'plain') plain_part.set_payload(plain_string) message.attach(plain_part) html_string = '<p>' + utf_8 + '</p>' html_part = nonmultipart.MIMENonMultipart('text', 'html') html_part.set_payload(html_string) message.attach(html_part) binary = from_octets([x for x in range(256)]) binary_b64 = encodestring(binary) binary_part = application.MIMEApplication(binary) message.attach(binary_part) encoded = self._callFUT(message) self.assertTrue(encodestring(plain_string.encode('utf-8')) in encoded) self.assertTrue(encodestring(html_string.encode('utf-8')) in encoded) self.assertTrue(binary_b64 in encoded)
def test_binary_body(self): from email.mime import application from email.mime import multipart from repoze.sendmail._compat import encodestring from repoze.sendmail._compat import b body = b('I know what you did last PyCon') message = multipart.MIMEMultipart() message.attach(application.MIMEApplication(body)) encoded = self._callFUT(message) self.assertTrue(encodestring(body) in encoded)
def test_encoding_utf_8_body(self): from repoze.sendmail._compat import b from repoze.sendmail._compat import encodestring utf_8_encoded = b('mo \xe2\x82\xac') utf_8 = utf_8_encoded.decode('utf-8') body = 'I know what you did last ' + utf_8 message = self._makeMessage() message.set_payload(body) encoded = self._callFUT(message) self.assertTrue(encodestring(body.encode('utf-8')) in encoded)
def test_encoding_utf_8_body(self): from repoze.sendmail._compat import b from repoze.sendmail._compat import encodestring utf_8_encoded = b('mo \xe2\x82\xac') utf_8 = utf_8_encoded.decode('utf-8') body = 'I know what you did last '+ utf_8 message = self._makeMessage() message.set_payload(body) encoded = self._callFUT(message) self.assertTrue(encodestring(body.encode('utf-8')) in encoded)