List all folders using IMAP
IMAP protocol sometimes calls folders mailboxes. It’s not very fortunate as mailbox usually means email address (john.smith@example.com) or account attached to an email address.
You can use Mail.dll IMAP component to retrieve a list of all IMAP folders existing on the server, by using GetFolders method. It returns a list of FolderInfo objects. You can use this object to get a folder name (FolderInfo.Name). You can also use FolderInfo instance as a parameter for SelectFolderInfo() method to access this folder.
// C# version:
using Limilabs.Mail;
using Limilabs.Client.IMAP;
using System;
class Program
{
static void Main(string[] args)
{
using (Imap imap = new Imap())
{
imap.Connect("imap.example.com");
imap.Login("user", "password");
foreach (FolderInfo folder in imap.GetFolders())
{
Console.WriteLine(folder.Name);
}
imap.Close();
}
}
};
' VB.NET version:
Imports Limilabs.Mail
Imports Limilabs.Client.IMAP
Public Module Module1
Public Sub Main(ByVal args As String())
Using imap As New Imap()
imap.Connect("imap.example.com")
imap.Login("user", "password")
For Each folder As FolderInfo In imap.GetFolders()
Console.WriteLine(folder.Name)
Next
imap.Close()
End Using
End Sub
End Module
FolderInfo object contains detailed information about the folder (Name, SeparatorChar, Flags)
You can read more about folder management using IMAP.
On some servers it is possible to get information about the purpose (spam, sent items) of each IMAP folder.
June 12th, 2011 at 15:03
[...] Use the XLIST command to get the entire list of labels for a mailbox. [...]