Switch from resent headers to rewriting From for DMARC compliance#97
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates Mailist’s email relay pipeline to forward messages in a more DMARC-compliant way by reconstructing outgoing messages (notably rewriting From to the configured sender and using Reply-To for the original sender), replacing the prior Resent-header-based approach.
Changes:
- Replace Resent-header forwarding with a single
PrepareForward()flow that rebuilds selected headers and rewritesFromfor DMARC compliance. - Update relay job logic to apply recipient override by mutating
To/Ccon the prepared forwarded message. - Update SMTP delivery to send with an explicit envelope sender/recipient (decoupling SMTP RCPT TO from message
To/Ccheaders).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| server/Mailist/EmailRelay/MimeMessageCreationService.cs | Removes Resent-based preparation and introduces PrepareForward() that rebuilds headers and rewrites From/Reply-To. |
| server/Mailist/EmailRelay/EmailRelayJobController.cs | Switches to the new forward preparation and applies OverrideRecipient by clearing/modifying To/Cc. |
| server/Mailist/EmailDelivery/EmailDeliveryJobController.cs | Sends via SMTP using explicit envelope sender/recipient to avoid relying on message header recipients. |
| server/Mailist.Tests/MimeMessageCreationServiceTests.cs | Adjusts the test to provide serialized headers and calls the new PrepareForward() API. |
Comments suppressed due to low confidence (1)
server/Mailist.Tests/MimeMessageCreationServiceTests.cs:66
- This test still only asserts the resolved display name. Since
PrepareForward()now rewrites header fields for DMARC compliance, it would be useful to also assert key behaviors (e.g.,Fromaddress is the configured sender address,Reply-Tois preserved/falls back as intended, andTo/Ccare copied from the original headers).
InboxEmail inboxEmail = new(
uniqueId: 1,
subject: "Test",
from: "support@example.com", // Armin Adendorf in demo.church.tools
sender: null,
replyTo: null,
to: "test@example.org",
receiver: "test@example.org",
header: header,
body: body);
var mimeMessage = await emailRelay.PrepareForward(inboxEmail, TestContext.Current.CancellationToken);
if (mimeMessage.From[0] is MailboxAddress from)
{
Assert.Equal("Armin Adendorf", from.Name);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Instead of sending original messages with resent headers, we reconstruct only a few headers (
Date,Subject,To,Cc,ReplyTo), namely notFromwhich is rewritten to comply even with the strictest DMARC policies.