Skip to content

improvement(reply-gmail): added reply to gmail - #1809

Merged
aadamgough merged 3 commits into
stagingfrom
improvement/gmail
Nov 5, 2025
Merged

improvement(reply-gmail): added reply to gmail#1809
aadamgough merged 3 commits into
stagingfrom
improvement/gmail

Conversation

@aadamgough

Copy link
Copy Markdown
Contributor

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

  • New feature

Testing

Tested on own email accts

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercelBot commented Nov 5, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
ProjectDeploymentPreviewCommentsUpdated (UTC)
docsSkippedSkippedNov 5, 2025 3:41am

@aadamgoughaadamgough changed the title added reply to thread/messageimprovement(reply-gmail): added reply to gmailNov 5, 2025

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown
Contributor

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 threadId and replyToMessageId parameters 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.ts and apps/sim/app/api/tools/gmail/send/route.ts for potential refactoring to reduce code duplication

Important Files Changed

File Analysis

FilenameScoreOverview
apps/sim/app/api/tools/gmail/draft/route.ts4/5Added 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.ts4/5Added 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.ts4/5Added 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
Loading

8 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment threadapps/sim/app/api/tools/gmail/draft/route.ts Outdated
@aadamgough
aadamgough merged commit b0fa3e8 into stagingNov 5, 2025
9 checks passed
@aadamgough
aadamgough deleted the improvement/gmail branch November 5, 2025 04:23
waleedlatif1 pushed a commit that referenced this pull request Nov 12, 2025
* added reply to thread/message
* cleanup, extract header helper for threaded replies
* more helpers
@waleedlatif1waleedlatif1 mentioned this pull request Nov 12, 2025
10 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@aadamgough