Client applications can search through one or more folders looking for messages that match search criteria. The most straightforward search technique involves applying a restriction to define criteria and placing the results into a search-results folder, created explicitly for this search or for a prior search. Not all message stores support this technique. To determine whether or not the message store you are using supports using search-results folders, call its IMAPIProp::GetProps method to retrieve the PR_STORE_SUPPORT_MASK property. If the STORE_SEARCH_OK flag is set, searching is supported. If it is not set, you'll need an alternate approach such as manually inspecting the target folders.
To search one or more folders in a message store
If you have a search-results folder from a previous search, skip to step 2. Otherwise, to create a search-results folder:
Retrieve the entry identifier for the search-results root folder by calling the message store's IMAPIProp::GetProps method and requesting PR_FINDER_ENTRYID.
Call the folder's IMAPIFolder::CreateFolder method to create a search-results folder with the FOLDER_SEARCH flag set.
Build a restriction to hold your search criteria.
Create an array of entry identifiers that represent the folders to search. This step is unnecessary if the search-results folder has been used before and you want to search the same folders.
Call the search-results folder's IMAPIContainer::SetSearchCriteria method, pointing lpContainerList to the entry identifier array and lpRestriction to the restriction.
If you have registered for search complete notifications with the message store, wait for the notification to arrive.
View the results of the search by calling the search-results folder's IMAPIContainer::GetContentsTable method to access its contents table.
Call the contents table's IMAPITable::QueryRows methodto retrieve the messages that satisfy the search criteria.