Fix broken string literal that disabled the quoted-printable attachment branch#163
Open
chuenchen309 wants to merge 1 commit into
Open
Conversation
…nt branch A line-continuation inside the string literal made the comparison target "quoted- printable" (the continuation line's indentation became part of the string), so it never equalled "quoted-printable". The branch handling quoted-printable application/* attachments was therefore dead: such attachments fell through to the text branch and were decoded as UTF-8 with errors="ignore", silently dropping every non-UTF8 byte and mis-flagging binary=False. Join the literal so the comparison works. Added a test with a quoted-printable application/octet-stream attachment that round-trips losslessly.
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.
In
core.py'sparse(), the branch that keeps quoted-printableapplication/*attachments as binary has a broken string literal:
The backslash is a line continuation, so the continuation line's indentation
becomes part of the string — the comparison target is
"quoted- printable", which never equals"quoted-printable". That branch is dead.As a result a quoted-printable
application/*attachment falls through to thetext branch and is decoded as UTF-8 with
errors="ignore", silently droppingevery non-UTF8 byte and setting
binary=False. A 16-byte binary attachmentcomes back as 9 bytes; the original file is unrecoverable.
Joining the literal to
== "quoted-printable"restores the intendedbinary-preserving path (the
base64operand next to it is already a cleansingle-line literal). Added a test with a quoted-printable
application/octet-streamattachment that now round-trips losslessly; theexisting
text/plainquoted-printable test is unaffected (it staysbinary=False), which is why the bug was never caught.This PR was authored by an AI coding agent (Claude Code) running on this account:
the AI found the bug, ran the repro, wrote the test, and wrote this description.
The human account holder reviews every change and is accountable for it. The
verification is real and re-runnable from the diff. If this isn't the kind of
contribution you want, say so and I'll close it.