HeaderListReplace(String, Encoding, String) Method

Replace all headers with identical field names with the single specified header.

Definition

Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public void Replace(
	string field,
	Encoding encoding,
	string value
)

Parameters

field  String
The name of the header field.
encoding  Encoding
The character encoding to use for the value.
value  String
The header value.

Remarks

Replaces all headers with identical field names with the single specified header.

If no headers with the specified field name exist, it is simply added.

Example

C#
                    public static void SetLatin1Subject (MimeMessage message)
{
    var index = message.Headers.IndexOf (HeaderId.Subject);
    Header subject;

    if (index == -1) {
        subject = new Header (HeaderId.Subject, string.Empty);
        message.Headers.Add (subject);
    } else {
        subject = message.Headers[index];
    }

    // By default, MimeKit encodes non-ASCII header values using UTF-8. Some legacy mail
    // clients may expect a specific charset, which can be specified via SetValue().
    // The value will be serialized as: Subject: =?iso-8859-1?b?Q2Fm6Q==?= au lait
    subject.SetValue ("iso-8859-1", "Café au lait");

    // HeaderList.Replace() and Add() also have overloads that take an Encoding.
    message.Headers.Replace (HeaderId.Comments, Encoding.UTF8, "Ça va?");
}
                  

Exceptions

ArgumentNullException

field is .

-or-

encoding is .

-or-

value is .

See Also