Header Class

A class representing a Message or MIME header.

Definition

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

Remarks

Represents a single header field and value pair.

Example

C#
                    public static void PrintHeaders (MimeMessage message)
{
    foreach (var header in message.Headers) {
        // Header.Field is the name of the header exactly as it appeared in the message,
        // while Header.Id is a HeaderId enum value that can be used for fast comparisons.
        // Headers that MimeKit does not know about have an Id of HeaderId.Unknown.
        if (header.Id == HeaderId.Unknown)
            Console.Write ("(custom) ");

        // Header.Value is the unfolded and decoded value of the header.
        Console.WriteLine ("{0}: {1}", header.Field, header.Value);
    }

    // Headers can also be enumerated by index which can be useful for headers that may
    // appear multiple times, such as the Received headers.
    for (int i = 0; i < message.Headers.Count; i++) {
        var header = message.Headers[i];

        if (header.Id == HeaderId.Received)
            Console.WriteLine ("Hop #{0}: {1}", i + 1, header.Value);
    }
}
                  

Constructors

Header(HeaderId, String) Initialize a new instance of the Header class.
Header(String, String) Initialize a new instance of the Header class.
Header(Encoding, HeaderId, String) Initialize a new instance of the Header class.
Header(Encoding, String, String) Initialize a new instance of the Header class.
Header(String, HeaderId, String) Initialize a new instance of the Header class.
Header(String, String, String) Initialize a new instance of the Header class.
Header(ParserOptions, HeaderId, String, Byte) Initialize a new instance of the Header class.
Header(ParserOptions, Byte, Byte, Boolean) Initialize a new instance of the Header class.
Header(ParserOptions, HeaderId, String, Byte, Byte) Initialize a new instance of the Header class.
Header(ParserOptions, Byte, Int32, Byte, Boolean) Initialize a new instance of the Header class.

Properties

Field Get the name of the header field.
Id Get the header identifier.
Offset Get the stream offset of the beginning of the header.
RawField Get the raw field name of the header.
RawValue Get the raw value of the header.
Value Get or sets the header value.

Methods

Clone Clone the header.
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)
FormatRawValue Format the raw value of the header to conform with the specified formatting options.
GetHashCode Serves as the default hash function.
(Inherited from Object)
GetType Gets the Type of the current instance.
(Inherited from Object)
GetValue(Encoding) Get the header value using the specified character encoding.
GetValue(String) Get the header value using the specified charset.
MemberwiseClone Creates a shallow copy of the current Object.
(Inherited from Object)
SetRawValue Set the raw header value.
SetValue(Encoding, String) Set the header value using the specified character encoding.
SetValue(String, String) Set the header value using the specified charset.
SetValue(FormatOptions, String, String) Set the header value using the specified formatting options and charset.
SetValue(FormatOptions, Encoding, String) Ses the header value using the specified formatting options and character encoding.
ToString Return a string representation of the header.
(Overrides ObjectToString)
TryParse(Byte, Header) Try to parse the given input buffer into a new Header instance.
TryParse(String, Header) Try to parse the given text into a new Header instance.
TryParse(Byte, Int32, Header) Try to parse the given input buffer into a new Header instance.
TryParse(ParserOptions, Byte, Header) Try to parse the given input buffer into a new Header instance.
TryParse(ParserOptions, String, Header) Try to parse the given text into a new Header instance.
TryParse(Byte, Int32, Int32, Header) Try to parse the given input buffer into a new Header instance.
TryParse(ParserOptions, Byte, Int32, Header) Try to parse the given input buffer into a new Header instance.
TryParse(ParserOptions, Byte, Int32, Int32, Header) Try to parse the given input buffer into a new Header instance.
Unfold Unfold the specified header value.

See Also

Reference