fix: handle non-x custom headers in MS Graph transport#6590
Open
gharlan wants to merge 1 commit into
Open
Conversation
The Graph API rejects the whole sendMail request if a custom header name does not start with "x-". Only pass x-prefixed headers through to internetMessageHeaders, map List-Unsubscribe to the MAPI property PidTagListUnsubscribe (0x1045) via singleValueExtendedProperties, and drop all other headers (e.g. Auto-Submitted, which Exchange strips even from raw MIME) instead of failing the send.
Member
Author
|
@davidspenner can you maybe test it? |
|
@gharlan I just tested it and can confirm that it works |
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.
Fixes #6588
The Graph API only accepts custom headers whose name starts with
x-/X-ininternetMessageHeaders— any other header (e.g.Auto-Submitted,List-Unsubscribeas set by newsletter addons) makes the wholesendMailrequest fail withInvalidInternetMessageHeader, so no mail is sent at all.This PR makes the MS Graph transport translate custom headers instead of passing them through blindly:
x-prefix (case-insensitive, checked on the header name) are passed tointernetMessageHeadersas before.List-Unsubscribeis mapped to the MAPI propertyPidTagListUnsubscribe(String 0x1045) viasingleValueExtendedProperties, with the raw (non-MIME-encoded) value, since MAPI properties expect plain strings.Compared to the suggestion in the issue, this handles all non-x headers generically (e.g.
Precedence,List-ID) instead of special-casing two of them, and checks the prefix on the header name rather than the value.Auto-Submittedcannot be transmitted at all: Exchange strips it even from raw MIME submissions (msgraph-sdk-dotnet#2209, Microsoft Q&A). Callers who want to suppress auto-replies from Exchange recipients can setX-Auto-Response-Suppress: Allinstead.List-Unsubscribe-Post(RFC 8058 one-click) has no MAPI mapping either — full bulk-sender deliverability requirements can't be met via the Graph transport.Testing note: I have no M365 tenant at hand — it would be great if someone with a Graph setup (e.g. the issue author) could verify that Exchange actually emits the
List-Unsubscribeheader on outbound mails sent this way.