This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Sergei Maertens
Recipients Sergei Maertens, barry, r.david.murray
Date 2015-12-26.13:17:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1451135822.65.0.451627687424.issue25955@psf.upfronthosting.co.za>
In-reply-to
Content
The function `formataddr` in stdlib `email.utils` does not allow unicode e-mail addresses where the first part (before the @) is unicode. Python 3.5 promises support for SMTPUTF8 through `EmailPoliy.utf8` (https://docs.python.org/3/whatsnew/3.5.html#email), but this utility function doesn't respect this, as it calls `address.encode('ascii')`.

For unicode addresses, an obvious `UnicodeEncodeError` is raised.

Reproduce steps:

➜  ~  python
Python 3.5.1 (default, Dec  7 2015, 12:58:09) 
[GCC 5.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from email.utils import formataddr
>>> formataddr(('dummy', 'juan.lópez@abc.com'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.5/email/utils.py", line 91, in formataddr
    address.encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode character '\xf3' in position 6: ordinal not in range(128)

Interesting is that on Python 2.7 the behaviour is more naive, but it works::

➜  ~  python2
Python 2.7.11 (default, Dec  6 2015, 15:43:46) 
[GCC 5.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from email.utils import formataddr
>>> formataddr(('dummy', u'juan.lópez@abc.com'))
u'dummy <juan.l\xf3pez@abc.com>'
History
Date User Action Args
2015-12-26 13:17:02Sergei Maertenssetrecipients: + Sergei Maertens, barry, r.david.murray
2015-12-26 13:17:02Sergei Maertenssetmessageid: <1451135822.65.0.451627687424.issue25955@psf.upfronthosting.co.za>
2015-12-26 13:17:02Sergei Maertenslinkissue25955 messages
2015-12-26 13:17:01Sergei Maertenscreate