Header ListLoad(Stream, Cancellation Token) Method
Load a HeaderList from the specified stream.
Definition
Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
The parsed list of headers.
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public static HeaderList Load(
Stream stream,
CancellationToken cancellationToken = default
)Parameters
- stream Stream
- The stream.
- cancellationToken CancellationToken (Optional)
- The cancellation token.
Return Value
HeaderListThe parsed list of headers.
Remarks
Loads a HeaderList from the given stream, using the
default ParserOptions.
Example
C#
public static string GetSubject (Stream stream)
{
// Only load the headers rather than the entire message.
var headers = HeaderList.Load (stream);
var index = headers.IndexOf (HeaderId.Subject);
if (index == -1)
return string.Empty;
var subject = headers[index];
// Some mail clients incorrectly include raw 8-bit text in headers instead of
// encoding the text using the rfc2047 encoding scheme. By default, MimeKit decodes
// any undeclared 8-bit text as UTF-8 (falling back to ParserOptions.CharsetEncoding).
// If the charset is known, it can be passed to GetValue() to decode the header properly.
return subject.GetValue ("iso-8859-1");
}
Exceptions
| ArgumentNullException | stream is . |
| OperationCanceledException | The operation was canceled via the cancellation token. |
| FormatException | There was an error parsing the entity. |
| IOException | An I/O error occurred. |