SPECIAL-USE | Blog | Limilabs https://www.limilabs.com/blog Using Limilabs .net components Tue, 17 Jun 2014 13:17:07 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 Common IMAP folders https://www.limilabs.com/blog/common-imap-folders Thu, 19 Apr 2012 14:56:18 +0000 http://www.limilabs.com/blog/?p=2647 There are no well-know names for common folders such as Drafts, Trash, Spam, … defined in IMAP protocol standards. This makes quite difficult for an IMAP client to know the real purpose of the folders on the server. Fortunately there are two IMAP protocol extensions: XLIST – supported by Gmail SPECIAL-USE – RFC 6154 standardized […]

The post Common IMAP folders first appeared on Blog | Limilabs.

]]>
There are no well-know names for common folders such as Drafts, Trash, Spam, … defined in IMAP protocol standards.

This makes quite difficult for an IMAP client to know the real purpose of the folders on the server.

Fortunately there are two IMAP protocol extensions:

You can check if your servers support it by checking if SupportedExtensions returns ImapExtension.XList or ImapExtension.SpecialUse

Both extensions are supported by Mail.dll and, if your server supports any of them, you can take advantage of CommonFolders class. CommonFolders allows you to get the name of the folder and Select it, by knowing its purpose (for example Spam folder may be called “Junk email” on the server).

// C# version:

using (Imap imap = new Imap())
{
    imap.ConnectSSL("imap.gmail.com");
    imap.UseBestLogin("pat@gmail.com", "password");

    CommonFolders folders = new CommonFolders(imap.GetFolders());

    Console.WriteLine("Inbox folder: " + folders.Inbox.Name);
    Console.WriteLine("Sent folder: " + folders.Sent.Name);
    Console.WriteLine("Spam folder: " + folders.Spam.Name);

    // You can select folders easy:
    imap.Select(folders.Inbox);
    imap.Select(folders.Sent);
    imap.Select(folders.Spam);

    imap.Close();
}
' VB.NET version:

Using imap As New Imap()
    imap.ConnectSSL("imap.gmail.com")
    imap.UseBestLogin("pat@gmail", "password")

    Dim folders As New CommonFolders(imap.GetFolders())

    Console.WriteLine("Inbox folder: " + folders.Inbox.Name)
    Console.WriteLine("Sent folder: " + folders.Sent.Name)

    ' You can select folders easy:
    imap.Select(folders.Inbox)
    imap.Select(folders.Sent)


    imap.Close()
End Using

You can check if you can use CommonFolders with following code:

// C#

List<ImapExtension> extensions = client.SupportedExtensions();
bool canUseCommonFolders = extensions.Contains(ImapExtension.XList) 
    || extensions.Contains(ImapExtension.SpecialUse);
' VB.NET

Dim extensions As List(Of ImapExtension) = client.SupportedExtensions()
Dim canUseCommonFolders As Boolean = extensions.Contains(ImapExtension.XList) OrElse extensions.Contains(ImapExtension.SpecialUse)

The post Common IMAP folders first appeared on Blog | Limilabs.

]]>