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 rad164
Recipients barry, r.david.murray, rad164
Date 2018-05-15.16:35:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Python 3.6.5 has trouble on folding email messages:

Traceback (most recent call last):
  File "", line 7, in <module>
    policy.fold("Subject", msg["Subject"])
  File "/usr/lib/python3.6/email/", line 183, in fold
    return self._fold(name, value, refold_binary=True)
  File "/usr/lib/python3.6/email/", line 205, in _fold
    return value.fold(policy=self)
  File "/usr/lib/python3.6/email/", line 258, in fold
    return header.fold(policy=policy)
  File "/usr/lib/python3.6/email/", line 144, in fold
    return _refold_parse_tree(self, policy=policy)
  File "/usr/lib/python3.6/email/", line 2651, in _refold_parse_tree
    part.ew_combine_allowed, charset)
  File "/usr/lib/python3.6/email/", line 2728, in _fold_as_ew
    first_part = to_encode[:text_space]
TypeError: slice indices must be integers or None or have an __index__ method

The message has non-ascii characters in header and set max_line_length=0, regardless length of the header. Here is the code to reproduce.

from email.message import EmailMessage
from email.policy import default

policy = default.clone(max_line_length=0)
msg = EmailMessage()
msg["Subject"] = "á"
policy.fold("Subject", msg["Subject"])

I first found this issue on Maildir.add, which saves the message to a file without word wrap.
Date User Action Args
2018-05-15 16:35:30rad164setrecipients: + rad164, barry, r.david.murray
2018-05-15 16:35:30rad164setmessageid: <>
2018-05-15 16:35:30rad164linkissue33524 messages
2018-05-15 16:35:30rad164create