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 Michael.JasonSmith
Recipients Michael.JasonSmith
Date 2014-03-03.18:14:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1393870493.46.0.373030769514.issue20845@psf.upfronthosting.co.za>
In-reply-to
Content
The email.utils.formataddr function is used to encode a name-address 2-tuple for use as an email message. If the name contains a non-ASCII character it needs to be encoded. This happens correctly in Python 3.3.2, but incorrectly in Python 2.7.5. Ideally Python 2 would acquire the Python 3 behaviour, as this should make porting easier.

In the following Python 3.3.2 example the name is encoded because of the non-ASCII ☢ character:
>>> import email.utils
>>> name = 'Me ☢'
>>> addr = 'mpj17@onlinegroups.net'
>>> email.utils.formataddr((name, addr))
'=?utf-8?b?TWUg4pii?= <mpj17@onlinegroups.net>'

In Python 2.7.5 the same name is incorrectly left unaltered:
>>> import email.utils
>>> name = u'Me ☢'
>>> addr = 'mpj17@onlinegroups.net'
>>> email.utils.formataddr((name, addr))
u'Me \u2622 <mpj17@onlinegroups.net>'

However, calling the email.header.Header.encode method works around this issue in Python 2:
>>> import email.utils
>>> import email.header
>>> name = u'Me ☢'
>>> addr = 'mpj17@onlinegroups.net'
>>> h = email.header.Header(name)
>>> email.utils.formataddr((h.encode(), addr))
'=?utf-8?b?TWUg4pii?= <mpj17@onlinegroups.net>'

The example code immediately above also works in Python 3; it is the current work-around in GroupServer. However, ideally instances of Unicode objects passed to email.utils.formataddr will work the same in both Python 2 and Python 3.
History
Date User Action Args
2014-03-03 18:14:53Michael.JasonSmithsetrecipients: + Michael.JasonSmith
2014-03-03 18:14:53Michael.JasonSmithsetmessageid: <1393870493.46.0.373030769514.issue20845@psf.upfronthosting.co.za>
2014-03-03 18:14:53Michael.JasonSmithlinkissue20845 messages
2014-03-03 18:14:53Michael.JasonSmithcreate