You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
generated email message exceeds RFC-mandated limit of 998 characters #84777
RFC53220 in section 2.1.1 mandates that the line cannot be longer than 998 characters and should not be longer than 78 characters (excluding CRLF). When we use raw_data_manager (default for EmailPolicy, EmailMessage) it does the correct thing as long as the message contains characters outside of 7bit US-ASCII set - base64 or qp Content-Transfer-Encoding which respects the line wrapping at 78 characters.
However if our message is limited the characters from the 7bit US-ASCII set no transfer encoding is applied, and such messages can easily go beyond 78 or even 998 characters.
The PR looks good to me, but I describe the change differently. I'm not sure how I missed this in the original implementation, since I obviously checked it for the 8bit case. Too long ago to remember :)
New changeset 6f2f475 by Arkadiusz Hiler in branch 'master': bpo-40597: email: Use CTE if lines are longer than max_line_length consistently (gh-20038) 6f2f475
New changeset c1f1ddf by Miss Islington (bot) in branch '3.8': bpo-40597: email: Use CTE if lines are longer than max_line_length consistently (gh-20038) (gh-20084) c1f1ddf
msapiro commented on May 30, 2020
msapiromannequin
Mannequin
More actions
With the fix in PR 20038, committed at 6f2f475 it is no longer possible to set_content(''). Attempts to do so produce the following
File "/var/MM/3/hk_39/hyperkitty/.tox/py39-django30/lib/python3.9/site-packages/django_mailman3/lib/scrub.py", line 95, in _get_all_attachments
part.set_content('')
File "/usr/local/lib/python3.9/email/message.py", line 1171, in set_content
super().set_content(*args, **kw)
File "/usr/local/lib/python3.9/email/message.py", line 1101, in set_content
content_manager.set_content(self, *args, **kw)
File "/usr/local/lib/python3.9/email/contentmanager.py", line 37, in set_content
handler(msg, obj, *args, **kw)
File "/usr/local/lib/python3.9/email/contentmanager.py", line 185, in set_text_content
cte, payload = _encode_text(string, charset, cte, msg.policy)
File "/usr/local/lib/python3.9/email/contentmanager.py", line 149, in _encode_text
if max(len(x) for x in lines) <= policy.max_line_length:
ValueError: max() arg is an empty sequence
New changeset c1c5034 by Miss Islington (bot) in branch '3.8': bpo-40597: Allow email.contextmanager set_content() to set a null string. (GH-20542) c1c5034
New changeset e689789 by Miss Islington (bot) in branch '3.9': bpo-40597: Allow email.contextmanager set_content() to set a null string. (GH-20542) e689789
Activity
ivyl commentedon May 11, 2020
RFC53220 in section 2.1.1 mandates that the line cannot be longer than 998 characters and should not be longer than 78 characters (excluding CRLF). When we use raw_data_manager (default for EmailPolicy, EmailMessage) it does the correct thing as long as the message contains characters outside of 7bit US-ASCII set - base64 or qp Content-Transfer-Encoding which respects the line wrapping at 78 characters.
However if our message is limited the characters from the 7bit US-ASCII set no transfer encoding is applied, and such messages can easily go beyond 78 or even 998 characters.
bitdancer commentedon May 11, 2020
The PR looks good to me, but I describe the change differently. I'm not sure how I missed this in the original implementation, since I obviously checked it for the 8bit case. Too long ago to remember :)
bitdancer commentedon May 14, 2020
New changeset 6f2f475 by Arkadiusz Hiler in branch 'master':
bpo-40597: email: Use CTE if lines are longer than max_line_length consistently (gh-20038)
6f2f475
bitdancer commentedon May 14, 2020
Thanks, Arkadiusz.
bitdancer commentedon May 18, 2020
New changeset c1f1ddf by Miss Islington (bot) in branch '3.8':
bpo-40597: email: Use CTE if lines are longer than max_line_length consistently (gh-20038) (gh-20084)
c1f1ddf
msapiro commentedon May 30, 2020
With the fix in PR 20038, committed at 6f2f475 it is no longer possible to set_content(''). Attempts to do so produce the following
miss-islington commentedon Jul 8, 2020
New changeset 4fa61a7 by Mark Sapiro in branch 'master':
bpo-40597: Allow email.contextmanager set_content() to set a null string. (GH-20542)
4fa61a7
miss-islington commentedon Jul 8, 2020
New changeset c1c5034 by Miss Islington (bot) in branch '3.8':
bpo-40597: Allow email.contextmanager set_content() to set a null string. (GH-20542)
c1c5034
miss-islington commentedon Jul 8, 2020
New changeset e689789 by Miss Islington (bot) in branch '3.9':
bpo-40597: Allow email.contextmanager set_content() to set a null string. (GH-20542)
e689789
maxking commentedon Jul 9, 2020
Closing this since the PRs for the behavior change reported by Mike and BPO-41206 is now merged too.
maxking commentedon Jul 9, 2020
Thanks Mark!