Mime Reader Class
A MIME message and entity reader.
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 class MimeReader- Inheritance
- Object MimeReader
Remarks
MimeReader provides forward-only, read-only access to MIME data in a stream.
Example
C#
// MimeReader is a low-level, forward-only reader that reports the structure of a MIME
// stream via protected virtual callbacks rather than constructing a MimeMessage. This
// makes it ideal for scanning large messages without loading their content into memory.
class MimeStructureReader : MimeReader
{
readonly TextWriter output;
int depth;
public MimeStructureReader (Stream stream, TextWriter output) : base (stream, MimeFormat.Entity)
{
this.output = output;
}
void WriteLine (string format, params object[] args)
{
output.Write (new string (' ', depth * 2));
output.WriteLine (format, args);
}
protected override void OnHeaderRead (Header header, int beginLineNumber, CancellationToken cancellationToken)
{
if (header.Id == HeaderId.Subject)
WriteLine ("Subject: {0}", header.Value);
}
protected override void OnMultipartBegin (ContentType contentType, long beginOffset, int beginLineNumber, CancellationToken cancellationToken)
{
WriteLine ("{0} (line {1})", contentType.MimeType, beginLineNumber);
depth++;
}
protected override void OnMultipartEnd (ContentType contentType, long beginOffset, int beginLineNumber, long headersEndOffset, long endOffset, int lines, CancellationToken cancellationToken)
{
depth--;
}
protected override void OnMessagePartBegin (ContentType contentType, long beginOffset, int beginLineNumber, CancellationToken cancellationToken)
{
WriteLine ("{0} (line {1})", contentType.MimeType, beginLineNumber);
depth++;
}
protected override void OnMessagePartEnd (ContentType contentType, long beginOffset, int beginLineNumber, long headersEndOffset, long endOffset, int lines, CancellationToken cancellationToken)
{
depth--;
}
protected override void OnMimePartEnd (ContentType contentType, long beginOffset, int beginLineNumber, long headersEndOffset, long endOffset, int lines, CancellationToken cancellationToken)
{
// The offsets make it possible to locate (and later extract) the raw part
// within the original stream.
WriteLine ("{0} (line {1}, {2} bytes)", contentType.MimeType, beginLineNumber, endOffset - beginOffset);
}
}
public static void PrintMimeStructure (string fileName)
{
using (var stream = File.OpenRead (fileName)) {
var reader = new MimeStructureReader (stream, Console.Out);
// ReadMessage() parses the stream, invoking the callbacks along the way.
reader.ReadMessage ();
}
}
Constructors
| MimeReader(Stream, MimeFormat) | Initialize a new instance of the MimeReader class. |
| MimeReader(ParserOptions, Stream, MimeFormat) | Initialize a new instance of the MimeReader class. |
Properties
| ComplianceLogger | Get or set the logger to use for reporting MIME compliance violations. |
| ComplianceOptions | Get or set the options that control how MIME compliance violations are reported. |
| IsEndOfStream | Get a value indicating whether the parser has reached the end of the input stream. |
| Options | Get or set the parser options. |
| Position | Get the current position of the parser within the stream. |
Methods
| 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) |
| OnBodySeparator | Called when the body separator is encountered in the stream. |
| OnBodySeparatorAsync | Called when the body separator is encountered in the stream. |
| OnHeaderRead | Called when a message or MIME part header is read from the stream. |
| OnHeaderReadAsync | Called when a message or MIME part header is read from the stream. |
| OnHeadersBegin | Called when the beginning of a list of headers is encountered in the stream. |
| OnHeadersBeginAsync | Called when the beginning of a list of headers is encountered in the stream. |
| OnHeadersEnd | Called when the end of a list of headers is encountered in the stream. |
| OnHeadersEndAsync | Called when the end of a list of headers is encountered in the stream. |
| OnMboxMarkerBegin | Called when an Mbox marker is encountered in the stream. |
| OnMboxMarkerBeginAsync | Called when an Mbox marker is encountered in the stream. |
| OnMboxMarkerEnd | Called when the end of an Mbox marker is encountered in the stream. |
| OnMboxMarkerEndAsync | Called when the end of an Mbox marker is encountered in the stream. |
| OnMboxMarkerRead | Called when an Mbox marker is encountered in the stream. |
| OnMboxMarkerReadAsync | Called when an Mbox marker is encountered in the stream. |
| OnMessagePartBegin | Called when the beginning of a message part is encountered in the stream. |
| OnMessagePartBeginAsync | Called when the beginning of a message part is encountered in the stream. |
| OnMessagePartEnd | Called when the end of a message part is encountered in the stream. |
| OnMessagePartEndAsync | Called when the end of a message part is encountered in the stream. |
| OnMimeMessageBegin | Called when the beginning of a message is encountered in the stream. |
| OnMimeMessageBeginAsync | Called when the beginning of a message is encountered in the stream. |
| OnMimeMessageEnd | Called when the end of a message is encountered in the stream. |
| OnMimeMessageEndAsync | Called when the end of a message is encountered in the stream. |
| OnMimePartBegin | Called when the beginning of a MIME part is encountered in the stream. |
| OnMimePartBeginAsync | Called when the beginning of a MIME part is encountered in the stream. |
| OnMimePartContentBegin | Called when the beginning of a MIME part's content is encountered in the stream. |
| OnMimePartContentBeginAsync | Called when the beginning of a MIME part's content is encountered in the stream. |
| OnMimePartContentEnd | Called when the end of a MIME part's content is encountered in the stream. |
| OnMimePartContentEndAsync | Called when the end of a MIME part's content is encountered in the stream. |
| OnMimePartContentRead | Called when MIME part content is read from the stream. |
| OnMimePartContentReadAsync | Called when MIME part content is read from the stream. |
| OnMimePartEnd | Called when the end of a MIME part is encountered in the stream. |
| OnMimePartEndAsync | Called when the end of a MIME part is encountered in the stream. |
| OnMultipartBegin | Called when the beginning of a multipart is encountered in the stream. |
| OnMultipartBeginAsync | Called when the beginning of a multipart is encountered in the stream. |
| OnMultipartBoundaryBegin | Called when a multipart boundary is encountered in the stream. |
| OnMultipartBoundaryBeginAsync | Called when a multipart boundary is encountered in the stream. |
| OnMultipartBoundaryEnd | Called when a multipart boundary is encountered in the stream. |
| OnMultipartBoundaryEndAsync | Called when a multipart boundary is encountered in the stream. |
| OnMultipartBoundaryRead | Called when a multipart boundary is encountered in the stream. |
| OnMultipartBoundaryReadAsync | Called when a multipart boundary is encountered in the stream. |
| OnMultipartEnd | Called when the end of a multipart is encountered in the stream. |
| OnMultipartEndAsync | Called when the end of a multipart is encountered in the stream. |
| OnMultipartEndBoundaryBegin | Called when a multipart end boundary is encountered in the stream. |
| OnMultipartEndBoundaryBeginAsync | Called when a multipart end boundary is encountered in the stream. |
| OnMultipartEndBoundaryEnd | Called when a multipart end boundary is encountered in the stream. |
| OnMultipartEndBoundaryEndAsync | Called when a multipart end boundary is encountered in the stream. |
| OnMultipartEndBoundaryRead | Called when a multipart end boundary is encountered in the stream. |
| OnMultipartEndBoundaryReadAsync | Called when a multipart end boundary is encountered in the stream. |
| OnMultipartEpilogueBegin | Called when the beginning of the epilogue of a multipart is encountered in the stream. |
| OnMultipartEpilogueBeginAsync | Called when the beginning of the epilogue of a multipart is encountered in the stream. |
| OnMultipartEpilogueEnd | Called when the end of the epilogue of a multipart is encountered in the stream. |
| OnMultipartEpilogueEndAsync | Called when the end of the epilogue of a multipart is encountered in the stream. |
| OnMultipartEpilogueRead | Called when multipart epilogue text is read from the stream. |
| OnMultipartEpilogueReadAsync | Called when multipart epilogue text is read from the stream. |
| OnMultipartPreambleBegin | Called when the beginning of the preamble of a multipart is encountered in the stream. |
| OnMultipartPreambleBeginAsync | Called when the beginning of the preamble of a multipart is encountered in the stream. |
| OnMultipartPreambleEnd | Called when the end of the preamble of a multipart is encountered in the stream. |
| OnMultipartPreambleEndAsync | Called when the end of the preamble of a multipart is encountered in the stream. |
| OnMultipartPreambleRead | Called when multipart preamble text is read from the stream. |
| OnMultipartPreambleReadAsync | Called when multipart preamble text is read from the stream. |
| ReadEntity | Read an entity from the stream. |
| ReadEntityAsync | Asynchronously read an entity from the stream. |
| ReadHeaders | Read a block of headers from the stream. |
| ReadHeadersAsync | Asynchronously read a block of headers from the stream. |
| ReadMessage | Read a message from the stream. |
| ReadMessageAsync | Asynchronously read a message from the stream. |
| SetStream | Set the stream to parse. |
| ToString | Returns a string that represents the current object. (Inherited from Object) |