Header List Class
A list of Headers.
Definition
Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public sealed class HeaderList : IList<Header>,
ICollection<Header>, IEnumerable<Header>, IEnumerable- Inheritance
- Object HeaderList
- Implements
- ICollectionHeader, IEnumerableHeader, IListHeader, IEnumerable
Remarks
Represents a list of headers as found in a MimeMessage
or MimeEntity.
Example
C#
public static void ModifyHeaders (MimeMessage message)
{
// Add() appends a new header to the end of the list, even if a header with the same
// name already exists.
message.Headers.Add ("X-Mailer", "MyMailer v1.0");
message.Headers.Add (HeaderId.Keywords, "MimeKit, Examples");
// Replace() replaces the value of the first header with the given name, and removes
// any other headers with that name. If no header exists, a new header is appended.
message.Headers.Replace (HeaderId.Organization, "Central Perk");
// The indexer may also be used to get or set the value of the first header with the
// given name. Getting the value of a header that does not exist returns null.
message.Headers["X-Priority"] = "1";
string? mailer = message.Headers["X-Mailer"];
Console.WriteLine ("X-Mailer: {0}", mailer ?? "(none)");
// Remove() removes only the first header with the given name, while RemoveAll()
// removes every header with that name.
message.Headers.Remove ("X-Priority");
message.Headers.RemoveAll (HeaderId.Received);
// Insert() can be used to control where a header goes. Trace headers, for example,
// are meant to be prepended to the existing headers.
message.Headers.Insert (0, "X-Trace", "Scanned by MyVirusScanner");
}
Constructors
| HeaderList | Initialize a new instance of the HeaderList class. |
Properties
| Count | Get the number of headers in the list. |
| IsReadOnly | Get whether the header list is read only. |
| ItemHeaderId | Get or set the value of the first occurrence of a header with the specified field name. |
| ItemInt32 | Get or set the Header at the specified index. |
| ItemString | Get or set the value of the first occurrence of a header with the specified field name. |
Methods
| Add(Header) | Add the specified header. |
| Add(HeaderId, String) | Add a header with the specified field and value. |
| Add(String, String) | Add a header with the specified field and value. |
| Add(HeaderId, Encoding, String) | Add a header with the specified field and value. |
| Add(String, Encoding, String) | Add a header with the specified field and value. |
| Clear | Clear the header list. |
| Contains(Header) | Check if the HeaderList contains the specified header. |
| Contains(HeaderId) | Check if the HeaderList contains a header with the specified field name. |
| Contains(String) | Check if the HeaderList contains a header with the specified field name. |
| CopyTo | Copy all of the headers in the HeaderList to the specified array. |
| Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
| GetEnumerator | Get an enumerator for the list of headers. |
| GetHashCode | Serves as the default hash function. (Inherited from Object) |
| GetType | Gets the Type of the current instance. (Inherited from Object) |
| IndexOf(Header) | Get the index of the requested header, if it exists. |
| IndexOf(HeaderId) | Get the index of the requested header, if it exists. |
| IndexOf(String) | Get the index of the requested header, if it exists. |
| Insert(Int32, Header) | Insert the specified header at the given index. |
| Insert(Int32, HeaderId, String) | Insert a header with the specified field and value at the given index. |
| Insert(Int32, String, String) | Insert a header with the specified field and value at the given index. |
| Insert(Int32, HeaderId, Encoding, String) | Insert a header with the specified field and value at the given index. |
| Insert(Int32, String, Encoding, String) | Insert a header with the specified field and value at the given index. |
| LastIndexOf(HeaderId) | Get the last index of the requested header, if it exists. |
| LastIndexOf(String) | Get the last index of the requested header, if it exists. |
| Load(Stream, CancellationToken) | Load a HeaderList from the specified stream. |
| Load(String, CancellationToken) | Load a HeaderList from the specified file. |
| Load(ParserOptions, Stream, CancellationToken) | Load a HeaderList from the specified stream. |
| Load(ParserOptions, String, CancellationToken) | Load a HeaderList from the specified file. |
| LoadAsync(Stream, CancellationToken) | Asynchronously load a HeaderList from the specified stream. |
| LoadAsync(String, CancellationToken) | Asynchronously load a HeaderList from the specified file. |
| LoadAsync(ParserOptions, Stream, CancellationToken) | Asynchronously load a HeaderList from the specified stream. |
| LoadAsync(ParserOptions, String, CancellationToken) | Asynchronously load a HeaderList from the specified file. |
| Remove(Header) | Remove the specified header. |
| Remove(HeaderId) | Remove the first occurrence of the specified header field. |
| Remove(String) | Remove the first occurrence of the specified header field. |
| RemoveAll(HeaderId) | Remove all the headers matching the specified field name. |
| RemoveAll(String) | Remove all the headers matching the specified field name. |
| RemoveAt | Remove the header at the specified index. |
| Replace(Header) | Replace all headers with identical field names with the single specified header. |
| Replace(HeaderId, String) | Replace all headers with identical field names with the single specified header. |
| Replace(String, String) | Replace all headers with identical field names with the single specified header. |
| Replace(HeaderId, Encoding, String) | Replace all headers with identical field names with the single specified header. |
| Replace(String, Encoding, String) | Replace all headers with identical field names with the single specified header. |
| ToString | Returns a string that represents the current object. (Inherited from Object) |
| WriteTo(Stream, CancellationToken) | Write the HeaderList to the specified output stream. |
| WriteTo(FormatOptions, Stream, CancellationToken) | Write the HeaderList to the specified output stream. |
| WriteToAsync(Stream, CancellationToken) | Asynchronously write the HeaderList to the specified output stream. |
| WriteToAsync(FormatOptions, Stream, CancellationToken) | Asynchronously write the HeaderList to the specified output stream. |