EmailFormatDetector Class

Detects the format of a file from its content: the signatures of the binary formats and the first lines of the text formats.

public static class EmailFormatDetector

Example

var format = EmailFormatDetector.Detect(path);
Assert.Equal(EmailFileFormat.Msg, format);

Assert.Equal(EmailFileFormat.VCard, EmailFormatDetector.Detect("BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Alice\r\nEND:VCARD\r\n"u8));
Assert.Equal(EmailFileFormat.Eml, EmailFormatDetector.Detect("From: alice@example.com\r\nSubject: Hello\r\n\r\nHi"u8));
Assert.Equal(EmailFileFormat.Unknown, EmailFormatDetector.Detect("Hello world"u8));

Methods

NameDescription
Detect(Stream)Detects the format of a file from its content, read from the current position of a stream.
Detect(ReadOnlySpan<byte>)Detects the format of a file from its content.
Detect(string)Detects the format of a file, or of a folder: a folder that has the cur, new and tmp subfolders is a Maildir folder.

Detect overloads

Detects the format of a file from its content, read from the current position of a stream.

public static EmailFileFormat Detect(Stream stream)
Parameters
stream Stream
The stream. When it can seek, its position is restored.
Returns

EmailFileFormat The format, or EmailFileFormat.Unknown.

Exceptions
IOException
The stream cannot be read.

Detect(ReadOnlySpan<byte>)

EmailFormatDetector.cs

Detects the format of a file from its content.

public static EmailFileFormat Detect(ReadOnlySpan<byte> data)
Parameters
data ReadOnlySpan<byte>
The content of the file. The first 64 KB are enough, except for an Outlook item (.msg): it is told from the other compound files by its streams, so it needs the whole file.
Returns

EmailFileFormat The format, or EmailFileFormat.Unknown.

Detects the format of a file, or of a folder: a folder that has the cur, new and tmp subfolders is a Maildir folder.

public static EmailFileFormat Detect(string path)
Parameters
path string
The path of the file or of the folder.
Returns

EmailFileFormat The format, or EmailFileFormat.Unknown.

Exceptions
IOException
The file cannot be read.