user3430435
user3430435

Reputation: 71

Retrieve IMAP Subfolders

I am trying to retrieve the subfolders and messages from the inbox but i was only able to retrieve the parent subfolders, also tried with PersonalNamespaces[0]

var inbox = client.Inbox;
inbox.Open (FolderAccess.ReadWrite);

Debug.WriteLine ("Total messages: {0}", inbox.Count);
//client.Inbox.Status(StatusItems.Unread);
//Debug.WriteLine("Recent messages: {0}", inbox.Unread);
//Debug.WriteLine("Recent messages: {0}", inbox.FirstUnread);

var personal = client.GetFolder(client.PersonalNamespaces[0]);

foreach (var folder in inbox.GetSubfolders(false))
{
        Console.WriteLine("[folder] {0}", folder.Name);
        folder.Open(FolderAccess.ReadOnly);

Upvotes: 6

Views: 9273

Answers (1)

jstedfast
jstedfast

Reputation: 38618

Not all IMAP servers will even allow subfolders of the INBOX folder. If you are sure that your IMAP account's INBOX folder has subfolders, you would use the following code snippet to get them:

foreach (var folder in client.Inbox.GetSubfolders (false)) {
    Console.WriteLine ("[folder] {0}", folder.Name);
}

Upvotes: 4

Related Questions