Skip to content

Fixes email reply threading for Gmail and Office365#158

Open
RazvanMitrica wants to merge 2 commits into
masterfrom
fix-reply-threading
Open

Fixes email reply threading for Gmail and Office365#158
RazvanMitrica wants to merge 2 commits into
masterfrom
fix-reply-threading

Conversation

@RazvanMitrica

Copy link
Copy Markdown
Contributor

Problem
Workflow reply steps were not threading correctly:

  • Gmail: threadId was never passed to the Gmail send API, so replies always created a new thread.

  • Office365: createReply was called with the RFC internetMessageId instead of the Microsoft Graph message id, causing an immediate 404 on every reply attempt. Additionally, stored Graph ids were mutable and would become invalid once a message moved from Drafts to Sent Items.

Changes
Adds a params.replyTo object ({ emailMessageId, serviceThreadId/serviceMessageId, references }) as the preferred reply target for both providers. Existing flat params (inReplyTo, threadId) remain as fallbacks — no breaking changes.
Gmail: populates In-Reply-To, References, and threadId from replyTo.
Office365: routes createReply to replyTo.serviceMessageId (the Graph id). Adds Prefer: IdType="ImmutableId" to draft creation and reply draft calls so stored ids survive the Drafts → Sent Items move.
Adds options.returnMetadata to both providers: returns { email_message_id, service_message_id, service_thread_id } instead of a plain string, letting the Server store provider ids immediately without waiting for sent webhooks.

@cursor

cursor Bot commented May 28, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches outbound send/reply paths for both providers (thread ids, Graph createReply, and id stability); behavior is backward compatible but errors in reply targeting would affect production email workflows.

Overview
Fixes workflow reply threading for Gmail and Office365 by introducing a preferred params.replyTo object while keeping legacy inReplyTo, references, and threadId as fallbacks.

Gmail now maps replyTo into RFC In-Reply-To / References, passes replyTo.serviceThreadId (or legacy threadId) on send, and supports options.returnMetadata so callers get { email_message_id, service_message_id, service_thread_id } (including partial ids when post-send getMessage fails).

Office365 routes replies through replyTo.serviceMessageId for createReply (instead of treating RFC ids as Graph ids), tightens legacy inReplyTo so it is not used when replyTo is present, sends Prefer: IdType="ImmutableId" on draft create/reply PATCH so stored message ids survive Drafts → Sent Items, and mirrors the same returnMetadata callback shape on send and reply paths.

Reviewed by Cursor Bugbot for commit 905e707. Bugbot is set up for automated code reviews on this repo. Configure here.

@RazvanMitrica RazvanMitrica changed the title Fixes email reply threading for Gmail and Office365. #11897 #11898 Fixes email reply threading for Gmail and Office365 May 28, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit bc3c846. Configure here.

Comment thread lib/unimail-gmail.js
Sign up for free to 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