This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: policy.max_line_length is incorrectly assumed to never be None
Type: behavior Stage: patch review
Components: email Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Jeffrey.Kintscher, andrei.avk, barry, equaeghe, iritkatriel, maxking, r.david.murray, s.williams-wynn
Priority: normal Keywords: patch

Created on 2020-08-18 20:47 by equaeghe, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 21955 closed s.williams-wynn, 2020-08-25 19:04
Messages (4)
msg375625 - (view) Author: Erik Quaeghebeur (equaeghe) Date: 2020-08-18 20:47
I got the following error (Python 3.7.8):

Traceback (most recent call last):
  File "/home/equaeghe/.local/bin/html2alternative.py", line 68, in <module>
    replaceable.add_alternative(plain)
  File "/usr/lib/python3.7/email/message.py", line 1153, in add_alternative
    self._add_multipart('alternative', *args, **kw)
  File "/usr/lib/python3.7/email/message.py", line 1144, in _add_multipart
    part.set_content(*args, **kw)
  File "/usr/lib/python3.7/email/message.py", line 1171, in set_content
    super().set_content(*args, **kw)
  File "/usr/lib/python3.7/email/message.py", line 1101, in set_content
    content_manager.set_content(self, *args, **kw)
  File "/usr/lib/python3.7/email/contentmanager.py", line 37, in set_content
    handler(msg, obj, *args, **kw)
  File "/usr/lib/python3.7/email/contentmanager.py", line 185, in set_text_content
    cte, payload = _encode_text(string, charset, cte, msg.policy)
  File "/usr/lib/python3.7/email/contentmanager.py", line 154, in _encode_text
    max(len(x) for x in lines) <= policy.max_line_length):
TypeError: '<=' not supported between instances of 'int' and 'NoneType'

This is triggered because it is incorrectly assumed that policy.max_line_length cannot be None. This issue is still present in current master:

https://github.com/python/cpython/blob/c3dd7e45cc5d36bbe2295c2840faabb5c75d83e4/Lib/email/contentmanager.py#L149
msg375653 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-08-19 15:16
Are you able to post a script that reproduces the issue?
msg375691 - (view) Author: Erik Quaeghebeur (equaeghe) Date: 2020-08-20 08:11
The script that triggered the issue can be found at

https://github.com/equaeghe/mailfilters/blob/master/html2alternative.py

You'll have to remove ", cte='8bit'" on line 68 to expose the bug (that was added as a workaround for this bug).

I was consistently able to trigger the bug when applying it to a mail with a multipart/alternative with text and html parts already present. It should replace that html part by a (nested) multipart/alternative part, but it crashes unless you keep the workaround.
msg409280 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2021-12-29 03:47
Seems to be a duplicate of #34800
History
Date User Action Args
2022-04-11 14:59:34adminsetgithub: 85751
2021-12-29 03:47:26andrei.avksetnosy: + andrei.avk
messages: + msg409280
2020-08-25 19:04:23s.williams-wynnsetkeywords: + patch
nosy: + s.williams-wynn

pull_requests: + pull_request21064
stage: patch review
2020-08-20 12:46:58xtreaksetnosy: + maxking
2020-08-20 08:11:18equaeghesetmessages: + msg375691
2020-08-20 03:01:25Jeffrey.Kintschersetnosy: + Jeffrey.Kintscher
2020-08-19 15:16:39iritkatrielsetnosy: + iritkatriel
messages: + msg375653
2020-08-18 20:47:21equaeghecreate