ImapDownloadFolders Method
Downloads the list of all IMAP folders of the mail account.

Namespace: MailBee.ImapMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
Syntax
public FolderCollection DownloadFolders()

Return Value

Type: FolderCollection
FolderCollection object if the folder list was downloaded successfully; otherwise, a null reference (Nothing in Visual Basic).
Exceptions
ExceptionCondition
MailBeeExceptionAn error occurred and ThrowExceptions is true.
Remarks
If the server supports XLIST or SPECIAL-USE extensions (Gmail does), well-known folder flags like Drafts or Trash will be available. See UseXList topic for details.
Examples
This sample downloads the list of all folders of the mail account, and displays them with in user-friendly view with indentation of folder nesting levels.
using System;
using MailBee;
using MailBee.ImapMail;

class Sample
{
    static void Main(string[] args)
    {
        Imap imp = new Imap();

        // Connect to the server and log in the account.
        imp.Connect("mail.server.com");
        imp.Login("jdoe", "secret");

        // Download all the folders.
        FolderCollection folders = imp.DownloadFolders();

        // Used for indentation of folder levels in the output.
        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        foreach (Folder fold in folders)
        {
            // Indent each nesting level with two space characters.
            sb.Length = 0;
            sb.Append(' ', fold.NestingLevel * 2);

            // Print formatted name of the folder.
            Console.WriteLine(sb.ToString() + fold.ShortName);
        }

        imp.Disconnect();
    }
}
See Also