Propagate body decode errors instead of swallowing them (#24)#81
Merged
Conversation
The MIME parts loop in src/mail_parser.rs decoded each part body with `get_body_raw().unwrap_or_default()` and `get_body().unwrap_or_default()`. When mailparse failed to decode a body (broken base64/quoted-printable or an undecodable charset) the error was silently discarded and an empty value stored, hiding corruption from the caller. Propagate the `MailParseError` from `get_body_raw`/`get_body` up through `Mail::new` instead. The PyO3 layer already maps `MailParseError` to the Python `ParseError`, so callers now see decode failures rather than empty bodies. Valid messages (including valid base64) are unaffected. Add tests/test_decode_errors.py covering broken-base64 text bodies and attachments raising ParseError, plus valid base64 and plain messages still parsing. Closes #24 Signed-off-by: yuriyryabikov <22548029+kurok@users.noreply.github.com>
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 issue #24 (high-priority bug): body decode errors were silently swallowed.
The MIME parts loop in
src/mail_parser.rsdecoded each part body withget_body_raw().unwrap_or_default()andget_body().unwrap_or_default(). When mailparse failed to decode a body (broken base64/quoted-printable or an undecodable charset), the error was discarded and an empty value stored — hiding corruption from the caller.Change
MailParseErrorfromget_body_raw/get_bodyup throughMail::new(which already returnsResult<_, MailParseError>). The PyO3 layer already mapsMailParseErrorto the PythonParseError, so callers now see decode failures rather than silently-empty bodies.Tests
Added
tests/test_decode_errors.py:ParseError(theget_body()path)ParseError(theget_body_raw()path)Full suite: 91 passed (87 existing + 4 new),
pytest -q --ignore tests/benchmark tests.Note: quoted-printable decoding in mailparse 0.15 is tolerant of invalid sequences (it passes them through rather than erroring), so the deterministic broken-encoding tests use base64.
Closes #24