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 martin.panter
Recipients barry, martin.panter, r.david.murray
Date 2017-02-08.10:10:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
By default, the email package turns single-line header fields into multi-line ones to try and limit the length of each line. The documentation <> says that setting the policy’s max_line_length attribute to None should prevent line wrapping. But this does not work:

>>> from email.policy import Compat32
>>> from email.message import Message
>>> from email.generator import Generator
>>> from sys import stdout
>>> p = Compat32(max_line_length=None)
>>> m = Message(p)
>>> m["Field"] = "x" * 100
>>> Generator(stdout).flatten(m)  # Field is split across two lines


A workaround is to specify zero instead:

>>> p = Compat32(max_line_length=0)
>>> Generator(stdout, policy=p).flatten(m)  # All on one line
Field: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Quickly looking at the code, Compat32._fold() passes max_line_length straight to Header.encode(), which is documented as using None as a placeholder for its real default value of 76. So I think the solution would be to add a special case in _fold() to call encode(maxlinelen=0) if max_line_length is None.
Date User Action Args
2017-02-08 10:10:45martin.pantersetrecipients: + martin.panter, barry, r.david.murray
2017-02-08 10:10:45martin.pantersetmessageid: <>
2017-02-08 10:10:45martin.panterlinkissue29478 messages
2017-02-08 10:10:45martin.pantercreate