-
Notifications
You must be signed in to change notification settings - Fork 3.1k
improvement(reply-gmail): added reply to gmail #1809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Greptile Summary
This PR adds email threading and reply functionality to Gmail operations, mirroring existing Outlook capabilities. The implementation adds support for replying to messages within email threads by:
- Adding
threadIdandreplyToMessageIdparameters to send/draft operations - Fetching original message headers (Message-ID, References, Subject) from Gmail API when replying
- Including proper RFC 5322 threading headers (In-Reply-To, References) in outgoing messages
- Making subject optional for replies (uses original subject as fallback)
- Enhancing read operations to include recipient (
to) field and message IDs in summaries
The changes are well-structured with consistent implementation across both draft and send operations, proper error handling (continues without threading headers if fetching fails), and maintains backwards compatibility.
Confidence Score: 4/5
- This PR is safe to merge with minimal risk - the implementation is solid with proper error handling and backwards compatibility
- The implementation correctly handles email threading with proper RFC headers, includes graceful error handling, and maintains API compatibility. Score is 4 (not 5) due to minor code duplication between draft and send routes that could be refactored into a shared utility function
- No critical issues, but consider reviewing
apps/sim/app/api/tools/gmail/draft/route.tsandapps/sim/app/api/tools/gmail/send/route.tsfor potential refactoring to reduce code duplication
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| apps/sim/app/api/tools/gmail/draft/route.ts | 4/5 | Added email threading support by fetching original message headers (Message-ID, References, Subject) when replyToMessageId is provided, and including them in draft creation with proper RFC threading headers |
| apps/sim/app/api/tools/gmail/send/route.ts | 4/5 | Added email threading support identical to draft route - fetches original message headers and includes In-Reply-To and References headers for proper email threading |
| apps/sim/tools/gmail/utils.ts | 4/5 | Added to field to message processing, enhanced message summaries with ID and threadId fields, and added In-Reply-To/References headers support to buildMimeMessage for proper email threading |
Sequence Diagram
sequenceDiagram
participant User
participant GmailTool as Gmail Send/Draft Tool
participant APIRoute as API Route (send/draft)
participant Gmail as Gmail API
User->>GmailTool: Send/Draft email with replyToMessageId
GmailTool->>APIRoute: POST with to, body, threadId, replyToMessageId
alt replyToMessageId provided
APIRoute->>Gmail: GET /messages/{replyToMessageId}?format=metadata
Gmail-->>APIRoute: Return Message-ID, References, Subject headers
APIRoute->>APIRoute: Extract originalMessageId, originalReferences, originalSubject
end
alt Has attachments
APIRoute->>APIRoute: Build MIME with buildMimeMessage()
APIRoute->>APIRoute: Add In-Reply-To: originalMessageId
APIRoute->>APIRoute: Add References: originalReferences + originalMessageId
else No attachments
APIRoute->>APIRoute: Build simple email headers
APIRoute->>APIRoute: Add In-Reply-To: originalMessageId
APIRoute->>APIRoute: Add References: originalReferences + originalMessageId
end
APIRoute->>APIRoute: Encode as base64url
APIRoute->>APIRoute: Add threadId to request if provided
APIRoute->>Gmail: POST /messages/send or /drafts with raw message + threadId
Gmail-->>APIRoute: Return message/draft with id and threadId
APIRoute-->>User: Success response with metadata
8 files reviewed, 1 comment
* added reply to thread/message * cleanup, extract header helper for threaded replies * more helpers
Summary
Adding threading and message replies to gmail, as we have in outlook. Outlook has its own endpoint, but gmail does not, it uses
Type of Change
Testing
Tested on own email accts
Checklist