111
111
msg.as_string(BOUNDARY))
113
113
def test_headers_accept_unicode_and_utf8(self):
114
for string in [ u'Pepe P\xe9rez <pperez@ejemplo.com>',
114
for user in [ u'Pepe P\xe9rez <pperez@ejemplo.com>',
115
115
'Pepe P\xc3\xa9red <pperez@ejemplo.com>' ]:
116
msg = EmailMessage(string, string, string) # no exception raised
116
msg = EmailMessage(user, user, user) # no exception raised
118
118
for header in ['From', 'To', 'Subject']:
119
119
value = msg[header]
153
153
def get_user_option(self, option):
156
def verify_message_with_mime_type(mime_subtype='plain'):
157
def wrapper(_self, msg):
158
self.assertEqualDiff(COMPLEX_MULTIPART_MESSAGE % mime_subtype,
159
msg.as_string(BOUNDARY))
162
def verify_message_without_attachment(_self, msg):
163
self.assertEqualDiff(SIMPLE_MESSAGE_ASCII , msg.as_string())
158
def send_as_append(_self, msg):
159
messages.append(msg.as_string(BOUNDARY))
165
161
old_send_email = SMTPConnection.send_email
167
SMTPConnection.send_email = verify_message_with_mime_type()
163
SMTPConnection.send_email = send_as_append
168
165
EmailMessage.send(FakeConfig(), 'from@from.com', 'to@to.com',
169
166
'subject', 'body', u'a\nb\nc\nd\ne\n', 'lines.txt')
167
self.assertEqualDiff(COMPLEX_MULTIPART_MESSAGE % 'plain',
171
SMTPConnection.send_email = verify_message_with_mime_type(
173
171
EmailMessage.send(FakeConfig(), 'from@from.com', 'to@to.com',
174
172
'subject', 'body', u'a\nb\nc\nd\ne\n', 'lines.txt',
174
self.assertEqualDiff(COMPLEX_MULTIPART_MESSAGE % 'x-patch',
177
SMTPConnection.send_email = verify_message_without_attachment
178
178
EmailMessage.send(FakeConfig(), 'from@from.com', 'to@to.com',
179
179
'subject', 'body')
180
self.assertEqualDiff(SIMPLE_MESSAGE_ASCII , messages[0])
181
183
SMTPConnection.send_email = old_send_email
220
222
'P\xc3\xa9rez': ('P\xc3\xa9rez', 'utf-8'),
221
223
'P\xe9rez': ('P\xe9rez', '8-bit'),
223
for string, pair in pairs.items():
224
self.assertEqual(pair, EmailMessage.string_with_encoding(string))
225
for string_, pair in pairs.items():
226
self.assertEqual(pair, EmailMessage.string_with_encoding(string_))