← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-MessageSet-fromEmail into launchpad:master.

Commit message:
Fix MessageSet.fromEmail for Python 3

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/399091

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.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-MessageSet-fromEmail into launchpad:master.
diff --git a/lib/lp/services/messages/model/message.py b/lib/lp/services/messages/model/message.py
index 49cbef2..e592daa 100644
--- a/lib/lp/services/messages/model/message.py
+++ b/lib/lp/services/messages/model/message.py
@@ -61,7 +61,6 @@ from lp.services.config import config
 from lp.services.database.constants import UTC_NOW
 from lp.services.database.datetimecol import UtcDateTimeCol
 from lp.services.database.sqlbase import SQLBase
-from lp.services.encoding import guess as ensure_unicode
 from lp.services.librarian.interfaces import ILibraryFileAliasSet
 from lp.services.messages.interfaces.message import (
     IDirectEmailAuthorization,
@@ -332,7 +331,7 @@ class MessageSet:
                 if not create_missing_persons:
                     raise UnknownSender(from_addrs[0][1])
                 # autocreate a person
-                sendername = ensure_unicode(from_addrs[0][0].strip())
+                sendername = six.ensure_text(from_addrs[0][0].strip())
                 senderemail = from_addrs[0][1].lower().strip()
                 # XXX: Guilherme Salgado 2006-08-31 bug=62344:
                 # It's hard to define what rationale to use here, and to