ImapBeginDownloadFolders Method

Note: This API is now obsolete.

Begins an asynchronous request for downloading IMAP folders matching the specified criteria.

Namespace: MailBee.ImapMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 11.2.0 build 590 for .NET 4.5
Syntax
[ObsoleteAttribute("This method is obsolete in .NET 4.5+. Use DownloadFoldersAsync instead.")]
public IAsyncResult BeginDownloadFolders(
	bool subscribedOnly,
	string parentFolderName,
	string pattern,
	AsyncCallback callback,
	Object state
)

Parameters

subscribedOnly
Type: SystemBoolean
If true, only subscribed folders will be downloaded; otherwise, all the folders.
parentFolderName
Type: SystemString
The full name of the folder which subfolders must be downloaded, or a null reference (Nothing in Visual Basic) to download all the folders.
pattern
Type: SystemString
The exact or wildcard name (relative to parentFolderName) of the folder or folders to be downloaded, or a null reference (Nothing in Visual Basic) to download all the folders.
callback
Type: SystemAsyncCallback
The AsyncCallback delegate. You can leave it a null reference (Nothing in Visual Basic) if you do not use callbacks.
state
Type: SystemObject
An object that contains state information for this request. You can leave it a null reference (Nothing in Visual Basic).

Return Value

Type: IAsyncResult
An IAsyncResult that references the asynchronous download folder list process.
Exceptions
ExceptionCondition
MailBeeInvalidStateExceptionThere is already an operation in progress.
Remarks
This method is an asynchronous version of DownloadFolders(Boolean, String, String).
Examples
This sample demonstrates asynchronous downloading of folders list using complex pattern in a console application. BeginDownloadFolders(Boolean, String, String, AsyncCallback, Object) method is called twice. First, to get a delimiter of folders level. Second, to get the list of folders which are subfolders of the 1st level. Thus, "Inbox/Orders" and "Sent Items/Personal" will be listed while "Inbox", "Sent Items", "Drafts", "Inbox/Orders/April 2006", "Inbox/Orders/April 2006/29" will not (because they are either parent folders or subfolders of deeper levels such as 2, 3, etc).
using System;
using MailBee;
using MailBee.ImapMail;

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

        imp.Connect("mail.somehost.com");

        imp.Login("jdoe", "secret");

        // Initiate an asynchronous download folder list attempt.
        // This will download a single empty Folder element having only delimiter
        // field set. We need it in order to correctly combine pattern value for
        // subsequent folder list download.
        IAsyncResult ar = imp.BeginDownloadFolders(false, "", "", null, null);

        // Simulate some lengthy work here. At the same time,
        // folders are being downloaded is executed on another thread.
        System.Threading.Thread.Sleep(3000);

        // If the download is still in progress, then wait until it's finished,
        // and get the delimiter.
        FolderCollection folders = imp.EndDownloadFolders();

        if (folders.Count == 0)
        {
            Console.WriteLine("Bad IMAP4 server.");
        }
        else
        {
            string delim = folders[0].Delimiter;

            if (delim == null)
            {
                Console.WriteLine("Folder names are flat. Hierarchy is not supported.");
            }
            else
            {

                // Initiate an asynchronous download folder list attempt.
                // Here, we request to download all 1st level subfolders of the account.
                ar = imp.BeginDownloadFolders(false, "", "%" + delim + "%", null, null);

                // Simulate some lengthy work here. At the same time,
                // folders are being downloaded is executed on another thread.
                System.Threading.Thread.Sleep(3000);

                // If the download is still in progress, then wait until it's finished,
                // and get the folders.
                folders = imp.EndDownloadFolders();

                // Print folder names matching the specified criteria.
                foreach (Folder fold in folders)
                {
                    Console.WriteLine(fold.Name);
                }
            }
        }

        // Disconnect from the server.
        imp.Disconnect();
    }
}
See Also