Skip to content

Commit

Permalink
#315: Fixed unicode surrogates bug with Python 3.12.3 and 3.11.9 (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
GitRon committed Apr 11, 2024
1 parent 83b32ec commit 5e29489
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions django_ses/__init__.py
Expand Up @@ -255,7 +255,7 @@ def _get_v2_parameters(self, message, source, email_feedback):
},
Content={
'Raw': {
'Data': dkim_sign(message.message().as_string(),
'Data': dkim_sign(message.message().as_bytes(linesep="\r\n"),
dkim_key=self.dkim_key,
dkim_domain=self.dkim_domain,
dkim_selector=self.dkim_selector,
Expand All @@ -278,7 +278,7 @@ def _get_v1_parameters(self, message, source):
params = dict(
Source=source or message.from_email,
Destinations=message.recipients(),
RawMessage={'Data': dkim_sign(message.message().as_string(),
RawMessage={'Data': dkim_sign(message.message().as_bytes(linesep="\r\n"),
dkim_key=self.dkim_key,
dkim_domain=self.dkim_domain,
dkim_selector=self.dkim_selector,
Expand Down
20 changes: 17 additions & 3 deletions tests/test_backend.py
Expand Up @@ -115,17 +115,31 @@ def test_rfc2047_helper(self):
def test_send_mail(self):
settings.AWS_SES_CONFIGURATION_SET = None

unicode_from_addr = 'Unicode Name óóóóóó <from@example.com>'
from_addr = 'Albertus Magnus <albertus.magnus@example.com>'

send_mail('subject', 'body', unicode_from_addr, ['to@example.com'])
send_mail('subject', 'body', from_addr, ['to@example.com'])
message = self.outbox.pop()
mail = email.message_from_string(smart_str(message['RawMessage']['Data']))
self.assertTrue('X-SES-CONFIGURAITON-SET' not in mail.keys())
self.assertEqual(mail['subject'], 'subject')
self.assertEqual(mail['from'], self._rfc2047_helper(unicode_from_addr))
self.assertEqual(mail['from'], self._rfc2047_helper(from_addr))
self.assertEqual(mail['to'], 'to@example.com')
self.assertEqual(mail.get_payload(), 'body')

def test_send_mail_unicode_body(self):
settings.AWS_SES_CONFIGURATION_SET = None

unicode_from_addr = 'Unicode Name óóóóóó <from@example.com>'

send_mail('Scandinavian', 'Sören & Björn', unicode_from_addr, ['to@example.com'])
message = self.outbox.pop()
mail = email.message_from_string(smart_str(message['RawMessage']['Data']))
self.assertTrue('X-SES-CONFIGURAITON-SET' not in mail.keys())
self.assertEqual(mail['subject'], 'Scandinavian')
self.assertEqual(mail['from'], self._rfc2047_helper(unicode_from_addr))
self.assertEqual(mail['to'], 'to@example.com')
self.assertEqual(mail.get_payload(), 'Sören & Björn')

def test_configuration_set_send_mail(self):
settings.AWS_SES_CONFIGURATION_SET = 'test-set'
send_mail('subject', 'body', 'from@example.com', ['to@example.com'])
Expand Down

0 comments on commit 5e29489

Please sign in to comment.