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 <1486548645.73.0.926739197467.issue29478@psf.upfronthosting.co.za>
In-reply-to
Content
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 <https://docs.python.org/release/3.5.2/library/email.policy.html#email.policy.Policy.max_line_length> 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
Field: 
 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

>>> 

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.
History
Date User Action Args
2017-02-08 10:10:45martin.pantersetrecipients: + martin.panter, barry, r.david.murray
2017-02-08 10:10:45martin.pantersetmessageid: <1486548645.73.0.926739197467.issue29478@psf.upfronthosting.co.za>
2017-02-08 10:10:45martin.panterlinkissue29478 messages
2017-02-08 10:10:45martin.pantercreate