Click or drag to resize
MimeKit

ImapClientGetFolder(FolderNamespace) Method

Get the folder for the specified namespace.

Namespace: MailKit.Net.Imap
Assembly: MailKit (in MailKit.dll) Version: 4.3.0
Syntax
C#
public override IMailFolder GetFolder(
	FolderNamespace namespace
)

Parameters

namespace  FolderNamespace
The namespace.

Return Value

IMailFolder
The folder.

Implements

IMailStoreGetFolder(FolderNamespace)
IMailStoreGetFolder(FolderNamespace)
Exceptions
ExceptionCondition
ArgumentNullExceptionnamespace is null.
ObjectDisposedException The ImapClient has been disposed.
ServiceNotConnectedException The ImapClient is not connected.
ServiceNotAuthenticatedException The ImapClient is not authenticated.
FolderNotFoundException The folder could not be found.
Remarks
Gets the folder for the specified namespace.
Example
C#
public static void ShowNamespaces ()
{
    using (var client = new ImapClient ()) {
        client.Connect ("imap.mail-server.com", 993, SecureSocketOptions.SslOnConnect);
        client.Authenticate ("username", "password");

        Console.WriteLine ("Personal namespaces:");
        foreach (var ns in client.PersonalNamespaces)
            Console.WriteLine ($"* \"{ns.Path}\" \"{ns.DirectorySeparator}\"");
        Console.WriteLine ();
        Console.WriteLine ("Shared namespaces:");
        foreach (var ns in client.SharedNamespaces)
            Console.WriteLine ($"* \"{ns.Path}\" \"{ns.DirectorySeparator}\"");
        Console.WriteLine ();
        Console.WriteLine ("Other namespaces:");
        foreach (var ns in client.OtherNamespaces)
            Console.WriteLine ($"* \"{ns.Path}\" \"{ns.DirectorySeparator}\"");
        Console.WriteLine ();

        // get the folder that represents the first personal namespace
        var personal = client.GetFolder (client.PersonalNamespaces[0]);

        // list the folders under the first personal namespace
        var subfolders = personal.GetSubfolders ();

        Console.WriteLine ("The list of folders that are direct children of the first personmal namespace:");
        foreach (var folder in subfolders)
            Console.WriteLine ($"* {folder.Name}");

        client.Disconnect (true);
    }
}
See Also