New submission from Martin Panter: 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. ---------- components: email messages: 287294 nosy: barry, martin.panter, r.david.murray priority: normal severity: normal status: open title: email.policy.Compat32(max_line_length=None) not as documented type: behavior versions: Python 3.5, Python 3.6, Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue29478> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com