Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Closed
Description
Bug report
Bug description:
From thedocumentation
max_line_length
The maximum length of any line in the serialized output, not counting the end of line character(s). Default is 78, perRFC 5322. A value of 0 orNone indicates that no line wrapping should be done at all.
If I follow this documentation thenset_content will fail. If I use the providedemail.policy.HTTP, which disables word wrapping, it also fails.
fromemailimportpolicyfromemail.messageimportEmailMessagemsg=EmailMessage(policy=policy.default.clone(max_line_length=None))msg["From"]="noreply@example.com"msg["To"]="noreply@example.com"msg["Subject"]="Email no wrap fails"msg.set_content("This line fails")print(msg)
Stack trace:
File "/usr/lib/python3.13/email/message.py", line 1207, in set_content super().set_content(*args, **kw) ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^ File "/usr/lib/python3.13/email/message.py", line 1137, in set_content content_manager.set_content(self, *args, **kw) ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.13/email/contentmanager.py", line 37, in set_content handler(msg, obj, *args, **kw) ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.13/email/contentmanager.py", line 187, in set_text_content cte, payload = _encode_text(string, charset, cte, msg.policy) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.13/email/contentmanager.py", line 151, in _encode_text if max((len(x) for x in lines), default=0) <= policy.max_line_length: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^TypeError: '<=' not supported between instances of 'int' and 'NoneType'Usingmax_line_length=0 gives a different error:
File "/usr/lib/python3.13/email/message.py", line 1207, in set_content super().set_content(*args, **kw) ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^ File "/usr/lib/python3.13/email/message.py", line 1137, in set_content content_manager.set_content(self, *args, **kw) ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.13/email/contentmanager.py", line 37, in set_content handler(msg, obj, *args, **kw) ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.13/email/contentmanager.py", line 187, in set_text_content cte, payload = _encode_text(string, charset, cte, msg.policy) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.13/email/contentmanager.py", line 159, in _encode_text sniff_qp = quoprimime.body_encode(sniff.decode('latin-1'), policy.max_line_length) File "/usr/lib/python3.13/email/quoprimime.py", line 173, in body_encode raise ValueError("maxlinelen must be at least 4")CPython versions tested on:
3.13
Operating systems tested on:
Linux