Merge ~cjwatson/launchpad:py3-MessageSet-fromEmail into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: cc1eff8560998fc345050e9de0d3d5aa1bf6d08b
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3-MessageSet-fromEmail
Merge into: launchpad:master
Diff against target: 21 lines (+1/-2)
1 file modified
lib/lp/services/messages/model/message.py (+1/-2)
Reviewer Review Type Date Requested Status
Cristian Gonzalez (community) Approve
Review via email: mp+399091@code.launchpad.net

Commit message

Fix MessageSet.fromEmail for Python 3

Description of the change

Using `lp.services.encoding.guess` doesn't work here, since the address may already be Unicode. It's possible that it's a native string on Python 2 after making its way through `email.utils.parseaddr`, though, so use `six.ensure_text` instead; there's no need to do any heuristic guesswork, as the addresses come from an RFC 2047 header which has explicit encoding information.

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/messages/model/message.py b/lib/lp/services/messages/model/message.py
2index 49cbef2..e592daa 100644
3--- a/lib/lp/services/messages/model/message.py
4+++ b/lib/lp/services/messages/model/message.py
5@@ -61,7 +61,6 @@ from lp.services.config import config
6 from lp.services.database.constants import UTC_NOW
7 from lp.services.database.datetimecol import UtcDateTimeCol
8 from lp.services.database.sqlbase import SQLBase
9-from lp.services.encoding import guess as ensure_unicode
10 from lp.services.librarian.interfaces import ILibraryFileAliasSet
11 from lp.services.messages.interfaces.message import (
12 IDirectEmailAuthorization,
13@@ -332,7 +331,7 @@ class MessageSet:
14 if not create_missing_persons:
15 raise UnknownSender(from_addrs[0][1])
16 # autocreate a person
17- sendername = ensure_unicode(from_addrs[0][0].strip())
18+ sendername = six.ensure_text(from_addrs[0][0].strip())
19 senderemail = from_addrs[0][1].lower().strip()
20 # XXX: Guilherme Salgado 2006-08-31 bug=62344:
21 # It's hard to define what rationale to use here, and to

Subscribers

People subscribed via source and target branches

to status/vote changes: