What about this code? It works quite well:
// initialize, connect and authenticate an IMAP session
Imap imap = new Imap();
...
// select a folder
imap.SelectFolder("Inbox");
// send a search command with free-form text
imap.SendCommand("UID SEARCH", "SUBJECT test SINCE 24-Mar-2009");
// read the response
ImapResponse response = imap.ReadResponse();
// create an empty message set to fill in with message UIDs
ImapMessageSet set = new ImapMessageSet();
// get the folder's validity ID, we will need this later
long validityId = imap.CurrentFolder.ValidityId;
// parse all "SEARCH" responses
foreach (ImapResponseLine line in response.GetLines())
{
if (line.Code == "SEARCH")
{
// get a list of raw IDs
string[] ids = line.Parameters.Split(' ');
foreach (string rawId in ids)
{
// convert each raw ID into Rebex-style unique ID
long id = Convert.ToInt64(rawId);
string uniqueId = ImapMessageSet.BuildUniqueId(validityId, id);
// add the unique ID into the message set
set.Add(uniqueId);
}
}
}
// use the message set for any purpose
// for example, you can use it to retrieve the list of message envelopes
ImapMessageCollection list = imap.GetMessageList(set, ImapListFields.Envelope);
// diplay message dates and subjects
foreach (ImapMessageInfo info in list)
{
Console.WriteLine("{0} {1}", info.Date, info.Subject);
}
If you prefer VB.NET, please let us know!