feat(gmail): auto-populate From display name + fix reply-all to own message#530
Conversation
🦋 Changeset detectedLatest commit: 674c298 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 significantly enhances the Gmail CLI helpers by improving how sender information is handled and by correcting a long-standing issue with reply-all functionality. It introduces automatic population of the 'From' header with configured display names, making sent emails appear more professional and consistent with the web client. Additionally, it resolves a critical bug where replying-all to one's own message would fail, ensuring a smoother and more reliable user experience for email interactions. 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 introduces two valuable features for the Gmail helpers: auto-populating the 'From' header with a display name, and fixing an issue with 'reply-all' to one's own messages. The implementation is robust, with comprehensive unit tests covering various edge cases. The code is clean and well-documented.
4da0b23 to
a12d6be
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces two main features for the Gmail helpers: auto-populating the From header with a display name and fixing an issue with reply-all to one's own message. The implementation is comprehensive and includes new tests. My review focuses on improving security and maintainability. I've identified a potential security vulnerability related to unsanitized error messages being printed to the terminal, which could lead to escape sequence injection. I've also suggested refactoring the error handling for new API calls to be more robust by using structured errors instead of string matching, which improves maintainability.
a12d6be to
c0b9695
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces two significant and valuable features for the Gmail helpers: auto-populating the From header with a display name, and fixing reply-all behavior for self-sent messages. The implementation is well-structured, introducing new functions with clear responsibilities and comprehensive unit tests. The graceful degradation for API failures is also a nice touch for user experience. I've identified one high-severity issue related to error handling that should be addressed to ensure correct error reporting.
Fetch the user's send-as identities via /users/me/settings/sendAs to set the From header with a display name in all mail helpers, matching Gmail web client behavior. The gmail.modify scope already covers this endpoint. Three resolution cases: - No --from: use the default send-as identity (display name + email) - --from with bare email: enrich from send-as list if the alias exists - --from with display name: use as-is, skip the API call For Workspace accounts where the primary address inherits its display name from the organization directory (sendAs returns empty displayName), falls back to the People API to fetch the profile name. This requires the userinfo.profile scope, which is now included in the identity scopes that auth login always requests. Degrades gracefully with a tip if the scope hasn't been granted yet. Introduces build_api_error, a shared helper that parses Google API JSON error responses (extracting message, reason, and enable URL), matching the executor's handle_error_response pattern. Used by all four Gmail API functions. All error messages printed to stderr are sanitized via sanitize_for_terminal. In +send, auth uses the discovery doc scopes rather than hardcoding gmail.modify, preserving compatibility with narrower send-only OAuth setups. In reply-all, the profile endpoint is always called for self-email dedup since the primary address may differ from the send-as alias.
When replying-all to a message you sent, the original sender (you) was excluded from To, leaving it empty and producing an error. Gmail web handles this by using the original To recipients as reply targets. Detect self-reply by checking if the original From matches the user's primary email or send-as alias, then swap the candidate logic: - Self-reply: To = original To, CC = original CC - Normal reply: To = Reply-To or From, CC = original To + CC
c0b9695 to
674c298
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces significant improvements to Gmail helpers, primarily by auto-populating the 'From' display name and correctly handling 'reply-all' to self-sent messages. The changes are well-structured, with new functions for resolving sender identities and fetching profile display names. Comprehensive unit tests have been added for the new logic, ensuring correctness and maintainability. Error handling has also been refactored for consistency and includes proper sanitization of terminal output, adhering to best practices. Overall, the changes are a valuable addition, enhancing both functionality and robustness.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #530 +/- ##
==========================================
+ Coverage 68.10% 68.97% +0.87%
==========================================
Files 40 41 +1
Lines 17954 19168 +1214
==========================================
+ Hits 12227 13222 +995
- Misses 5727 5946 +219 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Description
Two changes to the Gmail helpers:
1. Auto-populate From header with display name from send-as settings
When sending email without
--from, the CLI now fetches the user's send-asidentities (
/users/me/settings/sendAs) and sets the From header with thedisplay name, matching Gmail web client behavior. Previously, no From header
was set and Gmail's API filled it in with a bare email address.
Also enriches bare
--fromemails: if you pass--from alias@work.comandthat alias has a display name configured in Gmail, the From header includes it
automatically.
Three cases:
--from→ use the default send-as identity (display name + email)--fromwith bare email → look up in send-as list, enrich if found--fromwith display name already → use as-is, skip the API callWorkspace accounts: For accounts where the primary address inherits its
display name from the organization directory (sendAs returns empty
displayName), falls back to the People API (people/me) to fetch theprofile name. This requires the
userinfo.profilescope, which is nowincluded in the identity scopes that
auth loginalways requests. Degradesgracefully with a tip if the scope hasn't been granted yet.
Scopes:
gmail.modifyalready covers thesendAs.listendpoint, so noadditional OAuth scope is needed for the primary feature. In
+send, authuses the discovery doc scopes rather than hardcoding
gmail.modify,preserving compatibility with narrower send-only OAuth setups (e.g.
gmail.send). Theauth loginflow now includesuserinfo.profilealongsidethe existing
openidanduserinfo.emailidentity scopes (non-sensitive).2. Fix reply-all to own message
When replying-all to a message you sent, the original sender (you) was
excluded from To, leaving it empty and producing an error. Gmail web handles
this by using the original To recipients as reply targets instead. The fix
detects self-reply by checking if the original From matches the user's primary
email or send-as alias, then swaps the candidate logic accordingly.
Gmail web also ignores Reply-To on self-sent messages — we match that behavior.
This also correctly handles the case where the primary email differs from the
default send-as alias — both are excluded from recipients to prevent CCing
yourself.
Other notes
build_api_error: new shared helper that parses Google API JSON errorresponses (extracting message, reason, and enable URL), matching the
executor's
handle_error_responsepattern. Used by all four Gmail APIfunctions (
fetch_message_metadata,fetch_send_as_identities,fetch_profile_display_name,fetch_user_email). All error messagesprinted to stderr are sanitized via
sanitize_for_terminal.resolve_senderis a new shared function used by all four mail helpersparse_send_as_response,resolve_sender_from_identities,build_api_error,and
parse_profile_display_nameare pure/sync functions with comprehensiveunit tests
fetch_user_emailin reply.rs is retained for reply-all self-dedup (theprimary email may differ from the send-as alias)
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.