launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #26020
[Merge] ~cjwatson/launchpad:py3-raw-sendmail-bytes into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:py3-raw-sendmail-bytes into launchpad:master.
Commit message:
Make raw_sendmail accept messages as bytes, not str
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/396323
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.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-raw-sendmail-bytes into launchpad:master.
diff --git a/lib/lp/services/mail/sendmail.py b/lib/lp/services/mail/sendmail.py
index fea6424..a8ea76e 100644
--- a/lib/lp/services/mail/sendmail.py
+++ b/lib/lp/services/mail/sendmail.py
@@ -516,11 +516,8 @@ def raw_sendmail(from_addr, to_addrs, raw_message, message_detail):
"""
assert not isinstance(to_addrs, six.string_types), \
'to_addrs must be a sequence'
- assert isinstance(raw_message, str), 'Not a native string'
- if isinstance(raw_message, bytes): # Python 2
- assert raw_message.decode('ascii'), 'Not ASCII - badly encoded message'
- else: # Python 3
- assert raw_message.encode('ascii'), 'Not ASCII - badly encoded message'
+ assert isinstance(raw_message, bytes), 'Not a byte string'
+ assert raw_message.decode('ascii'), 'Not ASCII - badly encoded message'
mailer = getUtility(IMailDelivery, 'Mail')
request = get_current_browser_request()
timeline = get_request_timeline(request)