MimeAnonymizerPreserveHeaders Property

Get the set of headers that this anonymizer is configured to preserve.

Definition

Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public HashSet<string> PreserveHeaders { get; }

Property Value

HashSetString
The set of headers that the anonymizer is configured to preserve.

Remarks

Gets the set of headers that this anonymizer is configured to preserve.

Headers can be added or removed from this set in order to influence the output of the anonymizer.

  Note

This set of headers to preserve also applies to the status headers in the content of message/delivery-status parts as well.

Example

C#
                    public static byte[] AnonymizeMessagePreservingSubject (MimeMessage message)
{
    var anonymizer = new MimeAnonymizer ();

    // Headers that do not contain sensitive information (or that are needed to reproduce a
    // problem) can be excluded from anonymization. Header names are case-insensitive.
    anonymizer.PreserveHeaders.Add ("Subject");

    // Use Unix line endings so that the output is easy to paste into a bug report.
    var options = FormatOptions.Default.Clone ();
    options.NewLineFormat = NewLineFormat.Unix;

    using (var memory = new MemoryStream ()) {
        anonymizer.Anonymize (options, message, memory);

        return memory.ToArray ();
    }
}

// Given a message with the following headers as input:
//
// Received: from mail.friends.com (mail.friends.com [192.168.1.10])
//     by mx.example.com with ESMTPS id abc123
//     for <chandler@example.com>; Mon, 6 Apr 2026 10:15:32 -0400
// From: Joey Tribbiani <joey@friends.com>
// To: Chandler Bing <chandler@example.com>
// Subject: Paintball this weekend?
// Date: Mon, 6 Apr 2026 10:15:30 -0400
// Message-Id: <20260406141530.12345@friends.com>
// MIME-Version: 1.0
// Content-Type: multipart/mixed; boundary="=-boundary-1"
//
// The headers of the anonymized output will be:
//
// Received: from xxxx.xxxxxxx.xxx (xxxx.xxxxxxx.xxx [xxx.xxx.x.xx])
//     by xx.xxxxxxx.xxx with xxxxxx id xxxxxx
//     for <xxxxxxxx@xxxxxxx.xxx>; Mon, 6 Apr 2026 10:15:32 -0400
// From: xxxx xxxxxxxxx <xxxx@xxxxxxx.xxx>
// To: xxxxxxxx xxxx <xxxxxxxx@xxxxxxx.xxx>
// Subject: Paintball this weekend?
// Date: Mon, 6 Apr 2026 10:15:30 -0400
// Message-Id: <xxxxxxxxxxxxxx.xxxxx@xxxxxxx.xxx>
// MIME-Version: 1.0
// Content-Type: multipart/mixed; boundary="=-boundary-1"
                  

See Also