MimeAnonymizer Class

A tool for anonymizing a message or MIME entity.

Definition

Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public class MimeAnonymizer
Inheritance
Object    MimeAnonymizer

Remarks

Allows you to anonymize a MimeMessage or MimeEntity.

Example

C#
                    public static void AnonymizeMessage (string inputFileName, string outputFileName)
{
    // The MimeAnonymizer is useful for sharing a message that triggers a bug (for example,
    // in a bug report) without revealing any personal information. Letters and digits are
    // replaced with 'x' while punctuation, whitespace, line lengths and the MIME structure
    // of the message are preserved so that the anonymized message is likely to reproduce
    // the same parser behavior as the original.
    var message = MimeMessage.Load (inputFileName);
    var anonymizer = new MimeAnonymizer ();

    using (var stream = File.Create (outputFileName))
        anonymizer.Anonymize (message, stream);
}

// Given the following message 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"
//
// --=-boundary-1
// Content-Type: text/plain; charset=utf-8
// Content-Transfer-Encoding: 7bit
//
// Hey Chandler,
//
// Monica and I are going to play paintball on Saturday. You in?
//
// -- Joey
//
// --=-boundary-1
// Content-Type: application/pdf; name="map.pdf"
// Content-Disposition: attachment; filename="map.pdf"
// Content-Transfer-Encoding: base64
//
// JVBERi0xLjQKJcfsj6IKNSAwIG9iago8PC9MZW5ndGggNiAwIFI+PgpzdHJlYW0K
//
// --=-boundary-1--
//
// 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: xxxxxxxxx xxxx xxxxxxx?
// 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"
//
// --=-boundary-1
// Content-Type: text/plain; charset=utf-8
// Content-Transfer-Encoding: 7bit
//
// xxx xxxxxxxxx
//
// xxxxxx xxx x xxx xxxxx xx xxxx xxxxxxxxx xx xxxxxxxxx xxx xxx
//
// xx xxxx
//
// --=-boundary-1
// Content-Type: application/pdf; name="xxxxxxx"
// Content-Disposition: attachment; filename="xxxxxxx"
// Content-Transfer-Encoding: base64
//
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//
// --=-boundary-1--
//
// Note: Dates, as well as structural values such as the MIME-Version, Content-Type,
// Content-Transfer-Encoding and boundary markers, are left as-is.
                  

Constructors

MimeAnonymizer Initialize a new instance of the MimeAnonymizer class.

Properties

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

Methods

Anonymize(MimeEntity, Stream) Anonymize a MimeEntity.
Anonymize(MimeMessage, Stream) Anonymize a MimeMessage.
Anonymize(FormatOptions, MimeEntity, Stream) Anonymize a MimeEntity.
Anonymize(FormatOptions, MimeMessage, Stream) Anonymize a MimeMessage.
Equals Determines whether the specified object is equal to the current object.
(Inherited from Object)
Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
GetHashCode Serves as the default hash function.
(Inherited from Object)
GetType Gets the Type of the current instance.
(Inherited from Object)
MemberwiseClone Creates a shallow copy of the current Object.
(Inherited from Object)
ToString Returns a string that represents the current object.
(Inherited from Object)

See Also

Reference