+1 vote
by (260 points)
edited

Can someone from the Rebex team take a look at this posting? There is no way you can do a search in the IMAP client component with free-form text. Can you please provide time frame when this feature will be included? It doesn't look like it will require too many changes, just a bit of refactoring.

Applies to: Rebex Secure Mail
by (13.0k points)
Hello Stephen, Martin Vobr from Rebex here. I'll discuss it with devs and post the update here (today).

1 Answer

+1 vote
by (144k points)
edited
 
Best answer

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!

by (260 points)
This will get the job done. Thank you guys! You are awesome!
by (13.0k points)
Nice to know that it works for you! Could you describe why did you chose this approach instead of using default Imap.Seach method? Maybe we overlooked something and our Search API is unsuitable for some usage scenarios. It would help us to enhance the component. Feel free to edit your question if the comment is too short.
by (260 points)
Martin, I think you should definitely consider adding the above functionality as part of your component (probably another Search method with the free-form text). The API you have provided is nice abstraction on top of the low-level IMAP search. However in order for this to be flexibly used you have to create a complete search-criteria builder/editor. The nice thing about the IMAP free-form text search is that you can provide quick-and-dirty text box entry to the end-user.
...