-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: add In-Reply-To and References headers for Outlook reply threading #1246
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a40eb8d
fix: add In-Reply-To and References headers for Outlook reply threading
elie222 645b789
clean up
elie222 c0b0aa4
refactor: shared RFC 5322 threading headers for Gmail and Outlook
elie222 19c22fd
fix: use createReply pattern for Outlook email threading
elie222 53a13f1
Merge branch 'main' into fix/outlook-reply-threading
elie222 b141df2
fix: address PR review comments
elie222 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { describe, it, expect } from "vitest"; | ||
| import { buildThreadingHeaders } from "./threading"; | ||
|
|
||
| describe("buildThreadingHeaders", () => { | ||
| it("returns empty strings when headerMessageId is empty", () => { | ||
| const result = buildThreadingHeaders({ headerMessageId: "" }); | ||
| expect(result).toEqual({ inReplyTo: "", references: "" }); | ||
| }); | ||
|
|
||
| it("returns empty strings when headerMessageId is falsy", () => { | ||
| const result = buildThreadingHeaders({ | ||
| headerMessageId: undefined as unknown as string, | ||
| }); | ||
| expect(result).toEqual({ inReplyTo: "", references: "" }); | ||
| }); | ||
|
|
||
| it("uses headerMessageId for both fields when no references provided", () => { | ||
| const messageId = "<abc123@example.com>"; | ||
| const result = buildThreadingHeaders({ headerMessageId: messageId }); | ||
|
|
||
| expect(result).toEqual({ | ||
| inReplyTo: messageId, | ||
| references: messageId, | ||
| }); | ||
| }); | ||
|
|
||
| it("appends headerMessageId to existing references (RFC 5322)", () => { | ||
| const messageId = "<msg3@example.com>"; | ||
| const existingRefs = "<msg1@example.com> <msg2@example.com>"; | ||
|
|
||
| const result = buildThreadingHeaders({ | ||
| headerMessageId: messageId, | ||
| references: existingRefs, | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| inReplyTo: messageId, | ||
| references: "<msg1@example.com> <msg2@example.com> <msg3@example.com>", | ||
| }); | ||
| }); | ||
|
|
||
| it("handles references with trailing whitespace", () => { | ||
| const messageId = "<msg2@example.com>"; | ||
| const existingRefs = "<msg1@example.com> "; // trailing spaces | ||
|
|
||
| const result = buildThreadingHeaders({ | ||
| headerMessageId: messageId, | ||
| references: existingRefs, | ||
| }); | ||
|
|
||
| // .trim() should clean up the result | ||
| expect(result.references).toBe( | ||
| "<msg1@example.com> <msg2@example.com>".trim(), | ||
| ); | ||
| }); | ||
|
|
||
| it("handles empty string references", () => { | ||
| const messageId = "<abc@example.com>"; | ||
| const result = buildThreadingHeaders({ | ||
| headerMessageId: messageId, | ||
| references: "", | ||
| }); | ||
|
|
||
| // Empty string is falsy, so should use headerMessageId only | ||
| expect(result).toEqual({ | ||
| inReplyTo: messageId, | ||
| references: messageId, | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * Build RFC 5322 compliant email threading headers. | ||
| * References = parent's References + parent's Message-ID | ||
| * https://datatracker.ietf.org/doc/html/rfc5322#appendix-A.2 | ||
| */ | ||
| export function buildThreadingHeaders(options: { | ||
| headerMessageId: string; | ||
| references?: string; | ||
| }): { inReplyTo: string; references: string } { | ||
| if (!options.headerMessageId) { | ||
| return { inReplyTo: "", references: "" }; | ||
| } | ||
|
|
||
| return { | ||
| inReplyTo: options.headerMessageId, | ||
| references: options.references | ||
| ? `${options.references} ${options.headerMessageId}`.trim() | ||
| : options.headerMessageId, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: elie222/inbox-zero
Length of output: 3265
🏁 Script executed:
Repository: elie222/inbox-zero
Length of output: 5015
🏁 Script executed:
Repository: elie222/inbox-zero
Length of output: 2117
🏁 Script executed:
Repository: elie222/inbox-zero
Length of output: 1735
🏁 Script executed:
Repository: elie222/inbox-zero
Length of output: 3288
🏁 Script executed:
Repository: elie222/inbox-zero
Length of output: 1424
🏁 Script executed:
Repository: elie222/inbox-zero
Length of output: 2104
🏁 Script executed:
Repository: elie222/inbox-zero
Length of output: 1909
🏁 Script executed:
Repository: elie222/inbox-zero
Length of output: 831
🏁 Script executed:
Repository: elie222/inbox-zero
Length of output: 2342
🏁 Script executed:
Repository: elie222/inbox-zero
Length of output: 1414
🏁 Script executed:
Repository: elie222/inbox-zero
Length of output: 227
🏁 Script executed:
Repository: elie222/inbox-zero
Length of output: 2061
🏁 Script executed:
Repository: elie222/inbox-zero
Length of output: 1712
🏁 Script executed:
Repository: elie222/inbox-zero
Length of output: 1063
Address the interface contract violation for Outlook's empty messageId/threadId returns.
The Outlook
sendEmailWithHtmlfunction returns empty string formessageIdandthreadIdbecause Microsoft Graph's sendMail endpoint returns 202 with no body. This violates the interface contract that specifies both as non-empty strings. While the returned values aren't currently used for persistence, this inconsistency with Gmail's implementation could cause silent failures in future code that depends on these IDs.Consider either:
messageIdandthreadIdoptional in the return type to reflect Outlook's limitationsThere 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.
Addressed - returning empty
id(Graph limitation) while preservingconversationId/threadId. The interface allows empty strings which is acceptable for Outlook.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.
Commit b141df2 addressed this comment by improving the handling of Outlook's empty ID limitation. The code now attempts to preserve
conversationIdby usingbody.replyToEmail?.threadIdinstead of returningundefined, and fixes bugs where invalid draft IDs were being returned after send operations. While the interface contract still allows empty strings (rather than making fields optional as suggested), the implementation is now more correct and better documented with explanatory comments about Graph API limitations.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.