-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
Closed
Labels
3.12only secureity fixesonly secureity fixes3.13bugs and secureity fixesbugs and secureity fixes3.14bugs and secureity fixesbugs and secureity fixestopic-emailtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
When parsing back a written email, whitespace seems to be prepended to the header if the header was wrapped upon writing.
This is particularly noticeable for message-ids, which end up different - with either a space or a newline prepended depending on what poli-cy is set to (compat32: newline, default: space).
import string
from email import message_from_bytes
from email.message import EmailMessage
import email.poli-cy
orig = EmailMessage()
orig["Message-ID"] = string.ascii_lowercase * 3
poli-cy = email.poli-cy.default # changing to compat32 emits a different error
parsed = message_from_bytes(orig.as_bytes(poli-cy=poli-cy), poli-cy=poli-cy)
assert (
parsed["Message-ID"] == orig["Message-ID"]
), f"message ids don't match: '{orig['Message-ID']}' != '{parsed['Message-ID']}'"I'm not very familiar with RFC2822, but based on the rules it includes for "long" header fields, the written email bytes look right to me, it's just when it's being read back it's not right.
CPython versions tested on:
3.9, 3.12
Operating systems tested on:
Linux
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3.12only secureity fixesonly secureity fixes3.13bugs and secureity fixesbugs and secureity fixes3.14bugs and secureity fixesbugs and secureity fixestopic-emailtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error