Skip to content

email: encoded headers lose their quoting when refolded #87720

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

Open
EmilStyrke mannequin opened this issue Mar 19, 2021 · 3 comments
Open

email: encoded headers lose their quoting when refolded #87720

EmilStyrke mannequin opened this issue Mar 19, 2021 · 3 comments
Labels
3.9 only security fixes stdlib Python modules in the Lib dir topic-email type-bug An unexpected behavior, bug, or error

Comments

@EmilStyrke
Copy link
Mannequin

EmilStyrke mannequin commented Mar 19, 2021

BPO 43554
Nosy @warsaw, @bitdancer, @maxking
Files
  • test_folding_bug.py: unittest displaying the issue
  • 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 = None
    created_at = <Date 2021-03-19.09:45:02.487>
    labels = ['type-bug', 'library', '3.9']
    title = 'email: encoded headers lose their quoting when refolded'
    updated_at = <Date 2021-03-19.18:30:12.248>
    user = 'https://bugs.python.org/EmilStyrke'

    bugs.python.org fields:

    activity = <Date 2021-03-19.18:30:12.248>
    actor = 'shihai1991'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2021-03-19.09:45:02.487>
    creator = 'Emil.Styrke'
    dependencies = []
    files = ['49893']
    hgrepos = []
    issue_num = 43554
    keywords = []
    message_count = 1.0
    messages = ['389061']
    nosy_count = 4.0
    nosy_names = ['barry', 'r.david.murray', 'Emil.Styrke', 'maxking']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue43554'
    versions = ['Python 3.9']

    Linked PRs

    @EmilStyrke
    Copy link
    Mannequin Author

    EmilStyrke mannequin commented Mar 19, 2021

    When a header with an encoded (QP or Base64) display_name is refolded, it may lose (some of) its encoding. If it then contains illegal "atext" tokens, an invalid header will result.

    For example, From: =?utf-8?Q?a=2C=20123456789012345678901234567890123456?= <abc@example.com> will become From: a, 123456789012345678901234567890123456 <abc@example.com> This contains a comma character which needs to be quoted: correct rendering would be From: "a, 123456789012345678901234567890123456" <abc@example.com>. Note that this example isn't even folded to multiple lines, since the decoded text is short enough to fit in one line.

    This can be triggered by BytesParser(policy=policy.default).parsebytes("From: =?utf-8?Q?a=2C=20123456789012345678901234567890123456?= <abc@example.com>").as_bytes(), but the offending code seems to be in or below email.policy.EmailPolicy.fold. See attached file for examples with and without folding.

    @EmilStyrke EmilStyrke mannequin added 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Mar 19, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @brychcy
    Copy link

    brychcy commented May 12, 2025

    See #121284

    @medmunds
    Copy link
    Contributor

    rfc2047 RFC-2047 encoded-word

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes stdlib Python modules in the Lib dir topic-email type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants