gh-49680: Add translate_line_endings parameter to imaplib.IMAP4.append#152775
Merged
serhiy-storchaka merged 3 commits intoJul 2, 2026
Merged
Conversation
Pass False to send the message as an exact sequence of octets, without rewriting bare CR or LF to CRLF. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Documentation build overview
|
Read the APPEND literal by its octet count and verify that a serialized email message with bare LF is sent verbatim when translate_line_endings is false. Document using email.policy.SMTP for that case. Co-authored-by: harjoth <harjoth.khara@gmail.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…slate-newlines # Conflicts: # Lib/test/test_imaplib.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
IMAP4.append()rewrote every bare CR or LF in the message to CRLF(
MapCRLF.sub(CRLF, message)) before sending it as the APPEND literal.But an IMAP literal is "a sequence of octets (including CR and LF)"
(:rfc:
3501), and the protocol framing -- the octet count and thetrailing CRLF -- is handled separately by
_command(), so rewriting thepayload silently corrupts the caller's message (for example, content with
intentional bare CR or LF, reported back in 2009).
This adds a keyword-only
translate_line_endingsparameter. It defaultsto
True, preserving the previous behavior; passingFalsesends themessage literal exactly as given.
smtplibis intentionally left unchanged: it transmits the message asCRLF-terminated lines in the
DATAcommand (:rfc:5321), wherenormalization is required for correct framing -- unlike an octet-counted
IMAP literal.