MailBee.NET Objects 4.0

Imap.DownloadFolders Method ()

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

public FolderCollection DownloadFolders();

Return Value

FolderCollection object if the folder list was downloaded successfully; otherwise, a null reference (Nothing in Visual Basic).

Exceptions

Exception Type Condition
MailBeeException An error occurred and ThrowExceptions is true.

Example

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.

[C#]
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();
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.ImapMail

Module Sample
    Sub Main(ByVal args As String())
        Dim imp As New Imap

        ' Connect to the server and log in the account.
        imp.Connect("imap4.company.com")
        imp.Login("jdoe@company.com", "secret")

        ' Download only subscribed folders.
        Dim folders As FolderCollection = imp.DownloadFolders()

        ' Used for indentation of folder levels in the output.
        Dim sb As New System.Text.StringBuilder

        ' Print full names of the folders.
        For Each fold As Folder 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)
        Next

        imp.Disconnect()
    End Sub
End Module

See Also

Imap Class | MailBee.ImapMail Namespace | Imap.DownloadFolders Overload List | BeginDownloadFolders