Conversation
QuotedPrintableMailCodec.decodeData returned the undecoded source, so a quoted-printable attachment came out as `=25PDF=2D1=2E7` where the caller asked for `%PDF-1.7`. MailCodec.decodeBinary also had no entry for `quoted-printable`/`q` or `7bit` at all: it fell through to the undecoded source and only printed, so the corruption was silent. decodeData now decodes hex escapes to bytes and drops soft line breaks, applying no charset (an attachment's bytes are the payload, not text). Invalid escapes are passed through rather than dropped.
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.
Problem
QuotedPrintableMailCodec.decodeDatareturned the undecoded source (part.codeUnits), so any attachment withContent-Transfer-Encoding: quoted-printablecame out as its own source text: a PDF began=25PDF=2D1=2E7where the caller asked for%PDF-1.7.MailCodec.decodeBinaryalso had no entry forquoted-printable/q(or7bit) in_binaryDecodersByName, so it fell through to the undecoded source and only printed a message. The corruption was silent to the caller.Fix
decodeDatanow decodes=XYhex escapes to bytes and drops soft line breaks (=\r\n,=\n). It applies no charset: an attachment's bytes are the payload, not text. An invalid escape such as=ZZis passed through rather than dropped, and a trailing=with no hex digits is kept._binaryDecodersByNamegainsq,quoted-printableand7bit, so every encoding_textDecodersByNameknows has a binary counterpart.Tests
Eight new tests in
quoted_printable_mail_codec_test.dartcovering hex escapes, bytes above 0x7F, soft line breaks, literal pass-through, invalid and trailing escapes, and thedecodeBinaryrouting forquoted-printable,Qand7bit.