Skip to content

Switch from resent headers to rewriting From for DMARC compliance#97

Merged
daniel-lerch merged 2 commits into
masterfrom
dmarc
Apr 1, 2026
Merged

Switch from resent headers to rewriting From for DMARC compliance#97
daniel-lerch merged 2 commits into
masterfrom
dmarc

Conversation

@daniel-lerch
Copy link
Copy Markdown
Owner

@daniel-lerch daniel-lerch commented Apr 1, 2026

Instead of sending original messages with resent headers, we reconstruct only a few headers (Date, Subject, To,Cc, ReplyTo), namely not From which is rewritten to comply even with the strictest DMARC policies.

@daniel-lerch daniel-lerch requested a review from Copilot April 1, 2026 19:38
@daniel-lerch daniel-lerch self-assigned this Apr 1, 2026
@daniel-lerch daniel-lerch added the enhancement New feature or request label Apr 1, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 rewrites From for DMARC compliance.
  • Update relay job logic to apply recipient override by mutating To/Cc on the prepared forwarded message.
  • Update SMTP delivery to send with an explicit envelope sender/recipient (decoupling SMTP RCPT TO from message To/Cc headers).

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., From address is the configured sender address, Reply-To is preserved/falls back as intended, and To/Cc are 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.

Comment thread server/Mailist/EmailRelay/MimeMessageCreationService.cs
Comment thread server/Mailist/EmailRelay/MimeMessageCreationService.cs Outdated
Comment thread server/Mailist/EmailRelay/MimeMessageCreationService.cs
Comment thread server/Mailist/EmailRelay/EmailRelayJobController.cs
@daniel-lerch daniel-lerch merged commit ec04779 into master Apr 1, 2026
3 checks passed
@daniel-lerch daniel-lerch deleted the dmarc branch April 1, 2026 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify distribution list types in a single DMARC compliant type

2 participants