Repository navigation
Conversation
Share transfer decoding between text bodies and attachments, and fall back to RawStdEncoding after StdEncoding fails, matching piguard's tolerance. Keep the original bytes when both decoders reject the input. Cover missing one/two padding characters in plain text, HTML and binary attachments, MIME whitespace, and malformed-input fallback. Fixes tokencanopy#1063 Co-authored-by: Codex <noreply@openai.com> Signed-off-by: Raul Ernesto Guillen Hernandez <37725305+RauPro@users.noreply.github.com>
6 tasks done
Author
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.
Summary
Fixes #1063. Base64 bodies and attachments with omitted padding currently fall back to their still-encoded wire content. Try
RawStdEncodingafterStdEncoding, matching the tolerance already used inpiguard, so these messages return decoded text, HTML and attachment bytes.Have
decode()delegate todecodeBytes()so bodies and attachments share one transfer-decoding policy. If both base64 decoders fail, preserve the original bytes, including whitespace, rather than returning a partially decoded prefix. Quoted-printable and identity decoding retain their existing behavior.Scope and operational risk
Internal MIME parsing only; no API schema, migration or SDK changes. The intended behavior change is accepting standard-alphabet base64 without padding. Malformed padding, impossible lengths, invalid characters and URL-safe alphabet inputs retain the existing raw fallback.
Test plan
Regression tests first reproduced six failing unpadded cases on
main: plain text, HTML and binary attachments, each with one or two padding characters missing. The same tests pass with this change. Padded inputs, MIME whitespace, exact HTML and binary-byte preservation, and malformed-input fallback are covered as well.Verified locally with Go 1.26.9:
go test ./...go test -race ./internal/mailparse/ -count=1make fmt-checkscripts/check-repository-text-integrity.shscripts/check-no-committed-credentials.shgit diff --checkPostgres-backed integration tests and live SMTP delivery were not run locally; this change is confined to the parser.