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 EmlxFileExample
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
| Name | Description |
|---|---|
| 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.csReads an .emlx file from a stream, until its end.
public static EmlxMessage Load(Stream stream, MimeReadOptions? options = null)Parameters
streamStream- The stream.
optionsMimeReadOptions?- The options of the message, or
nullfor the default options.MimeReadOptions.MaxSizelimits 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.csReads an .emlx file.
public static EmlxMessage Load(ReadOnlyMemory<byte> data, MimeReadOptions? options = null)Parameters
dataReadOnlyMemory<byte>- The content of the file.
optionsMimeReadOptions?- The options of the message, or
nullfor 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.csReads an .emlx or .partial.emlx file.
public static EmlxMessage Load(string path, MimeReadOptions? options = null)Parameters
pathstring- The path of the file.
optionsMimeReadOptions?- The options of the message, or
nullfor 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.csWrites 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
messageMimeMessage- The message.
streamStream- The stream.
flagsEmlxFlags- The flags of the message.
dateReceivedDateTimeOffset?- The date the message was received, or
nullfor the date of the message.
Save(MimeMessage, string, EmlxFlags, DateTimeOffset?)
EmlxFile.csWrites a message as an .emlx file.
public static void Save(MimeMessage message, string path, EmlxFlags flags = EmlxFlags.None, DateTimeOffset? dateReceived = null)Parameters
messageMimeMessage- The message.
pathstring- The path of the file.
flagsEmlxFlags- The flags of the message.
dateReceivedDateTimeOffset?- The date the message was received, or
nullfor the date of the message.