Merge ~cjwatson/launchpad:py3-raw-sendmail-bytes into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: d0b90b7b41f0ccb267ad9d496ffe06fb12dd4802
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3-raw-sendmail-bytes
Merge into: launchpad:master
Diff against target: 18 lines (+2/-5)
1 file modified
lib/lp/services/mail/sendmail.py (+2/-5)
Reviewer Review Type Date Requested Status
Cristian Gonzalez (community) Approve
Review via email: mp+396323@code.launchpad.net

Commit message

Make raw_sendmail accept messages as bytes, not str

Description of the change

Experimentation suggests that on Python 3 it works best to treat email messages as bytes in most situations, although we still need to change quite a few call sites to achieve that consistently.

To post a comment you must log in.
Revision history for this message
Cristian Gonzalez (cristiangsp) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/services/mail/sendmail.py b/lib/lp/services/mail/sendmail.py
2index fea6424..a8ea76e 100644
3--- a/lib/lp/services/mail/sendmail.py
4+++ b/lib/lp/services/mail/sendmail.py
5@@ -516,11 +516,8 @@ def raw_sendmail(from_addr, to_addrs, raw_message, message_detail):
6 """
7 assert not isinstance(to_addrs, six.string_types), \
8 'to_addrs must be a sequence'
9- assert isinstance(raw_message, str), 'Not a native string'
10- if isinstance(raw_message, bytes): # Python 2
11- assert raw_message.decode('ascii'), 'Not ASCII - badly encoded message'
12- else: # Python 3
13- assert raw_message.encode('ascii'), 'Not ASCII - badly encoded message'
14+ assert isinstance(raw_message, bytes), 'Not a byte string'
15+ assert raw_message.decode('ascii'), 'Not ASCII - badly encoded message'
16 mailer = getUtility(IMailDelivery, 'Mail')
17 request = get_current_browser_request()
18 timeline = get_request_timeline(request)

Subscribers

People subscribed via source and target branches

to status/vote changes: