Skip to content

Backport of email package breaks when used with unicode newstr #534

Description

@tsx

How to reproduce:

Python2 with latest future

>>> from builtins import str
>>> from future.backports.email.mime.text import MIMEText
>>> m = MIMEText('x')
>>> m['x'] = str(u'ó')
>>> m.as_string()
... snip ...
AttributeError: encode method has been disabled in newbytes

Python3:

>>> from email.mime.text import MIMEText
>>> m = MIMEText('x')
>>> m['x'] = str(u'ó')
>>> m.as_string()
'Content-Type: text/plain; charset="us-ascii"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\nx: =?utf-8?b?w7M=?=\n\nx'

I suspect that the cause is missing builtins.str import in https://github.com/PythonCharmers/python-future/blob/master/src/future/backports/email/base64mime.py.

Native str is being used in isinstance check in this module:
https://github.com/PythonCharmers/python-future/blob/master/src/future/backports/email/base64mime.py#L72

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions