-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Open
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-emailtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
From the documentation
max_line_length
The maximum length of any line in the serialized output, not counting the end of line character(s). Default is 78, per RFC 5322. A value of 0 or None indicates that no line wrapping should be done at all.
If I follow this documentation then set_content
will fail. If I use the provided email.policy.HTTP
, which disables word wrapping, it also fails.
from email import policy
from email.message import EmailMessage
msg = EmailMessage(policy=policy.default.clone(max_line_length=None))
msg["From"] = "[email protected]"
msg["To"] = "[email protected]"
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'
Using max_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
Linked PRs
Metadata
Metadata
Assignees
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-emailtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error