Skip to content

Fix broken string literal that disabled the quoted-printable attachment branch#163

Open
chuenchen309 wants to merge 1 commit into
SpamScope:developfrom
chuenchen309:fix/quoted-printable-attachment-literal
Open

Fix broken string literal that disabled the quoted-printable attachment branch#163
chuenchen309 wants to merge 1 commit into
SpamScope:developfrom
chuenchen309:fix/quoted-printable-attachment-literal

Conversation

@chuenchen309

Copy link
Copy Markdown

In core.py's parse(), the branch that keeps quoted-printable application/*
attachments as binary has a broken string literal:

elif transfer_encoding == "base64" or (
    transfer_encoding
    == "quoted-\
                   printable"
    and "application" in mail_content_type
):

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 the
text branch and is decoded as UTF-8 with errors="ignore", silently dropping
every non-UTF8 byte
and setting binary=False. A 16-byte binary attachment
comes back as 9 bytes; the original file is unrecoverable.

Joining the literal to == "quoted-printable" restores the intended
binary-preserving path (the base64 operand next to it is already a clean
single-line literal). Added a test with a quoted-printable
application/octet-stream attachment that now round-trips losslessly; the
existing text/plain quoted-printable test is unaffected (it stays
binary=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.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant