Skip to content

Make email/message.py read headers more robustly #123742

Closed as not planned
Closed as not planned
@zsolt-sb

Description

@zsolt-sb

Bug report

Bug description:

if variable 'attachment' is of type email.message.Message

attachment.get_payload(decode=True) 

Will yield the base64 content rather than the unecoded content if the sender provides the header 'base64 '

IE

attachment['Content-Transfer-Encoding']
'base64 '  <-notice the extra space

If we adjusted this code
https://github.com/python/cpython/blob/3.12/Lib/email/message.py#L290
to also strip(), this would resolve those edge cases where email clients erroneously add spaces.

This was an actual problem I have run into with a vendor.

CPython versions tested on:

3.9, 3.12

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtopic-emailtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions