fix(mailgun): preserve duplicate custom headers - #147
Open
faisalahammad wants to merge 1 commit into
Open
Conversation
When a wp_mail() call passes two or more headers with the same name (for example several X-Mailgun-Tag lines for Mailgun tag routing), only the last value reached the Mailgun API before this change. RFC 5322 section 3.6 permits repeated optional-field headers and Mailgun's API documents h:X-Mailgun-Tag as supporting an array of strings. - PostmanMailgunMailEngine::addHeader third argument was an unused $deprecated flag. Rename to $append=false and use it: when the loop reports $append=true and an h:<name> key is already set, accumulate the new value into an array instead of overwriting. The first occurrence still assigns a scalar, so single-value use is byte-identical to before. - PostmanMailGun\Handler::get_headers enters the multipart branch whenever any content value is an array, not only when an attachment is present. This sends duplicate header tags as repeated form fields (which Mailgun accepts) instead of as bracketed PHP query string keys via http_build_query. Fixes wpexpertsio#74
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
Preserves multiple headers with the same key when sending through the Mailgun transport. RFC 5322 section 3.6 permits repeated optional-field headers and Mailgun documents
h:X-Mailgun-Tagas accepting an array of strings, but PostmanMailgunMailEngine was flat-assigning$mailgunMessage["h:" . $name]on every iteration so only the last value survived.Fixes #74
Changes
Postman/Postman-Mail/PostmanMailgunMailEngine.phpBefore:
After:
Why: the third arg was a dead
$deprecatedplaceholder. Rename it to$append=false, and when the header loop at line 197 sets it totrueand the same key is already present, append instead of overwrite. The first occurrence still hits the else branch, so single-value behaviour is byte-identical.Postman/Postman-Mail/Services/MailGun/Handler.phpBefore: the multipart branch only activated when
attachmentwas set.After: also activates when any content value is an array.
Why: when headers are accumulated as arrays,
wp_remote_postbody serialisation would have producedh:X-Mailgun-Tag[0]and[1]query keys, which Mailgun would have parsed as literal header names instead of repeated tags. Routing duplicate header tags through the existing multipart emitter keeps the wire shape Mailgun expects.Repro
Before: Mailgun dashboard log shows one tag. After: both tags appear.
Testing
Test 1: duplicate tags delivered
Result: both
test-category-accountandtest-account-reset-passwordare listed as tags. ✓Test 2: single tag still works
X-Mailgun-Tag: single-tag.Result: one tag. ✓ (No regression for single-value behaviour.)
Test 3: attachment still works
Result: byte-identical to before. ✓ (No regression in the multipart path.)
Notes