Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix subject encoding error with Python3.4 #88 #89

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions flask_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,7 @@ def as_string(self):
return self._message().as_string()

def as_bytes(self):
if PY34:
return self._message().as_bytes()
else: # fallback for old Python (3) versions
return self._message().as_string().encode(self.charset or 'utf-8')
return self._message().as_string().encode(self.charset or 'utf-8')

def __str__(self):
return self.as_string()
Expand Down
10 changes: 9 additions & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,12 @@ def test_unicode_subject(self):
msg = Message(subject=make_lazy_string(lambda a: a, u"sübject"),
sender='from@example.com',
recipients=["to@example.com"])
self.assertIn('=?utf-8?q?s=C3=BCbject?=', msg.as_string())
self.assertIn(b'=?utf-8?q?s=C3=BCbject?=', msg.as_bytes())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we still test the as_string() case? I could be missing something.


msg = Message(subject=make_lazy_string(lambda a: a, u"[Foo Bar] Voici vos paramètres d'accès à"),
sender='from@example.com',
recipients=["to@example.com"])
self.assertIn(b'=?utf-8?b?W0ZvbyBCYXJdIFZvaWNpIHZvcyBwYXJhbcOodHJlcyBkJ2FjY8OocyDDoA==?=', msg.as_bytes())

def test_extra_headers(self):
msg = Message(sender="from@example.com",
Expand Down Expand Up @@ -691,3 +696,6 @@ def test_sendmail_with_non_ascii_body(self):
msg.mail_options,
msg.rcpt_options
)

if __name__ == '__main__':
unittest.main()