How to search folder for imap4?

Aug 27, 2012 at 8:21 AM
Edited Aug 27, 2012 at 8:22 AM

I am a chinese programmer.So I need find a folder(name is chinese) for imap4.

My code like:

 Imap4Client imap = new Imap4Client();               

imap.Connect(_server, 143, _user, _password);

Mailbox inbox = imap.SelectMailbox("收件箱");

--“收件箱” is a folder name.

And i try  use "imap.Mailboxes.Count",but it not work.

so i want to know how to find or get the folder list?

Can you help me?

Aug 18, 2013 at 5:06 AM
If you just need to know the name of the mailboxes in the IMAP server, you can use the allmailboxes property from a connected Imap4Client, that gives you a collection of Mailboxes that you can check their names with property "name" (if you want hierarchy) or "shortname" (the Imap4Client should be logged and not fastlogged).

The problem with the code you wrote is that when you use the overloaded method imap.connect(host, port, username, password), MailSystem uses internally the fastLogin method which does NOT bring mailboxes of the account. I can think 2 ways to work arround this:

1) Replace your imap.Connect method with:
imap.Connect(hostString, portNumber);
imap.Login(emailAddress, emailPassword): //will load the Mailboxes of the account
2) Or after your imap.Connect method add:
imap.LoadMailboxes();
Fast code you can use to print the names of the mailboxes (put after mailboxes were loaded):
for (int currentMailbox = 0; currentMailbox < this.receiver.AllMailboxes.Count; currentMailbox++)
{
      System.Console.WriteLine(this.receiver.AllMailboxes[currentMail].Name);
}
System.Console.ReadKey(); //so console doesnt close automatically
Hope this helps!