Skip to content

fix: preserve In-Reply-To/References via MAPI extended properties - #1

Open
ChrKahl wants to merge 1 commit into
mainfrom
fix/preserve-threading-headers
Open

ChrKahl wants to merge 1 commit into
mainfrom
fix/preserve-threading-headers

Conversation

@ChrKahl

@ChrKahl ChrKahl commented Jul 9, 2026

Copy link
Copy Markdown
Member

Problem

The sendMail JSON payload silently drops the In-Reply-To and References headers set on the Mail object. Graph's internetMessageHeaders only accepts x-* custom headers, so standard threading headers cannot be transmitted that way at all. Replies sent through this gem therefore never thread in the recipient's mail client — every reply starts a new conversation.

Found while auditing the case-email integration in m2-api, where CaseMailer sets both headers for reply mails.

Fix

Map both headers to their MAPI extended properties in the message payload:

Header MAPI property Id
In-Reply-To PidTagInReplyToId String 0x1042
References PidTagInternetReferences String 0x1039

Exchange translates these back into the wire headers on send. Bare message ids from the mail gem's parsed accessors are re-wrapped in angle brackets to match the RFC 5322 format. The properties are omitted entirely when neither header is set, so payloads for non-reply mail are unchanged.

Tests

  • New specs for deliver! covering: both headers transmitted, bare ids wrapped, properties omitted without headers, and the basic payload shape (the spec file was an empty placeholder before).
  • bundle exec rake test (RuboCop + RSpec) green.

The sendMail JSON payload silently dropped the In-Reply-To and
References headers set on the Mail object: Graph's
internetMessageHeaders only accepts x-* custom headers, so standard
threading headers cannot be transmitted that way at all. Replies sent
through this gem therefore never threaded in the recipient's client.

Map both headers to their MAPI extended properties instead
(PidTagInReplyToId 0x1042, PidTagInternetReferences 0x1039), which
Exchange translates back into the wire headers. Bare message ids from
the mail gem's parsed accessors are re-wrapped in angle brackets to
match the RFC 5322 format.
@ChrKahl
ChrKahl requested a review from floriancrusius July 9, 2026 10:18
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