When you need to limit the view of a sorted table, always make the following IMAPITable calls in the following order:
If the sorted table is categorized, make a call to SetCollapseState if necessary after the SortTable call. This ordering of calls is important because most service providers sort a table as the last task to achieve the best performance. If, for example, a message store provider must categorize a folder contents table before a restriction can be imposed, this categorization will be removed during the processing of the restriction. A second categorization will be necessary.