Message287294
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. | |
Date | User | Action | Args | 2017-02-08 10:10:45 | martin.panter | set | recipients: + martin.panter, barry, r.david.murray | 2017-02-08 10:10:45 | martin.panter | set | messageid: <1486548645.73.0.926739197467.issue29478@psf.upfronthosting.co.za> | 2017-02-08 10:10:45 | martin.panter | link | issue29478 messages | 2017-02-08 10:10:45 | martin.panter | create | | |