[issue15763] email non-ASCII characters in TO or FROM field doesn't work

R. David Murray report at bugs.python.org
Wed Aug 22 16:46:40 CEST 2012


R. David Murray added the comment:

Doing non-ASCII email in python before 3.3 is a bit of a pain and not as well documented as it should be.  3.3 will work more like you expect, if you use the new provisional policies (which are intended to become standard in 3.4, after a the bake-in period in 3.3).

For 3.2, you need to handle encoding addresses using utils.formataddr and header.Header:

>>> h = Header(header_name='Sender')
>>> h.append("Éric", 'latin-1')
>>> h.append('<eric at example.com>')
>>> h.encode()
'=?iso-8859-1?q?=C9ric?= <eric at example.com>'
>>> m = Message()
>>> m['Sender'] = h
>>> print(m)
Sender: =?iso-8859-1?q?=C9ric?= <eric at example.com>

In 3.3 this will work:

>>> m = Message()
>>> m['Sender'] = formataddr(('Éric', 'eric at example.com'))
>>> print(m)
Sender: =?iso-8859-1?q?=C9ric?= <eric at example.com>

But even better, so will this:

>>> m = Message(policy=policy.SMTP)
>>> m['From'] = "Günter Weiße <jarausch at igpm.rwth-aachen.de>"
>>> print(m)
From: =?utf-8?q?G=C3=BCnter_Wei=C3=9Fe?= <jarausch at igpm.rwth-aachen.de>

----------
resolution:  -> works for me
stage:  -> committed/rejected
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15763>
_______________________________________


More information about the Python-bugs-list mailing list