Skip to content

Commit

Permalink
Merge pull request #538 from closeio/fix-unicode-headers-in-emails
Browse files Browse the repository at this point in the history
Fix Unicode headers in emails
  • Loading branch information
jmadler authored Feb 5, 2020
2 parents f389b09 + 461d77e commit fcd78df
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/future/backports/email/base64mime.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from __future__ import absolute_import
from future.builtins import range
from future.builtins import bytes
from future.builtins import str

__all__ = [
'body_decode',
Expand Down
30 changes: 30 additions & 0 deletions tests/test_future/test_email_generation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
"""Tests for email generation."""

from __future__ import unicode_literals

from future.backports.email.mime.multipart import MIMEMultipart
from future.backports.email.mime.text import MIMEText
from future.backports.email.utils import formatdate
from future.tests.base import unittest


class EmailGenerationTests(unittest.TestCase):
def test_email_custom_header_can_contain_unicode(self):
msg = MIMEMultipart()
alternative = MIMEMultipart('alternative')
alternative.attach(MIMEText('Plain content with Únicødê', _subtype='plain', _charset='utf-8'))
alternative.attach(MIMEText('HTML content with Únicødê', _subtype='html', _charset='utf-8'))
msg.attach(alternative)

msg['Subject'] = 'Subject with Únicødê'
msg['From'] = 'sender@test.com'
msg['To'] = 'recipient@test.com'
msg['Date'] = formatdate(None, localtime=True)
msg['Message-ID'] = 'anIdWithÚnicødêForThisEmail'

msg_lines = msg.as_string().split('\n')
self.assertEqual(msg_lines[2], 'Subject: =?utf-8?b?U3ViamVjdCB3aXRoIMOabmljw7hkw6o=?=')
self.assertEqual(msg_lines[6], 'Message-ID: =?utf-8?b?YW5JZFdpdGjDmm5pY8O4ZMOqRm9yVGhpc0VtYWls?=')
self.assertEqual(msg_lines[17], 'UGxhaW4gY29udGVudCB3aXRoIMOabmljw7hkw6o=')
self.assertEqual(msg_lines[24], 'SFRNTCBjb250ZW50IHdpdGggw5puaWPDuGTDqg==')

0 comments on commit fcd78df

Please sign in to comment.