Localized Gmail IMAP folders


There are no well-know names for common folders such as Drafts, Trash, Spam, … on IMAP servers.

The problem is even worse when you use localized version of IMAP client. GMail folder names are localized with respect to the user localization settings, so ‘[Gmail]/All Mail’ show as ‘[Gmail]/Todos’ to Spanish users for example.

Google and Apple developed a special IMAP command XLIST to address this issue.

IMAP XLIST command returns a list of folders and their well-know flags (Inbox, Drafts, Trash, Sent, Spam Important).

Mail.dll IMAP client supports XLIST command. It is used automatically when server advertises support for this feature.

You can use CommonFolders class to match folder names with they real purpose.

Take a look at the examples:

// C# version:

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

    CommonFolders folders = 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();
}
' VB.NET version:

Using imap As New Imap()
    imap.ConnectSSL("imap.gmail.com")
    imap.Login("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

Tags: , , ,

2 Responses to “Localized Gmail IMAP folders”

  1. Ola Says:

    Great stuff! Very useful!
    Mail.dll keeps getting better

  2. IMAP: LIST, XLIST and LSUB Says:

    [...] You can read more about XLIST here: http://www.lesnikowski.com/blog/localized-gmail-imap-folders/ [...]

Leave a Reply