MaildirFolder Class
A Maildir folder: a directory with the subdirectories tmp, new and cur, and a file per message. The subfolders follow the Maildir++ convention: directories whose names start with a dot.
public sealed class MaildirFolderExample
var folder = MaildirFolder.Create(path);
var message = new MimeMessage { Subject = "Hello" };
var body = new MimePart();
body.SetText("Hello from a Maildir folder.");
message.Body = body;
// A message without flags goes in "new", a message with flags in "cur" with the flags in its name
var added = folder.AddMessage(message);
Assert.True(added.IsNew);
var read = folder.SetFlags(added, MaildirFlags.Seen | MaildirFlags.Replied);
Assert.EndsWith("2,RS", read.FullPath, StringComparison.Ordinal);
var sent = folder.CreateFolder("Sent");
sent.AddMessage(message, MaildirFlags.Seen);
Assert.Equal(["Sent"], folder.EnumerateFolders().Select(subfolder => subfolder.Name));
Assert.Equal("Hello", folder.EnumerateMessages().Single().Load().Subject);Properties
| Name | Description |
|---|---|
| FullPath | Gets the path of the directory of the folder. |
| InfoSeparator | Gets the character between the unique name of a message and its information when the folder writes a file name: :, or ! on Windows, where a file name cannot contain :. The reader accepts :, ! and ;. |
FullPath
MaildirFolder.csInfoSeparator
MaildirFolder.csMethods
| Name | Description |
|---|---|
| AddMessage(MimeMessage, MaildirFlags) | Adds a message: writes it in tmp, then moves it to new, or to cur when it has flags. |
| AddMessage(ReadOnlySpan<byte>, MaildirFlags) | Adds the bytes of a message: writes them in tmp, then moves the file to new, or to cur when the message has flags. |
| Create(string) | Creates a folder, or opens it when it exists. |
| CreateFolder(string) | Creates a subfolder (Maildir++), or opens it when it exists. |
| Delete(MaildirMessage) | Deletes the file of a message. |
| EnumerateFolders() | Returns the subfolders (Maildir++): the subdirectories whose names start with a dot, such as .Sent or .Archive.2026. |
| EnumerateMessages() | Returns the messages of the new and cur directories. The files whose names start with a dot are skipped. |
| Open(string) | Opens a folder. |
| SetFlags(MaildirMessage, MaildirFlags) | Sets the flags of a message: moves its file to cur, with the flags in its name. |
AddMessage overloads
AddMessage(MimeMessage, MaildirFlags)
MaildirFolder.csAdds a message: writes it in tmp, then moves it to new, or to cur when it has flags.
public MaildirMessage AddMessage(MimeMessage message, MaildirFlags flags = MaildirFlags.None)Parameters
messageMimeMessage- The message.
flagsMaildirFlags- The flags of the message.
Returns
MaildirMessage The message added.
AddMessage(ReadOnlySpan<byte>, MaildirFlags)
MaildirFolder.csAdds the bytes of a message: writes them in tmp, then moves the file to new, or to cur when the message has flags.
public MaildirMessage AddMessage(ReadOnlySpan<byte> content, MaildirFlags flags = MaildirFlags.None)Parameters
contentReadOnlySpan<byte>- The bytes of the message.
flagsMaildirFlags- The flags of the message.
Returns
MaildirMessage The message added.
Create(string)
MaildirFolder.csCreates a folder, or opens it when it exists.
public static MaildirFolder Create(string path)CreateFolder(string)
MaildirFolder.csCreates a subfolder (Maildir++), or opens it when it exists.
public MaildirFolder CreateFolder(string name)Parameters
namestring- The name of the subfolder, such as
Sent; the levels are separated by dots (Archive.2026).
Returns
MaildirFolder The subfolder.
Delete(MaildirMessage)
MaildirFolder.csDeletes the file of a message.
public void Delete(MaildirMessage message)Parameters
messageMaildirMessage- The message.
EnumerateFolders()
MaildirFolder.csReturns the subfolders (Maildir++): the subdirectories whose names start with a dot, such as .Sent or .Archive.2026.
public IEnumerable<(string Name, MaildirFolder Folder)> EnumerateFolders()Returns
IEnumerable<(string Name, MaildirFolder Folder)> The names of the subfolders, without their first dot, and their folders.
EnumerateMessages()
MaildirFolder.csReturns the messages of the new and cur directories. The files whose names start with a dot are skipped.
public IEnumerable<MaildirMessage> EnumerateMessages()Returns
IEnumerable<MaildirMessage> The messages.
Open(string)
MaildirFolder.csOpens a folder.
public static MaildirFolder Open(string path)Parameters
pathstring- The path of the directory.
Returns
MaildirFolder The folder.
Exceptions
DirectoryNotFoundException- The directory does not exist, or has no
curornewsubdirectory.
SetFlags(MaildirMessage, MaildirFlags)
MaildirFolder.csSets the flags of a message: moves its file to cur, with the flags in its name.
public MaildirMessage SetFlags(MaildirMessage message, MaildirFlags flags)Parameters
messageMaildirMessage- The message.
flagsMaildirFlags- The flags.
Returns
MaildirMessage The message, with its new path.