fix(gmail): decode message bodies by declared charset instead of dropping non-UTF-8 (P1 data loss)#114
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
Next review available in: 5 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
b2de80f to
fa6dc7c
Compare
…ping non-UTF-8 Gmail's API returns each part's original bytes untranscoded, so a text/plain; charset=windows-1252 (or iso-8859-1, shift_jis) body failed the strict from_utf8 in base64_decode_url; .ok() then turned it into None and the entire body was silently lost while envelope/subject/snippet remained. Split base64 decoding from string decoding: decode_body_part now decodes the part's bytes using the charset declared in its Content-Type header (via encoding_rs), defaulting to UTF-8 and falling back to lossy decode for unknown labels so content is never dropped. The three text leaves in walk_parts (text/plain, text/html, text/calendar) are now charset-aware. The IMAP path already charset-decoded via mail_parser and is unaffected.
fa6dc7c to
e5ec17f
Compare
Problem (P1 data loss)
base64_decode_urlended inString::from_utf8(bytes)?andwalk_partscalled it via.ok(). Gmail returns each part's ORIGINAL bytes untranscoded, so acharset=windows-1252/iso-8859-1/shift_jisbody (e.g.0xE9=é,0x92=') failed strict UTF-8 →None→text_plain/text_htmlnever set → the entire body silently vanished (envelope/subject/snippet remained). IMAP path was unaffected.Fix
Split base64→bytes from bytes→string; decode each text leaf with its declared Content-Type charset via
encoding_rs(default UTF-8, lossy fallback — content is never dropped).charset_from_content_typeparses thecharset=param (case-insensitive, quote-stripped).extract_bodysignature preserved; provider logic stays in the provider crate. Addedencoding_rs(already locked transitively via mail-parser). 3 regression tests; 70 provider-gmail tests pass.CI note: workspace clippy red on pre-existing 1.97 lints until #111 merges; will rebase (Cargo.lock).
Summary by cubic
Decode Gmail message bodies using the charset declared in Content-Type instead of assuming UTF‑8, preventing non‑UTF‑8 text from being dropped. Defaults to UTF‑8; unknown labels use a lossy fallback so content isn’t lost.
Bug Fixes
encoding_rs.charset=from Content-Type (case-insensitive, strips quotes).text/plain,text/html, andtext/calendar;extract_bodyunchanged; IMAP path unaffected.windows-1252, quotedISO-8859-1, and UTF‑8 multibyte.Dependencies
encoding_rsto the workspace andprovider-gmail.Written for commit e5ec17f. Summary will update on new commits.