[issue35222] email.utils.formataddr is not exactly the reverse of email.utils.parseaddr

R. David Murray report at bugs.python.org
Mon Nov 12 18:50:38 EST 2018


R. David Murray <rdmurray at bitdance.com> added the comment:

Thanks for the report, but parseaddr and formataddr are defined *only* for ASCII.  In the port to python3, parseaddr sort-of-maybe-sometimes does the naively expected thing with non-ascii, but that's just an accident.  We could have added a check for non-ascii to parseaddr during the python3 port, but we didn't think of it, and it is too late now since adding it would break otherwise working code even though that code is technically broken.

So, for the defined API of parseaddr/formataddr, there is no bug here.

As for handling non-ascii in email per your link:

    >>> from email.message import EmailMessage
    >>> from email.policy import default
    >>> m = EmailMessage(policy=default.clone(utf8=True))
    >>> m['From'] = 'skreft+ñandú@sudoai.com
    >>> bytes(m)
    b'From: skreft+\xc3\xb1and\xc3\xba at sudoai.com\n\n'

(NB: in testing the above I discovered there is actually a recent bug in the serialization when utf8 is *False*: it does RFC2047 encoding of the username, which it should not do...instead it should raise an error.  Feel free to open a bug report for that...)

----------
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed
type:  -> behavior

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35222>
_______________________________________


More information about the Python-bugs-list mailing list