Folder management using IMAP (create, delete, rename)
Here’s the simple example that creates, renames and deletes an IMAP folder:
// C# version:
using Limilabs.Mail;
using Limilabs.Client.IMAP;
class Program
{
static void Main(string[] args)
{
using (Imap imap = new Imap())
{
imap.Connect("server.company.com");
imap.Login("user", "password");
imap.SelectInbox();
imap.CreateFolder("New folder");
imap.RenameFolder("New folder", "Better name");
imap.DeleteFolder("Better 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("server.company.com")
imap.Login("user", "password")
imap.SelectInbox()
imap.CreateFolder("New folder")
imap.RenameFolder("New folder", "Better name")
imap.DeleteFolder("Better name")
imap.Close()
End Using
End Sub
End Module
How to test if a folder exists.
List all = imap.GetFolders();
bool exists = all.Contains("Inbox/Test folder");
How to create a folder
Use imap.CreateFolder(string folder) method
How to list the number of messages in the folder
FolderStatus status = imap.Examine(string folder); long count = status.MessageCount;
How to list the subfolders of the folder
// direct children
List direct = imap.GetFoldersOneLevelDown("Inbox");
// all children
List all = imap.GetFolders("Inbox");
How to copy messages from one folder to another
imap.Select("Inbox/Source folder");
List uids = imap.GetAll();
imap.CopyByUID(uids, "Inbox/Destination folder");
How to delete folder and its messages
imap.DeleteFolder("Inbox/folder to delete");
June 12th, 2011 at 15:03
[...] such, labels can be modified using the standard IMAP commands, CreateFolder, RenameFolder, and DeleteFolder, that act on [...]
December 7th, 2011 at 16:10
[...] You can read more about folder management using IMAP. [...]
February 16th, 2012 at 15:11
[...] such, labels can be modified using the standard IMAP commands, CreateFolder, RenameFolder, and DeleteFolder, that act on [...]