EmlxFile Class

Reads and writes the files of the messages of Apple Mail (.emlx): the size of the message on the first line, the message, then a property list of its flags and dates.

public static class EmlxFile

Example

var emlx = EmlxFile.Load(path);
Assert.Equal("First", emlx.Message.Subject);
Assert.True(emlx.Flags.HasFlag(EmlxFlags.Read));
Assert.Equal(new DateTimeOffset(2025, 7, 1, 8, 52, 37, TimeSpan.Zero), emlx.DateReceived);
Assert.Equal("4242", emlx.Properties["remote-id"]);

using var stream = new MemoryStream();
EmlxFile.Save(emlx.Message, stream, EmlxFlags.Read | EmlxFlags.Flagged);

Methods

NameDescription
Load(Stream, MimeReadOptions?)Reads an .emlx file from a stream, until its end.
Load(ReadOnlyMemory<byte>, MimeReadOptions?)Reads an .emlx file.
Load(string, MimeReadOptions?)Reads an .emlx or .partial.emlx file.
Save(MimeMessage, Stream, EmlxFlags, DateTimeOffset?)Writes a message as an .emlx file. The lines of the message end with LF, as in the files of Apple Mail.
Save(MimeMessage, string, EmlxFlags, DateTimeOffset?)Writes a message as an .emlx file.

Load overloads

Load(Stream, MimeReadOptions?)

EmlxFile.cs

Reads an .emlx file from a stream, until its end.

public static EmlxMessage Load(Stream stream, MimeReadOptions? options = null)
Parameters
stream Stream
The stream.
options MimeReadOptions?
The options of the message, or null for the default options. MimeReadOptions.MaxSize limits the size of the file.
Returns

EmlxMessage The message and its properties.

Exceptions
InvalidEmailDataException
The first line is not the size of the message, the size is larger than the file, or the property list is malformed.
EmailResourceLimitException
The file is larger than MimeReadOptions.MaxSize.

Load(ReadOnlyMemory<byte>, MimeReadOptions?)

EmlxFile.cs

Reads an .emlx file.

public static EmlxMessage Load(ReadOnlyMemory<byte> data, MimeReadOptions? options = null)
Parameters
data ReadOnlyMemory<byte>
The content of the file.
options MimeReadOptions?
The options of the message, or null for the default options.
Returns

EmlxMessage The message and its properties.

Exceptions
InvalidEmailDataException
The first line is not the size of the message, the size is larger than the file, or the property list is malformed.

Load(string, MimeReadOptions?)

EmlxFile.cs

Reads an .emlx or .partial.emlx file.

public static EmlxMessage Load(string path, MimeReadOptions? options = null)
Parameters
path string
The path of the file.
options MimeReadOptions?
The options of the message, or null for the default options.
Returns

EmlxMessage The message and its properties.

Exceptions
InvalidEmailDataException
The first line is not the size of the message, the size is larger than the file, or the property list is malformed.
EmailResourceLimitException
The file is larger than MimeReadOptions.MaxSize.

Save overloads

Save(MimeMessage, Stream, EmlxFlags, DateTimeOffset?)

EmlxFile.cs

Writes a message as an .emlx file. The lines of the message end with LF, as in the files of Apple Mail.

public static void Save(MimeMessage message, Stream stream, EmlxFlags flags = EmlxFlags.None, DateTimeOffset? dateReceived = null)
Parameters
message MimeMessage
The message.
stream Stream
The stream.
flags EmlxFlags
The flags of the message.
dateReceived DateTimeOffset?
The date the message was received, or null for the date of the message.

Save(MimeMessage, string, EmlxFlags, DateTimeOffset?)

EmlxFile.cs

Writes a message as an .emlx file.

public static void Save(MimeMessage message, string path, EmlxFlags flags = EmlxFlags.None, DateTimeOffset? dateReceived = null)
Parameters
message MimeMessage
The message.
path string
The path of the file.
flags EmlxFlags
The flags of the message.
dateReceived DateTimeOffset?
The date the message was received, or null for the date of the message.