Message257034
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>' |
|
Date |
User |
Action |
Args |
2015-12-26 13:17:02 | Sergei Maertens | set | recipients:
+ Sergei Maertens, barry, r.david.murray |
2015-12-26 13:17:02 | Sergei Maertens | set | messageid: <1451135822.65.0.451627687424.issue25955@psf.upfronthosting.co.za> |
2015-12-26 13:17:02 | Sergei Maertens | link | issue25955 messages |
2015-12-26 13:17:01 | Sergei Maertens | create | |
|