ImapBeginDownloadFolders Method |
Note: This API is now obsolete.
Namespace: MailBee.ImapMail
[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 )
Exception | Condition |
---|---|
MailBeeInvalidStateException | There is already an operation in progress. |
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(); } }