Merge ~cjwatson/launchpad:py3only-message-from-bytes into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 5baa1c0d154199d3b8524ce0e291be0ee9cb98bf
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3only-message-from-bytes
Merge into: launchpad:master
Diff against target: 1083 lines (+100/-118)
31 files modified
lib/lp/blueprints/doc/specification-notifications.txt (+6/-6)
lib/lp/bugs/doc/externalbugtracker-debbugs.txt (+3/-4)
lib/lp/bugs/doc/initial-bug-contacts.txt (+2/-2)
lib/lp/bugs/externalbugtracker/debbugs.py (+4/-4)
lib/lp/bugs/scripts/debbugs.py (+2/-4)
lib/lp/bugs/tests/bugs-emailinterface.txt (+10/-9)
lib/lp/bugs/utilities/filebugdataparser.py (+2/-2)
lib/lp/code/doc/codeimport.txt (+2/-2)
lib/lp/code/mail/tests/test_codeimport.py (+8/-8)
lib/lp/code/model/tests/test_gitrepository.py (+2/-2)
lib/lp/codehosting/scanner/tests/test_email.py (+5/-5)
lib/lp/registry/browser/tests/test_person.py (+2/-2)
lib/lp/registry/doc/distribution-mirror.txt (+2/-2)
lib/lp/registry/stories/gpg-coc/xx-gpg-coc.txt (+5/-5)
lib/lp/registry/stories/mailinglists/hosted-email-address.txt (+2/-2)
lib/lp/registry/stories/person/xx-add-sshkey.txt (+2/-2)
lib/lp/registry/tests/test_mailinglistapi.py (+4/-7)
lib/lp/services/compat.py (+0/-6)
lib/lp/services/mail/doc/emailauthentication.txt (+3/-6)
lib/lp/services/mail/doc/mailbox.txt (+3/-3)
lib/lp/services/mail/doc/sending-mail.txt (+13/-13)
lib/lp/services/mail/notification.py (+2/-2)
lib/lp/services/mail/signedmessage.py (+2/-2)
lib/lp/services/mail/stub.py (+3/-5)
lib/lp/services/mail/tests/incomingmail.txt (+1/-2)
lib/lp/services/mail/tests/test_stub.py (+1/-1)
lib/lp/services/messages/model/message.py (+2/-2)
lib/lp/services/verification/doc/logintoken.txt (+1/-1)
lib/lp/services/verification/tests/logintoken.py (+2/-3)
lib/lp/testing/mail_helpers.py (+2/-2)
lib/lp/translations/doc/translations-export-to-branch.txt (+2/-2)
Reviewer Review Type Date Requested Status
Cristian Gonzalez (community) Approve
Review via email: mp+408168@code.launchpad.net

Commit message

Use email.message_from_bytes directly

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/blueprints/doc/specification-notifications.txt b/lib/lp/blueprints/doc/specification-notifications.txt
2index 7eb04ab..63130a4 100644
3--- a/lib/lp/blueprints/doc/specification-notifications.txt
4+++ b/lib/lp/blueprints/doc/specification-notifications.txt
5@@ -116,9 +116,9 @@ are now subscribed.
6
7 Now let's take a look at what the notification looks like:
8
9- >>> from lp.services.compat import message_from_bytes
10+ >>> import email
11 >>> notifications = [
12- ... message_from_bytes(raw_message)
13+ ... email.message_from_bytes(raw_message)
14 ... for from_addr, to_addrs, raw_message in sorted(stub.test_emails)]
15 >>> status_notification = notifications[0]
16 >>> status_notification['To']
17@@ -158,7 +158,7 @@ Whiteboard change:
18 >>> transaction.commit()
19
20 >>> notifications = [
21- ... message_from_bytes(raw_message)
22+ ... email.message_from_bytes(raw_message)
23 ... for from_addr, to_addrs, raw_message in sorted(stub.test_emails)]
24 >>> status_notification = notifications[0]
25 >>> status_notification['To']
26@@ -198,7 +198,7 @@ Definition status and whiteboard change:
27 >>> transaction.commit()
28
29 >>> notifications = [
30- ... message_from_bytes(raw_message)
31+ ... email.message_from_bytes(raw_message)
32 ... for from_addr, to_addrs, raw_message in sorted(stub.test_emails)]
33 >>> status_notification = notifications[0]
34 >>> status_notification['To']
35@@ -238,7 +238,7 @@ Change priority:
36 >>> transaction.commit()
37
38 >>> notifications = [
39- ... message_from_bytes(raw_message)
40+ ... email.message_from_bytes(raw_message)
41 ... for from_addr, to_addrs, raw_message in sorted(stub.test_emails)]
42 >>> status_notification = notifications[0]
43 >>> status_notification['To']
44@@ -272,7 +272,7 @@ Change approver, assignee and drafter:
45 >>> transaction.commit()
46
47 >>> notifications = [
48- ... message_from_bytes(raw_message)
49+ ... email.message_from_bytes(raw_message)
50 ... for from_addr, to_addrs, raw_message in sorted(stub.test_emails)]
51 >>> status_notification = notifications[0]
52 >>> status_notification['To']
53diff --git a/lib/lp/bugs/doc/externalbugtracker-debbugs.txt b/lib/lp/bugs/doc/externalbugtracker-debbugs.txt
54index 9dce3b5..aec439d 100644
55--- a/lib/lp/bugs/doc/externalbugtracker-debbugs.txt
56+++ b/lib/lp/bugs/doc/externalbugtracker-debbugs.txt
57@@ -416,10 +416,9 @@ same comment.
58 If we query the DebBugs database directly we'll see that there are two
59 copies of the same comment.
60
61- >>> from lp.services.compat import message_from_bytes
62 >>> debian_bug = external_debbugs._findBug(bug_watch.remotebug)
63 >>> for comment in debian_bug.comments:
64- ... comment_email = message_from_bytes(comment)
65+ ... comment_email = email.message_from_bytes(comment)
66 ... print(comment_email['message-id'])
67 <20040309081430.98BF411EE67@tux>
68 <20040309081430.98BF411EE67@tux>
69@@ -493,7 +492,7 @@ datecreated comes not from the Date header but from the Received header.
70
71 >>> from lp.bugs.tests.externalbugtracker import (
72 ... read_test_file)
73- >>> parsed_message = message_from_bytes(
74+ >>> parsed_message = email.message_from_bytes(
75 ... read_test_file('debbugs-comment-with-received-date.txt').encode(
76 ... 'UTF-8'))
77
78@@ -519,7 +518,7 @@ default to using the Date header again.
79 >>> print(message.datecreated)
80 2007-12-14 18:54:30+00:00
81
82- >>> parsed_message = message_from_bytes(
83+ >>> parsed_message = email.message_from_bytes(
84 ... read_test_file('debbugs-comment-with-received-date.txt').encode(
85 ... 'UTF-8'))
86
87diff --git a/lib/lp/bugs/doc/initial-bug-contacts.txt b/lib/lp/bugs/doc/initial-bug-contacts.txt
88index 46e8ed2..7161f17 100644
89--- a/lib/lp/bugs/doc/initial-bug-contacts.txt
90+++ b/lib/lp/bugs/doc/initial-bug-contacts.txt
91@@ -167,8 +167,8 @@ notification). The email has the X-Launchpad-Message-Rationale header to
92 track why daf received the email. The rational is repeated in the footer
93 of the email with the bug title and URL.
94
95+ >>> import email
96 >>> from operator import itemgetter
97- >>> from lp.services.compat import message_from_bytes
98
99 >>> test_emails = list(stub.test_emails)
100 >>> test_emails.sort(key=itemgetter(1))
101@@ -183,7 +183,7 @@ of the email with the bug title and URL.
102 >>> print(to_addr)
103 ['daf@canonical.com']
104
105- >>> msg = message_from_bytes(raw_message)
106+ >>> msg = email.message_from_bytes(raw_message)
107 >>> msg['References'] == (
108 ... bug_one_in_ubuntu_firefox.bug.initial_message.rfc822msgid)
109 True
110diff --git a/lib/lp/bugs/externalbugtracker/debbugs.py b/lib/lp/bugs/externalbugtracker/debbugs.py
111index 360c2b5..1bca0c7 100644
112--- a/lib/lp/bugs/externalbugtracker/debbugs.py
113+++ b/lib/lp/bugs/externalbugtracker/debbugs.py
114@@ -10,6 +10,7 @@ __all__ = [
115 ]
116
117 from datetime import datetime
118+import email
119 from email.utils import (
120 mktime_tz,
121 parseaddr,
122@@ -41,7 +42,6 @@ from lp.bugs.interfaces.externalbugtracker import (
123 UNKNOWN_REMOTE_IMPORTANCE,
124 )
125 from lp.bugs.scripts import debbugs
126-from lp.services.compat import message_from_bytes
127 from lp.services.config import config
128 from lp.services.database.isolation import ensure_no_transaction
129 from lp.services.mail.sendmail import simple_sendmail
130@@ -242,7 +242,7 @@ class DebBugs(ExternalBugTracker):
131
132 comment_ids = []
133 for comment in debian_bug.comments:
134- parsed_comment = message_from_bytes(comment)
135+ parsed_comment = email.message_from_bytes(comment)
136
137 # It's possible for the same message to appear several times
138 # in a DebBugs comment log, since each control command in a
139@@ -271,7 +271,7 @@ class DebBugs(ExternalBugTracker):
140 self._loadLog(debian_bug)
141
142 for comment in debian_bug.comments:
143- parsed_comment = message_from_bytes(comment)
144+ parsed_comment = email.message_from_bytes(comment)
145 if parsed_comment['message-id'] == comment_id:
146 return parseaddr(parsed_comment['from'])
147
148@@ -324,7 +324,7 @@ class DebBugs(ExternalBugTracker):
149 self._loadLog(debian_bug)
150
151 for comment in debian_bug.comments:
152- parsed_comment = message_from_bytes(comment)
153+ parsed_comment = email.message_from_bytes(comment)
154 if parsed_comment['message-id'] == comment_id:
155 msg_date = self._getDateForComment(parsed_comment)
156 message = getUtility(IMessageSet).fromEmail(comment, poster,
157diff --git a/lib/lp/bugs/scripts/debbugs.py b/lib/lp/bugs/scripts/debbugs.py
158index 81055c1..d693df1 100644
159--- a/lib/lp/bugs/scripts/debbugs.py
160+++ b/lib/lp/bugs/scripts/debbugs.py
161@@ -11,8 +11,6 @@ import sys
162
163 import six
164
165-from lp.services.compat import message_from_bytes
166-
167
168 class Bug:
169 def __init__(self, db, id, package=None, date=None, status=None,
170@@ -59,7 +57,7 @@ class Bug:
171 if self._emails:
172 return self._emails
173 for comment in self.comments:
174- message = message_from_bytes(comment)
175+ message = email.message_from_bytes(comment)
176 self._emails.append(message)
177 return self._emails
178
179@@ -207,7 +205,7 @@ class Database:
180 bug.report = fd.read()
181 fd.close()
182
183- report_msg = message_from_bytes(bug.report)
184+ report_msg = email.message_from_bytes(bug.report)
185 charset = report_msg.get_content_charset('ascii')
186 description = report_msg.get_payload(decode=True)
187 bug.description = description.decode(charset)
188diff --git a/lib/lp/bugs/tests/bugs-emailinterface.txt b/lib/lp/bugs/tests/bugs-emailinterface.txt
189index 452b6bf..94d9412 100644
190--- a/lib/lp/bugs/tests/bugs-emailinterface.txt
191+++ b/lib/lp/bugs/tests/bugs-emailinterface.txt
192@@ -70,11 +70,11 @@ we'll have to authenticate the user manually:
193 Now if we pass the message to the Malone handler, we can see that the
194 bug got submitted correctly:
195
196+ >>> import email
197 >>> from lp.bugs.mail.handler import MaloneHandler
198- >>> from lp.services.compat import message_from_bytes
199 >>> handler = MaloneHandler()
200 >>> def construct_email(raw_mail):
201- ... msg = message_from_bytes(raw_mail, _class=MockSignedMessage)
202+ ... msg = email.message_from_bytes(raw_mail, _class=MockSignedMessage)
203 ... if 'Message-Id' not in msg:
204 ... msg['Message-Id'] = factory.makeUniqueRFC822MsgId()
205 ... return msg
206@@ -356,7 +356,7 @@ And the person sending the email has received an error message.
207 ... if not stub.test_emails:
208 ... raise AssertionError("No emails queued!")
209 ... from_addr, to_addrs, raw_message = stub.test_emails[-1]
210- ... sent_msg = message_from_bytes(raw_message)
211+ ... sent_msg = email.message_from_bytes(raw_message)
212 ... error_mail, original_mail = sent_msg.get_payload()
213 ... print("Subject: %s" % sent_msg['Subject'])
214 ... print("To: %s" % ', '.join(to_addrs))
215@@ -456,7 +456,8 @@ The same will happen if we send the same email without signing it:
216 >>> class MockUnsignedMessage(email.message.Message):
217 ... signedMessage = None
218 ... signature = None
219- >>> msg = message_from_bytes(comment_mail, _class=MockUnsignedMessage)
220+ >>> msg = email.message_from_bytes(
221+ ... comment_mail, _class=MockUnsignedMessage)
222 >>> handler.process(
223 ... msg, msg['To'],
224 ... )
225@@ -2040,7 +2041,7 @@ Let's take a closer look at send_process_error_notification(), which is
226 used to send the error messages. It needs the message that caused the
227 error, so let's create one.
228
229- >>> test_msg = message_from_bytes(b"""From: foo.bar@canonical.com
230+ >>> test_msg = email.message_from_bytes(b"""From: foo.bar@canonical.com
231 ... To: bugs@launchpad.net
232 ... Message-Id: <original@msg>
233 ... Subject: Original Message Subject
234@@ -2063,7 +2064,7 @@ The To and Subject headers got set to the values we provided:
235
236 >>> transaction.commit()
237 >>> from_addr, to_addrs, raw_message = stub.test_emails[-1]
238- >>> sent_msg = message_from_bytes(raw_message)
239+ >>> sent_msg = email.message_from_bytes(raw_message)
240 >>> sent_msg['To']
241 'test@canonical.com'
242 >>> sent_msg['Subject']
243@@ -2123,7 +2124,7 @@ the original message.
244 ... max_return_size=max_return_size)
245 >>> transaction.commit()
246 >>> from_addr, to_addrs, raw_message = stub.test_emails[-1]
247- >>> sent_msg = message_from_bytes(raw_message)
248+ >>> sent_msg = email.message_from_bytes(raw_message)
249 >>> failure_msg, original_msg = sent_msg.get_payload()
250 >>> msg = original_msg.get_payload()[0]
251
252@@ -2220,7 +2221,7 @@ The 'subscribe' command failed, and the user is being notified of the
253 failure in an email.
254
255 >>> from_addr, to_addrs, raw_message = stub.test_emails[-1]
256- >>> sent_msg = message_from_bytes(raw_message)
257+ >>> sent_msg = email.message_from_bytes(raw_message)
258 >>> failure_msg, original_msg = sent_msg.get_payload()
259 >>> print(failure_msg.get_payload(decode=True).decode('UTF-8'))
260 An error occurred while processing a mail you sent to Launchpad's email
261@@ -2268,7 +2269,7 @@ And the sender receives an email to let them know about the failing
262 'security' command.
263
264 >>> from_addr, to_addrs, raw_message = stub.test_emails[-1]
265- >>> sent_msg = message_from_bytes(raw_message)
266+ >>> sent_msg = email.message_from_bytes(raw_message)
267 >>> failure_msg, original_msg = sent_msg.get_payload()
268 >>> print(failure_msg.get_payload(decode=True).decode('UTF-8'))
269 An error occurred while processing a mail you sent to Launchpad's email
270diff --git a/lib/lp/bugs/utilities/filebugdataparser.py b/lib/lp/bugs/utilities/filebugdataparser.py
271index 3b320be..4ffc0a1 100644
272--- a/lib/lp/bugs/utilities/filebugdataparser.py
273+++ b/lib/lp/bugs/utilities/filebugdataparser.py
274@@ -9,12 +9,12 @@ __all__ = [
275 ]
276
277 import base64
278+import email
279 import tempfile
280
281 import six
282
283 from lp.bugs.model.bug import FileBugData
284-from lp.services.compat import message_from_bytes
285
286
287 class FileBugDataParser:
288@@ -62,7 +62,7 @@ class FileBugDataParser:
289 header_text = self._consumeBytes(b'\n\n')
290 # Use the email package to return a dict-like object of the
291 # headers, so we don't have to parse the text ourselves.
292- return message_from_bytes(header_text)
293+ return email.message_from_bytes(header_text)
294
295 def readLine(self):
296 """Read a line of the message."""
297diff --git a/lib/lp/code/doc/codeimport.txt b/lib/lp/code/doc/codeimport.txt
298index 3856ed3..d5da426 100644
299--- a/lib/lp/code/doc/codeimport.txt
300+++ b/lib/lp/code/doc/codeimport.txt
301@@ -103,8 +103,8 @@ three members of the vcs-imports team.
302 >>> vcs_imports = getUtility(ILaunchpadCelebrities).vcs_imports
303 >>> len(get_contact_email_addresses(vcs_imports))
304 3
305- >>> from lp.services.compat import message_from_bytes
306- >>> message = message_from_bytes(stub.test_emails[0][2])
307+ >>> import email
308+ >>> message = email.message_from_bytes(stub.test_emails[0][2])
309 >>> print(message['subject'])
310 New code import: ~import-person/widget/trunk-cvs
311 >>> print(message['X-Launchpad-Message-Rationale'])
312diff --git a/lib/lp/code/mail/tests/test_codeimport.py b/lib/lp/code/mail/tests/test_codeimport.py
313index 18ecb59..ee62761 100644
314--- a/lib/lp/code/mail/tests/test_codeimport.py
315+++ b/lib/lp/code/mail/tests/test_codeimport.py
316@@ -3,6 +3,7 @@
317
318 """Tests for code import related mailings"""
319
320+import email
321 import textwrap
322
323 import six
324@@ -14,7 +15,6 @@ from lp.code.enums import (
325 TargetRevisionControlSystems,
326 )
327 from lp.code.tests.helpers import GitHostingFixture
328-from lp.services.compat import message_from_bytes
329 from lp.services.mail import stub
330 from lp.testing import (
331 login_celebrity,
332@@ -40,7 +40,7 @@ class TestNewCodeImports(TestCaseWithFactory):
333 cvs_module='a_module', branch_name='import',
334 product=fooix, registrant=eric)
335 transaction.commit()
336- msg = message_from_bytes(stub.test_emails[0][2])
337+ msg = email.message_from_bytes(stub.test_emails[0][2])
338 self.assertEqual('code-import', msg['X-Launchpad-Notification-Type'])
339 self.assertEqual('~eric/fooix/import', msg['X-Launchpad-Branch'])
340 self.assertEqual(
341@@ -64,7 +64,7 @@ class TestNewCodeImports(TestCaseWithFactory):
342 branch_name='trunk', product=fooix, registrant=eric,
343 rcs_type=RevisionControlSystems.BZR_SVN)
344 transaction.commit()
345- msg = message_from_bytes(stub.test_emails[0][2])
346+ msg = email.message_from_bytes(stub.test_emails[0][2])
347 self.assertEqual('code-import', msg['X-Launchpad-Notification-Type'])
348 self.assertEqual('~eric/fooix/trunk', msg['X-Launchpad-Branch'])
349 self.assertEqual(
350@@ -87,7 +87,7 @@ class TestNewCodeImports(TestCaseWithFactory):
351 git_repo_url='git://git.example.com/fooix.git',
352 branch_name='master', product=fooix, registrant=eric)
353 transaction.commit()
354- msg = message_from_bytes(stub.test_emails[0][2])
355+ msg = email.message_from_bytes(stub.test_emails[0][2])
356 self.assertEqual('code-import', msg['X-Launchpad-Notification-Type'])
357 self.assertEqual('~eric/fooix/master', msg['X-Launchpad-Branch'])
358 self.assertEqual(
359@@ -113,7 +113,7 @@ class TestNewCodeImports(TestCaseWithFactory):
360 branch_name=u'master', product=fooix, registrant=eric,
361 target_rcs_type=TargetRevisionControlSystems.GIT)
362 transaction.commit()
363- msg = message_from_bytes(stub.test_emails[0][2])
364+ msg = email.message_from_bytes(stub.test_emails[0][2])
365 self.assertEqual('code-import', msg['X-Launchpad-Notification-Type'])
366 self.assertEqual('~eric/fooix/+git/master', msg['X-Launchpad-Branch'])
367 self.assertEqual(
368@@ -141,7 +141,7 @@ class TestNewCodeImports(TestCaseWithFactory):
369 git_repo_url='git://git.example.com/fooix.git',
370 branch_name='master', sourcepackage=fooix, registrant=eric)
371 transaction.commit()
372- msg = message_from_bytes(stub.test_emails[0][2])
373+ msg = email.message_from_bytes(stub.test_emails[0][2])
374 self.assertEqual('code-import', msg['X-Launchpad-Notification-Type'])
375 self.assertEqual(
376 '~eric/foobuntu/manic/fooix/master', msg['X-Launchpad-Branch'])
377@@ -164,7 +164,7 @@ class TestUpdatedCodeImports(TestCaseWithFactory):
378 layer = DatabaseFunctionalLayer
379
380 def assertSameDetailsEmail(self, details, unique_name):
381- msg = message_from_bytes(stub.test_emails[0][2])
382+ msg = email.message_from_bytes(stub.test_emails[0][2])
383 self.assertEqual(
384 'code-import-updated', msg['X-Launchpad-Notification-Type'])
385 self.assertEqual(unique_name, msg['X-Launchpad-Branch'])
386@@ -183,7 +183,7 @@ class TestUpdatedCodeImports(TestCaseWithFactory):
387
388 def assertDifferentDetailsEmail(self, old_details, new_details,
389 unique_name):
390- msg = message_from_bytes(stub.test_emails[0][2])
391+ msg = email.message_from_bytes(stub.test_emails[0][2])
392 self.assertEqual(
393 'code-import-updated', msg['X-Launchpad-Notification-Type'])
394 self.assertEqual(unique_name, msg['X-Launchpad-Branch'])
395diff --git a/lib/lp/code/model/tests/test_gitrepository.py b/lib/lp/code/model/tests/test_gitrepository.py
396index de296a7..6edeb1e 100644
397--- a/lib/lp/code/model/tests/test_gitrepository.py
398+++ b/lib/lp/code/model/tests/test_gitrepository.py
399@@ -13,6 +13,7 @@ from datetime import (
400 datetime,
401 timedelta,
402 )
403+import email
404 from functools import partial
405 import hashlib
406 import json
407@@ -145,7 +146,6 @@ from lp.registry.interfaces.personociproject import IPersonOCIProjectFactory
408 from lp.registry.interfaces.personproduct import IPersonProductFactory
409 from lp.registry.tests.test_accesspolicy import get_policies_for_artifact
410 from lp.services.authserver.xmlrpc import AuthServerAPIView
411-from lp.services.compat import message_from_bytes
412 from lp.services.config import config
413 from lp.services.database.constants import UTC_NOW
414 from lp.services.database.interfaces import IStore
415@@ -1326,7 +1326,7 @@ class TestGitRepositoryModificationNotifications(TestCaseWithFactory):
416 getUtility(IGitRepositoryModifiedMailJobSource)).runAll()
417 bodies_by_recipient = {}
418 for from_addr, to_addrs, message in stub.test_emails:
419- body = message_from_bytes(message).get_payload(decode=True)
420+ body = email.message_from_bytes(message).get_payload(decode=True)
421 for to_addr in to_addrs:
422 bodies_by_recipient[to_addr] = six.ensure_text(body)
423 # Both the owner and the unprivileged subscriber receive email.
424diff --git a/lib/lp/codehosting/scanner/tests/test_email.py b/lib/lp/codehosting/scanner/tests/test_email.py
425index 3072ec2..34af406 100644
426--- a/lib/lp/codehosting/scanner/tests/test_email.py
427+++ b/lib/lp/codehosting/scanner/tests/test_email.py
428@@ -5,6 +5,7 @@
429
430 __metaclass__ = type
431
432+import email
433 import os
434
435 from breezy.uncommit import uncommit
436@@ -25,7 +26,6 @@ from lp.codehosting.scanner import events
437 from lp.codehosting.scanner.bzrsync import BzrSync
438 from lp.codehosting.scanner.tests.test_bzrsync import BzrSyncTestCase
439 from lp.registry.interfaces.person import IPersonSet
440-from lp.services.compat import message_from_bytes
441 from lp.services.config import config
442 from lp.services.features.testing import FeatureFixture
443 from lp.services.job.runner import JobRunner
444@@ -72,7 +72,7 @@ class TestBzrSyncEmail(BzrSyncTestCase):
445 self.assertEqual(len(stub.test_emails), 1)
446 [initial_email] = stub.test_emails
447 expected = 'First scan of the branch detected 0 revisions'
448- message = message_from_bytes(initial_email[2])
449+ message = email.message_from_bytes(initial_email[2])
450 email_body = message.get_payload()
451 self.assertIn(expected, email_body)
452 self.assertEmailHeadersEqual(
453@@ -87,7 +87,7 @@ class TestBzrSyncEmail(BzrSyncTestCase):
454 [initial_email] = stub.test_emails
455 expected = ('First scan of the branch detected 1 revision'
456 ' in the revision history of the=\n branch.')
457- message = message_from_bytes(initial_email[2])
458+ message = email.message_from_bytes(initial_email[2])
459 email_body = message.get_payload()
460 self.assertIn(expected, email_body)
461 self.assertEmailHeadersEqual(
462@@ -105,7 +105,7 @@ class TestBzrSyncEmail(BzrSyncTestCase):
463 self.assertEqual(len(stub.test_emails), 1)
464 [uncommit_email] = stub.test_emails
465 expected = '1 revision was removed from the branch.'
466- message = message_from_bytes(uncommit_email[2])
467+ message = email.message_from_bytes(uncommit_email[2])
468 email_body = message.get_payload()
469 self.assertIn(expected, email_body)
470 self.assertEmailHeadersEqual(
471@@ -137,7 +137,7 @@ class TestBzrSyncEmail(BzrSyncTestCase):
472 'Subject: [Branch %s] Test branch' % self.db_branch.unique_name)
473 self.assertIn(expected, uncommit_email_body)
474
475- recommit_email_msg = message_from_bytes(recommit_email[2])
476+ recommit_email_msg = email.message_from_bytes(recommit_email[2])
477 recommit_email_body = recommit_email_msg.get_payload()[0].get_payload(
478 decode=True)
479 subject = '[Branch %s] Rev 1: second' % self.db_branch.unique_name
480diff --git a/lib/lp/registry/browser/tests/test_person.py b/lib/lp/registry/browser/tests/test_person.py
481index 2b015ce..b21e38e 100644
482--- a/lib/lp/registry/browser/tests/test_person.py
483+++ b/lib/lp/registry/browser/tests/test_person.py
484@@ -5,6 +5,7 @@
485 __metaclass__ = type
486
487 import doctest
488+import email
489 from operator import attrgetter
490 import re
491 from textwrap import dedent
492@@ -67,7 +68,6 @@ from lp.registry.interfaces.teammembership import (
493 from lp.registry.model.karma import KarmaCategory
494 from lp.registry.model.milestone import milestone_sort_key
495 from lp.scripts.garbo import PopulateLatestPersonSourcePackageReleaseCache
496-from lp.services.compat import message_from_bytes
497 from lp.services.config import config
498 from lp.services.database.interfaces import IStore
499 from lp.services.features.testing import FeatureFixture
500@@ -938,7 +938,7 @@ class TestPersonEditView(TestPersonRenameFormMixin, TestCaseWithFactory):
501 messages = [msg for from_addr, to_addr, msg in stub.test_emails]
502 raw_msg = None
503 for orig_msg in messages:
504- msg = message_from_bytes(orig_msg)
505+ msg = email.message_from_bytes(orig_msg)
506 if msg.get('to') == added_email:
507 raw_msg = orig_msg
508 token_url = get_token_url_from_email(raw_msg)
509diff --git a/lib/lp/registry/doc/distribution-mirror.txt b/lib/lp/registry/doc/distribution-mirror.txt
510index 29c35dc..8939a83 100644
511--- a/lib/lp/registry/doc/distribution-mirror.txt
512+++ b/lib/lp/registry/doc/distribution-mirror.txt
513@@ -364,7 +364,7 @@ up on the public mirror listings.
514 >>> import transaction
515 >>> transaction.commit()
516
517- >>> from lp.services.compat import message_from_bytes
518+ >>> import email
519 >>> from lp.services.mail import stub
520 >>> len(stub.test_emails)
521 2
522@@ -377,7 +377,7 @@ up on the public mirror listings.
523 ['mark@example.com']
524 >>> valid_mirror.enabled
525 False
526- >>> msg = message_from_bytes(raw_message)
527+ >>> msg = email.message_from_bytes(raw_message)
528 >>> print(msg.get_payload())
529 Dear mirror administrator,
530 <BLANKLINE>
531diff --git a/lib/lp/registry/stories/gpg-coc/xx-gpg-coc.txt b/lib/lp/registry/stories/gpg-coc/xx-gpg-coc.txt
532index 09342e8..1b81c27 100644
533--- a/lib/lp/registry/stories/gpg-coc/xx-gpg-coc.txt
534+++ b/lib/lp/registry/stories/gpg-coc/xx-gpg-coc.txt
535@@ -5,9 +5,9 @@ Claiming GPG Keys
536 Setup
537 -----
538
539+ >>> import email
540 >>> from zope.component import getUtility
541 >>> from lp.registry.interfaces.person import IPersonSet
542- >>> from lp.services.compat import message_from_bytes
543 >>> from lp.services.mail import stub
544 >>> from lp.testing.keyserver import KeyServerTac
545 >>> from lp.testing.pages import setupBrowserFreshLogin
546@@ -56,7 +56,7 @@ text part that provides useful information to users who -- for whatever reason
547 -- cannot decrypt the token url. Start by grabbing the confirmation message.
548
549 >>> from_addr, to_addrs, raw_msg = stub.test_emails.pop()
550- >>> msg = message_from_bytes(raw_msg)
551+ >>> msg = email.message_from_bytes(raw_msg)
552 >>> msg.get_content_type()
553 'text/plain'
554
555@@ -178,7 +178,7 @@ their Launchpad account.
556 Sample Person checks their email.
557
558 >>> from_addr, to_addrs, raw_msg = stub.test_emails.pop()
559- >>> msg = message_from_bytes(raw_msg)
560+ >>> msg = email.message_from_bytes(raw_msg)
561 >>> msg.get_content_type()
562 'text/plain'
563 >>> body = msg.get_payload(decode=True)
564@@ -512,7 +512,7 @@ Get the token from the body of the email sent.
565 >>> import re
566 >>> from lp.services.mail import stub
567 >>> from_addr, to_addrs, raw_msg = stub.test_emails.pop()
568- >>> msg = message_from_bytes(raw_msg)
569+ >>> msg = email.message_from_bytes(raw_msg)
570 >>> cipher_body = msg.get_payload(decode=1)
571 >>> body = decrypt_content(cipher_body, six.ensure_str('test'))
572 >>> link = get_token_url_from_bytes(body)
573@@ -628,7 +628,7 @@ Test if the advertisement email was sent:
574
575 >>> from lp.services.mail import stub
576 >>> from_addr, to_addrs, raw_msg = stub.test_emails.pop()
577- >>> msg = message_from_bytes(raw_msg)
578+ >>> msg = email.message_from_bytes(raw_msg)
579 >>> print(six.ensure_text(msg.get_payload(decode=True)))
580 <BLANKLINE>
581 ...
582diff --git a/lib/lp/registry/stories/mailinglists/hosted-email-address.txt b/lib/lp/registry/stories/mailinglists/hosted-email-address.txt
583index 9952c67..3853b24 100644
584--- a/lib/lp/registry/stories/mailinglists/hosted-email-address.txt
585+++ b/lib/lp/registry/stories/mailinglists/hosted-email-address.txt
586@@ -46,8 +46,8 @@ Launchpad sends that address a confirmation message.
587 >>> from_addr, to_addrs, raw_msg = stub.test_emails.pop()
588 >>> stub.test_emails
589 []
590- >>> from lp.services.compat import message_from_bytes
591- >>> msg = message_from_bytes(raw_msg)
592+ >>> import email
593+ >>> msg = email.message_from_bytes(raw_msg)
594 >>> print(msg['From'])
595 Launchpad Email Validator <noreply@launchpad.net>
596 >>> print(msg['Subject'])
597diff --git a/lib/lp/registry/stories/person/xx-add-sshkey.txt b/lib/lp/registry/stories/person/xx-add-sshkey.txt
598index c58405f..8c1095d 100644
599--- a/lib/lp/registry/stories/person/xx-add-sshkey.txt
600+++ b/lib/lp/registry/stories/person/xx-add-sshkey.txt
601@@ -225,7 +225,7 @@ this case we'll raise an UnexpectedFormData.
602 If he removes a key then he will get a security warning email notification
603 that the key has been removed.
604
605- >>> from lp.services.compat import message_from_bytes
606+ >>> import email
607 >>> from lp.services.mail import stub
608 >>> stub.test_emails = []
609 >>> browser.open('http://launchpad.test/~salgado/+editsshkeys')
610@@ -233,7 +233,7 @@ that the key has been removed.
611 >>> from_addr, to_addr, msg = stub.test_emails.pop()
612 >>> to_addr
613 ['guilherme.salgado@canonical.com']
614- >>> payload = message_from_bytes(msg).get_payload()
615+ >>> payload = email.message_from_bytes(msg).get_payload()
616 >>> assert payload.startswith('The SSH Key')
617
618
619diff --git a/lib/lp/registry/tests/test_mailinglistapi.py b/lib/lp/registry/tests/test_mailinglistapi.py
620index 256bbfa..ec689eb 100644
621--- a/lib/lp/registry/tests/test_mailinglistapi.py
622+++ b/lib/lp/registry/tests/test_mailinglistapi.py
623@@ -6,7 +6,7 @@
624 __metaclass__ = type
625 __all__ = []
626
627-from email import message_from_string
628+import email
629 from textwrap import dedent
630
631 from six.moves import xmlrpc_client
632@@ -36,10 +36,7 @@ from lp.registry.xmlrpc.mailinglist import (
633 ENABLED,
634 MailingListAPIView,
635 )
636-from lp.services.compat import (
637- message_as_bytes,
638- message_from_bytes,
639- )
640+from lp.services.compat import message_as_bytes
641 from lp.services.config import config
642 from lp.services.identity.interfaces.account import AccountStatus
643 from lp.services.identity.interfaces.emailaddress import (
644@@ -449,7 +446,7 @@ class MailingListAPIMessageTestCase(TestCaseWithFactory):
645 self.factory.makeMailingList(team, owner)
646 sender = self.factory.makePerson(email='me@eg.dom')
647 with person_logged_in(sender):
648- message = message_from_string(dedent("""\
649+ message = email.message_from_string(dedent("""\
650 From: me@eg.dom
651 To: team@lists.launchpad.test
652 Subject: A question
653@@ -493,7 +490,7 @@ class MailingListAPIMessageTestCase(TestCaseWithFactory):
654 # Non-ascii messages headers are re-encoded for moderators.
655 team, sender, message = self.makeMailingListAndHeldMessage()
656 with person_logged_in(sender):
657- message = message_from_bytes(dedent("""\
658+ message = email.message_from_bytes(dedent("""\
659 From: \xa9 me <me@eg.dom>
660 To: team@lists.launchpad.test
661 Subject: \xa9 gremlins
662diff --git a/lib/lp/services/compat.py b/lib/lp/services/compat.py
663index 88df437..835b123 100644
664--- a/lib/lp/services/compat.py
665+++ b/lib/lp/services/compat.py
666@@ -10,15 +10,9 @@ __metaclass__ = type
667 __all__ = [
668 'escape',
669 'message_as_bytes',
670- 'message_from_bytes',
671 ]
672
673 try:
674- from email import message_from_bytes
675-except ImportError:
676- from email import message_from_string as message_from_bytes
677-
678-try:
679 from html import escape
680 except ImportError:
681 from cgi import escape
682diff --git a/lib/lp/services/mail/doc/emailauthentication.txt b/lib/lp/services/mail/doc/emailauthentication.txt
683index efcdce9..8cd8a8b 100644
684--- a/lib/lp/services/mail/doc/emailauthentication.txt
685+++ b/lib/lp/services/mail/doc/emailauthentication.txt
686@@ -108,14 +108,11 @@ be canonicalised to \r\n. In order to ensure that the line endings in
687 signed_canonicalised.txt are not already '\r\n', we recreate the test
688 message.
689
690- >>> from lp.services.compat import (
691- ... message_as_bytes,
692- ... message_from_bytes,
693- ... )
694+ >>> from lp.services.compat import message_as_bytes
695 >>> from lp.services.mail.signedmessage import SignedMessage
696 >>> msg = read_test_message('signed_canonicalised.txt')
697 >>> msg_lines = message_as_bytes(msg).splitlines()
698- >>> msg = message_from_bytes(
699+ >>> msg = email.message_from_bytes(
700 ... b'\n'.join(msg_lines), _class=SignedMessage)
701 >>> msg.parsed_bytes = message_as_bytes(msg)
702
703@@ -135,7 +132,7 @@ authenticateEmail() doesn't have any problems verifying the signature:
704
705 >>> from lp.registry.interfaces.person import IPerson
706 >>> for line_ending in b'\n', b'\r\n':
707- ... msg = message_from_bytes(
708+ ... msg = email.message_from_bytes(
709 ... line_ending.join(msg_lines), _class=SignedMessage)
710 ... msg.parsed_bytes = message_as_bytes(msg)
711 ... principal = authenticateEmail(msg, accept_any_timestamp)
712diff --git a/lib/lp/services/mail/doc/mailbox.txt b/lib/lp/services/mail/doc/mailbox.txt
713index aa9ac88..6424f2d 100644
714--- a/lib/lp/services/mail/doc/mailbox.txt
715+++ b/lib/lp/services/mail/doc/mailbox.txt
716@@ -74,8 +74,8 @@ before:
717 >>> len(mails)
718 2
719 >>> id, raw_mail = mails[0]
720- >>> from lp.services.compat import message_from_bytes
721- >>> mail = message_from_bytes(raw_mail)
722+ >>> import email
723+ >>> mail = email.message_from_bytes(raw_mail)
724 >>> print(mail['Message-ID'])
725 <test1>
726
727@@ -90,7 +90,7 @@ Since we didn't delete the mail, it's still in there:
728 >>> len(mails)
729 2
730 >>> id, raw_mail = mails[0]
731- >>> mail = message_from_bytes(raw_mail)
732+ >>> mail = email.message_from_bytes(raw_mail)
733 >>> print(mail['Message-ID'])
734 <test1>
735
736diff --git a/lib/lp/services/mail/doc/sending-mail.txt b/lib/lp/services/mail/doc/sending-mail.txt
737index de0483f..b520983 100644
738--- a/lib/lp/services/mail/doc/sending-mail.txt
739+++ b/lib/lp/services/mail/doc/sending-mail.txt
740@@ -17,10 +17,10 @@ The mail get sent when the transaction gets commited:
741
742 Now let's look at the sent email:
743
744- >>> from lp.services.compat import message_from_bytes
745+ >>> import email
746 >>> from lp.services.mail import stub
747 >>> from_addr, to_addr, raw_message = stub.test_emails.pop()
748- >>> msg = message_from_bytes(raw_message)
749+ >>> msg = email.message_from_bytes(raw_message)
750 >>> msg['To']
751 'test@canonical.com'
752 >>> msg['From']
753@@ -52,7 +52,7 @@ the person's name is encoded properly.
754
755 >>> transaction.commit()
756 >>> from_addr, to_addr, raw_message = stub.test_emails.pop()
757- >>> msg = message_from_bytes(raw_message)
758+ >>> msg = email.message_from_bytes(raw_message)
759 >>> msg['To']
760 'test@canonical.com'
761 >>> msg['From']
762@@ -86,7 +86,7 @@ simple_sendmail_from_person uses the Person's preferred email address:
763 >>> transaction.commit()
764 >>> found = False
765 >>> for from_addr, to_addr, raw_message in stub.test_emails:
766- ... msg = message_from_bytes(raw_message)
767+ ... msg = email.message_from_bytes(raw_message)
768 ... if msg['From'] == 'Sample Person <testing@canonical.com>':
769 ... found = True
770 >>> assert found
771@@ -109,7 +109,7 @@ the header will appear more than once in the output message.
772 >>> transaction.commit()
773
774 >>> from_addr, to_addr, raw_message = stub.test_emails.pop()
775- >>> msg = message_from_bytes(raw_message)
776+ >>> msg = email.message_from_bytes(raw_message)
777 >>> msg["X-Foo"]
778 'test'
779 >>> msg.get_all("X-Bar")
780@@ -129,7 +129,7 @@ only.
781 Now let's look at the sent email again.
782
783 >>> from_addr, to_addr, raw_message = stub.test_emails.pop()
784- >>> msg = message_from_bytes(raw_message)
785+ >>> msg = email.message_from_bytes(raw_message)
786
787 >>> from email.header import decode_header
788 >>> subject_str, charset = decode_header(msg['Subject'])[0]
789@@ -154,7 +154,7 @@ contain non-ASCII characters:
790 >>> transaction.commit()
791
792 >>> from_addr, to_addr, raw_message = stub.test_emails.pop()
793- >>> msg = message_from_bytes(raw_message)
794+ >>> msg = email.message_from_bytes(raw_message)
795
796 >>> from email.utils import parseaddr
797 >>> from_name_encoded, from_addr = parseaddr(msg['From'])
798@@ -185,7 +185,7 @@ surrounded by quotes and quoted if necessary:
799 >>> transaction.commit()
800
801 >>> from_addr, to_addr, raw_message = stub.test_emails.pop()
802- >>> msg = message_from_bytes(raw_message)
803+ >>> msg = email.message_from_bytes(raw_message)
804 >>> parseaddr(msg['From'])
805 ('Foo [Baz] " Bar', 'foo.bar@canonical.com')
806
807@@ -244,7 +244,7 @@ The message is the same as the one from the simple_sendmail test except
808 that the precedence header was not added.
809
810 >>> from_addr, to_addr, raw_message = stub.test_emails.pop()
811- >>> msg = message_from_bytes(raw_message)
812+ >>> msg = email.message_from_bytes(raw_message)
813 >>> msg['To']
814 'test@canonical.com'
815 >>> msg['From']
816@@ -282,7 +282,7 @@ provide better bounce handling.
817
818 >>> from lp.services.config import config
819 >>> from_addr, to_add, raw_message = stub.test_emails.pop()
820- >>> sent_msg = message_from_bytes(raw_message)
821+ >>> sent_msg = email.message_from_bytes(raw_message)
822 >>> sent_msg['Return-Path'] == config.canonical.bounce_address
823 True
824 >>> sent_msg['Errors-To'] == config.canonical.bounce_address
825@@ -301,7 +301,7 @@ It's possible to set Return-Path manually if needed.
826 >>> transaction.commit()
827
828 >>> from_addr, to_add, raw_message = stub.test_emails.pop()
829- >>> sent_msg = message_from_bytes(raw_message)
830+ >>> sent_msg = email.message_from_bytes(raw_message)
831 >>> sent_msg['Return-Path']
832 '<>'
833
834@@ -322,7 +322,7 @@ are ignored.
835 ... print(to_addr)
836 no-priv@canonical.com
837
838- >>> sent_msg = message_from_bytes(raw_message)
839+ >>> sent_msg = email.message_from_bytes(raw_message)
840 >>> sent_msg['To']
841 'test@canonical.com'
842 >>> sent_msg['CC']
843@@ -332,7 +332,7 @@ Since sendmail() gets the addresses to send to from the email header,
844 it needs to take care of unfolding the headers, so that they don't
845 contain any line breaks.
846
847- >>> folded_message = message_from_bytes(b"""Subject: required
848+ >>> folded_message = email.message_from_bytes(b"""Subject: required
849 ... From: Not used
850 ... <from.address@example.com>
851 ... To: To Address
852diff --git a/lib/lp/services/mail/notification.py b/lib/lp/services/mail/notification.py
853index 1d55202..9704416 100644
854--- a/lib/lp/services/mail/notification.py
855+++ b/lib/lp/services/mail/notification.py
856@@ -10,13 +10,13 @@ __all__ = [
857
858
859 from difflib import unified_diff
860+import email
861 from email.mime.message import MIMEMessage
862 from email.mime.multipart import MIMEMultipart
863 from email.mime.text import MIMEText
864 import re
865
866 from lp.bugs.mail.bugnotificationbuilder import get_bugmail_error_address
867-from lp.services.compat import message_from_bytes
868 from lp.services.config import config
869 from lp.services.mail.helpers import get_email_template
870 from lp.services.mail.mailwrapper import MailWrapper
871@@ -72,7 +72,7 @@ def send_process_error_notification(to_address, subject, error_msg,
872 original_msg_str = bytes(original_msg)
873 if len(original_msg_str) > max_return_size:
874 truncated_msg_str = original_msg_str[:max_return_size]
875- original_msg = message_from_bytes(truncated_msg_str)
876+ original_msg = email.message_from_bytes(truncated_msg_str)
877 msg.attach(MIMEMessage(original_msg))
878 sendmail(msg)
879
880diff --git a/lib/lp/services/mail/signedmessage.py b/lib/lp/services/mail/signedmessage.py
881index 02eeb90..732a397 100644
882--- a/lib/lp/services/mail/signedmessage.py
883+++ b/lib/lp/services/mail/signedmessage.py
884@@ -11,12 +11,12 @@ __all__ = [
885 'strip_pgp_signature',
886 ]
887
888+import email
889 from email.message import Message
890 import re
891
892 from zope.interface import implementer
893
894-from lp.services.compat import message_from_bytes
895 from lp.services.mail.interfaces import ISignedMessage
896
897
898@@ -42,7 +42,7 @@ def signed_message_from_bytes(buf):
899 It makes sure that the SignedMessage instance has access to the
900 parsed bytes.
901 """
902- msg = message_from_bytes(buf, _class=SignedMessage)
903+ msg = email.message_from_bytes(buf, _class=SignedMessage)
904 msg.parsed_bytes = buf
905 return msg
906
907diff --git a/lib/lp/services/mail/stub.py b/lib/lp/services/mail/stub.py
908index b63265c..c63d2fd 100644
909--- a/lib/lp/services/mail/stub.py
910+++ b/lib/lp/services/mail/stub.py
911@@ -5,16 +5,14 @@
912
913 __metaclass__ = type
914
915+import email
916 from logging import getLogger
917
918 from zope.component import getUtility
919 from zope.interface import implementer
920 from zope.sendmail.interfaces import IMailer
921
922-from lp.services.compat import (
923- message_as_bytes,
924- message_from_bytes,
925- )
926+from lp.services.compat import message_as_bytes
927
928
929 @implementer(IMailer)
930@@ -41,7 +39,7 @@ class StubMailer:
931 # headers that determine the actual To: address. However, this might
932 # be required to bypass some spam filters.
933 if self.rewrite:
934- message = message_from_bytes(message)
935+ message = email.message_from_bytes(message)
936 message['X-Orig-To'] = message['To']
937 message['X-Orig-Cc'] = message['Cc']
938 message['X-Orig-From'] = message['From']
939diff --git a/lib/lp/services/mail/tests/incomingmail.txt b/lib/lp/services/mail/tests/incomingmail.txt
940index 6fa33ca..bd77caa 100644
941--- a/lib/lp/services/mail/tests/incomingmail.txt
942+++ b/lib/lp/services/mail/tests/incomingmail.txt
943@@ -301,8 +301,7 @@ to the user, citing the OOPS ID, with the original message attached.
944
945 OOPS notifications work even if the From: address isn't properly MIME-encoded.
946
947- >>> from lp.services.compat import message_from_bytes
948- >>> msg = message_from_bytes(
949+ >>> msg = email.message_from_bytes(
950 ... u"""From: \u05D1 <bet@canonical.com>
951 ... To: launchpad@oops.com
952 ... X-Launchpad-Original-To: launchpad@oops.com
953diff --git a/lib/lp/services/mail/tests/test_stub.py b/lib/lp/services/mail/tests/test_stub.py
954index 85a549f..e1af47a 100644
955--- a/lib/lp/services/mail/tests/test_stub.py
956+++ b/lib/lp/services/mail/tests/test_stub.py
957@@ -15,9 +15,9 @@ def test_simple_sendmail():
958 r"""
959 Send an email (faked by TestMailer - no actual email is sent)
960
961+ >>> from email import message_from_bytes
962 >>> from email.mime.text import MIMEText
963 >>> import transaction
964- >>> from lp.services.compat import message_from_bytes
965 >>> from lp.services.mail import stub
966 >>> from lp.services.mail.sendmail import simple_sendmail
967
968diff --git a/lib/lp/services/messages/model/message.py b/lib/lp/services/messages/model/message.py
969index f6638b2..a2943ea 100644
970--- a/lib/lp/services/messages/model/message.py
971+++ b/lib/lp/services/messages/model/message.py
972@@ -11,6 +11,7 @@ __all__ = [
973 ]
974
975 from datetime import datetime
976+import email
977 from email.header import (
978 decode_header,
979 make_header,
980@@ -57,7 +58,6 @@ from lp.registry.interfaces.person import (
981 PersonCreationRationale,
982 validate_public_person,
983 )
984-from lp.services.compat import message_from_bytes
985 from lp.services.config import config
986 from lp.services.database.constants import UTC_NOW
987 from lp.services.database.datetimecol import UtcDateTimeCol
988@@ -376,7 +376,7 @@ class MessageSet:
989 # Parse the raw message into an email.message.Message instance,
990 # if we haven't been given one already.
991 if parsed_message is None:
992- parsed_message = message_from_bytes(email_message)
993+ parsed_message = email.message_from_bytes(email_message)
994
995 # We could easily generate a default, but a missing message-id
996 # almost certainly means a developer is using this method when
997diff --git a/lib/lp/services/verification/doc/logintoken.txt b/lib/lp/services/verification/doc/logintoken.txt
998index 9a8587c..201c15a 100644
999--- a/lib/lp/services/verification/doc/logintoken.txt
1000+++ b/lib/lp/services/verification/doc/logintoken.txt
1001@@ -49,7 +49,7 @@ Let's create a new LoginToken to confirm an email address for foobar.
1002 The email does not have a precedence header because the user implicitly
1003 requested it to complete their task.
1004
1005- >>> from lp.services.compat import message_from_bytes
1006+ >>> from email import message_from_bytes
1007
1008 >>> msg = message_from_bytes(found_msg)
1009 >>> print(msg['Precedence'])
1010diff --git a/lib/lp/services/verification/tests/logintoken.py b/lib/lp/services/verification/tests/logintoken.py
1011index 4f7d3ee..fda3d6a 100644
1012--- a/lib/lp/services/verification/tests/logintoken.py
1013+++ b/lib/lp/services/verification/tests/logintoken.py
1014@@ -3,16 +3,15 @@
1015
1016 """Helper functions for logintoken-related tests."""
1017
1018+import email
1019 import re
1020
1021 import six
1022
1023-from lp.services.compat import message_from_bytes
1024-
1025
1026 def get_token_url_from_email(email_msg):
1027 """Return the logintoken URL contained in the given email message."""
1028- msg = message_from_bytes(email_msg)
1029+ msg = email.message_from_bytes(email_msg)
1030 return get_token_url_from_bytes(msg.get_payload(decode=True))
1031
1032
1033diff --git a/lib/lp/testing/mail_helpers.py b/lib/lp/testing/mail_helpers.py
1034index 16bdcc2..23112fe 100644
1035--- a/lib/lp/testing/mail_helpers.py
1036+++ b/lib/lp/testing/mail_helpers.py
1037@@ -5,6 +5,7 @@
1038
1039 __metaclass__ = type
1040
1041+import email
1042 import operator
1043
1044 import six
1045@@ -18,7 +19,6 @@ from lp.registry.interfaces.persontransferjob import (
1046 ITeamInvitationNotificationJobSource,
1047 ITeamJoinNotificationJobSource,
1048 )
1049-from lp.services.compat import message_from_bytes
1050 from lp.services.config import config
1051 from lp.services.job.runner import JobRunner
1052 from lp.services.log.logger import DevNullLogger
1053@@ -44,7 +44,7 @@ def pop_notifications(sort_key=None, commit=True):
1054
1055 notifications = []
1056 for fromaddr, toaddrs, raw_message in stub.test_emails:
1057- notification = message_from_bytes(raw_message)
1058+ notification = email.message_from_bytes(raw_message)
1059 notification['X-Envelope-To'] = ', '.join(toaddrs)
1060 notification['X-Envelope-From'] = fromaddr
1061 notifications.append(notification)
1062diff --git a/lib/lp/translations/doc/translations-export-to-branch.txt b/lib/lp/translations/doc/translations-export-to-branch.txt
1063index c8b74b0..76b63db 100644
1064--- a/lib/lp/translations/doc/translations-export-to-branch.txt
1065+++ b/lib/lp/translations/doc/translations-export-to-branch.txt
1066@@ -223,8 +223,8 @@ The Launchpad UI allows users to register branches in the Launchpad
1067 database without populating them in bzr. Exporting to such a branch
1068 won't work, so we email a notification to the branch owner.
1069
1070+ >>> import email
1071 >>> from lp.codehosting.vfs import get_rw_server
1072- >>> from lp.services.compat import message_from_bytes
1073 >>> from lp.services.mail import stub
1074 >>> from lp.testing.factory import (
1075 ... remove_security_proxy_and_shout_at_engineer)
1076@@ -255,7 +255,7 @@ won't work, so we email a notification to the branch owner.
1077 >>> transaction.commit()
1078
1079 >>> sender, recipients, body = stub.test_emails.pop()
1080- >>> message = message_from_bytes(body)
1081+ >>> message = email.message_from_bytes(body)
1082 >>> print(message['Subject'])
1083 Launchpad: translations branch has not been set up.
1084

Subscribers

People subscribed via source and target branches

to status/vote changes: