fix(gmail): use case-insensitive matching for email headers in parse_message_headers#674
fix(gmail): use case-insensitive matching for email headers in parse_message_headers#674gura105 wants to merge 3 commits intogoogleworkspace:mainfrom
Conversation
…message_headers The Gmail API preserves original header casing from the sending MTA. For example, Microsoft Exchange emits "CC" instead of "Cc". Per RFC 5322 §1.2.2, header field names are case-insensitive. parse_message_headers used exact case-sensitive string matching, so headers like "CC", "FROM", or "message-id" silently fell through to the catch-all, dropping recipients and metadata. This change normalizes header names via to_ascii_lowercase() before matching, consistent with the existing get_part_header function in the same file which already uses eq_ignore_ascii_case. Fixes googleworkspace#642
Avoids per-header String allocation in the loop. Consistent with get_part_header in the same file. Addresses gemini-code-assist review feedback.
🦋 Changeset detectedLatest commit: 5d071a7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where email header parsing was failing due to strict case-sensitive matching. By adopting case-insensitive comparisons, the system now correctly handles headers regardless of the originating MTA's casing conventions, ensuring reliable extraction of essential message metadata. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request implements case-insensitive matching for email headers in the parse_message_headers function within the Gmail helper module, aligning with RFC 5322 requirements. The changes replace exact string matching with eq_ignore_ascii_case for standard headers and include new unit tests covering uppercase, lowercase, and mixed-case scenarios. I have no feedback to provide.
Description
parse_message_headersuses exact case-sensitive string matching for header names ("Cc","From", etc.), but the Gmail API preserves original header casing from the sending MTA. Per RFC 5322 §1.2.2, header field names are case-insensitive.This causes
+reply-all(and other commands) to silently drop CC recipients when the original message was sent through an MTA that uses non-canonical casing (e.g., Microsoft Exchange emits"CC"instead of"Cc").Root cause
Fix
Use
eq_ignore_ascii_casematch guards for zero-allocation case-insensitive matching, consistent with the existingget_part_headerandextract_headerfunctions in the same file.This also simplifies the
Message-IDarm from"Message-ID" | "Message-Id"to justeq_ignore_ascii_case("message-id").Scope
All headers in the match block are affected, not just
Cc:From"Message is missing From header")Message-ID"Message is missing Message-ID header")To+reply-allmisses To recipientsCC+reply-alldrops CC recipientsReply-ToReferencesTests
3 new tests (701 total, up from 698):
test_parse_message_headers_all_uppercase— all-caps headers (Exchange/Outlook pattern)test_parse_message_headers_all_lowercase— all-lowercase headerstest_parse_message_headers_mixed_case— canonical + non-canonical mixAll existing tests pass unchanged.
Fixes #642
Checklist:
AGENTS.mdguidelines (no generatedgoogle-*crates).cargo fmt --allto format the code perfectly.cargo clippy -- -D warningsand resolved all warnings.pnpx changeset) to document my changes.