Repository navigation
fix(drafts): preserve Gmail thread when --reply-to receives a threadId - #14
Merged
Merged
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes Gmail reply threading when
--reply-toreceives a thread ID (or a message whoseMessage-Id/Referencesheaders use non-uppercase casing).Root causes fixed
createDraftandsendMessageonly calledusers.threads.getwhenusers.messages.get(replyToId)threw. Because a Gmail thread's ID equals its first message's ID, passing--reply-to <threadId>succeeded onmessages.getand replied to the stale root message instead of resolving the thread's latest message.Message-IDandReferenceswere matched with strict===instead of case-insensitivegetHeaderValue, silently droppingIn-Reply-ToandReferenceswhenever Gmail/MTAs returnedMessage-Idorreferences.messages[messages.length - 1]blindly, even if that entry had theDRAFTlabel.selectLatestReplyMessagenow prefers the latest non-draft message (falling back to the last message only if all entries are drafts).resolveReplyTargetandresolveReplyMetadatahelpers used by bothcreateDraftandsendMessage, and avoided duplicatingMessage-IDwhen already present inReferences.Testing
npm run check(biome check src/ --write --diagnostic-level=error && tsgo --noEmit): passednpm test(npm run build && node --test test/**/*.test.js): 16/16 passed, including new unit tests intest/reply-threading.test.jscovering:createDraft --reply-to <threadId>wherethreadId === rootMessageId(with trailingDRAFTmessage andMessage-Id/referencescasing)createDraft --reply-to <threadId>fallback when root message is missing (messages.getthrows)createDraft --reply-to <messageId>targeting a specific non-root messagesendMessage --reply-to <threadId>resolving the latest message and headersselectLatestReplyMessageskippingDRAFTmessagesCloses #4