Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generated email message exceeds RFC-mandated limit of 998 characters #84777

Closed
ivyl mannequin opened this issue May 11, 2020 · 11 comments
Closed

generated email message exceeds RFC-mandated limit of 998 characters #84777

ivyl mannequin opened this issue May 11, 2020 · 11 comments
Labels
3.8 only security fixes 3.9 only security fixes topic-email type-bug An unexpected behavior, bug, or error

Comments

@ivyl
Copy link
Mannequin

ivyl mannequin commented May 11, 2020

BPO 40597
Nosy @warsaw, @msapiro, @bitdancer, @maxking, @miss-islington, @ivyl
PRs
  • bpo-40597: email: Don't shy from using CTE for US-ASCII-only emails #20038
  • [3.8] bpo-40597: email: Use CTE if lines are longer than max_line_length consistently (gh-20038) #20084
  • bpo-40597: Allow email.contextmanager set_content() to set a null string. #20542
  • [3.9] bpo-40597: Allow email.contextmanager set_content() to set a null string. (GH-20542) #21404
  • [3.8] bpo-40597: Allow email.contextmanager set_content() to set a null string. (GH-20542) #21405
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-07-09.00:18:35.262>
    created_at = <Date 2020-05-11.19:00:19.898>
    labels = ['type-bug', '3.8', 'expert-email', '3.9']
    title = 'generated email message exceeds RFC-mandated limit of 998 characters'
    updated_at = <Date 2020-07-09.00:19:01.131>
    user = 'https://github.com/ivyl'

    bugs.python.org fields:

    activity = <Date 2020-07-09.00:19:01.131>
    actor = 'maxking'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-07-09.00:18:35.262>
    closer = 'maxking'
    components = ['email']
    creation = <Date 2020-05-11.19:00:19.898>
    creator = 'ivyl'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40597
    keywords = ['patch']
    message_count = 11.0
    messages = ['368641', '368646', '368810', '368811', '369157', '370395', '373350', '373353', '373354', '373362', '373363']
    nosy_count = 6.0
    nosy_names = ['barry', 'msapiro', 'r.david.murray', 'maxking', 'miss-islington', 'ivyl']
    pr_nums = ['20038', '20084', '20542', '21404', '21405']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue40597'
    versions = ['Python 3.8', 'Python 3.9']

    @ivyl
    Copy link
    Mannequin Author

    ivyl mannequin commented 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.

    @ivyl ivyl mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes topic-email type-bug An unexpected behavior, bug, or error labels May 11, 2020
    @bitdancer
    Copy link
    Member

    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
    Copy link
    Member

    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
    Copy link
    Member

    Thanks, Arkadiusz.

    @bitdancer bitdancer removed 3.7 (EOL) end of life labels May 14, 2020
    @bitdancer
    Copy link
    Member

    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
    Copy link
    Mannequin

    msapiro mannequin commented 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

      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
    

    @miss-islington
    Copy link
    Contributor

    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
    Copy link
    Contributor

    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
    Copy link
    Contributor

    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
    Copy link
    Contributor

    maxking commented Jul 9, 2020

    Closing this since the PRs for the behavior change reported by Mike and BPO-41206 is now merged too.

    @maxking maxking closed this as completed Jul 9, 2020
    @maxking maxking closed this as completed Jul 9, 2020
    @maxking
    Copy link
    Contributor

    maxking commented Jul 9, 2020

    Thanks Mark!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes 3.9 only security fixes topic-email type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants