ImapBeginSortedSearch Method

Note: This API is now obsolete.

Begins an asynchronous request for searching the currently selected folder for messages meeting the specified criteria and sorting them accordingly the specified sort condition.

Namespace: MailBee.ImapMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
Syntax
[ObsoleteAttribute("This method is obsolete in .NET 4.5+. Use SortedSearchAsync instead.")]
public IAsyncResult BeginSortedSearch(
	bool returnUids,
	string searchCondition,
	string charset,
	string orderBy,
	AsyncCallback callback,
	Object state
)

Parameters

returnUids
Type: SystemBoolean
If true, search results will be returned as UidCollection; otherwise, as MessageNumberCollection.
searchCondition
Type: SystemString
Search expression in IMAP4 language, or a null reference (Nothing in Visual Basic) to make the method return all messages in the folder.
charset
Type: SystemString
Charset used in searchCondition, or a null reference to use US-ASCII setting.
orderBy
Type: SystemString
Sorting order expression in IMAP4 language, or a null reference (Nothing in Visual Basic) to make the method downgrade to the regular BeginSearch(Boolean, String, String, AsyncCallback, Object).
callback
Type: SystemAsyncCallback
The AsyncCallback delegate. You can leave it a null reference (Nothing in Visual Basic) if you do not use callbacks.
state
Type: SystemObject
An object that contains state information for this request. You can leave it a null reference (Nothing in Visual Basic).

Return Value

Type: IAsyncResult
An IAsyncResult that references the asynchronous search process.
Exceptions
ExceptionCondition
MailBeeInvalidStateExceptionThere is already an operation in progress.
Remarks
This method is an asynchronous version of SortedSearch(Boolean, String, String, String).
Examples
This console sample demonstrates asynchronous search of messages arrived into the Inbox folder since yesterday and sorting them by their Subject line.
C#
using System;
using MailBee;
using MailBee.ImapMail;

class Sample
{
    // A callback function.
    private static void SortedSearchCallback(IAsyncResult result)
    {
        // Extract values from state object.
        Imap imp = (Imap)((object [])result.AsyncState)[0];
        bool sortAvail = (bool)((object [])result.AsyncState)[1];

        // Display the outcome.
        Console.WriteLine("SORT capability is " + (!sortAvail ? "NOT " : "") + "available");
        try
        {
            Console.WriteLine("UIDs found: " + ((UidCollection)imp.EndSortedSearch()).ToString());
        }
        catch (Exception e)
        {
            // Catching exception here is recommended. Because callback function is a separate
            // thread, unhandled exception would silently terminate it without any message to
            // the user (and it would be hard to understand what exactly happened).
            Console.WriteLine("Exception occurred: " + e.Message);
            Console.WriteLine(e.StackTrace);
        }
    }

    // The actual code.
    static void Main(string[] args)
    {
        Imap imp = new Imap();

        // Connect to the server, login and select inbox.
        imp.Connect("imap.domain.com");
        imp.Login("jdoe", "secret");
        imp.SelectFolder("INBOX");

        // Set to true if SORT extension is available.
        bool sortAvail = (imp.GetExtension("SORT") != null);

        // If SORT is supported, order messages by SUBJECT field. If SORT is not supported,
        // orderBy criteria will not be set and SortedSearch will downgrade to the regular Search.
        string orderByCriteria = sortAvail ? "SUBJECT" : null;

        // Initiate an asynchronous request for getting UIDs of messages received since yesterday,
        // sorted accordingly orderByCriteria.
        IAsyncResult ar = imp.BeginSortedSearch(true,
            "SINCE \"" + ImapUtils.GetImapDateString(DateTime.Today.AddDays(-1)) + "\"",
            null, orderByCriteria,
            new AsyncCallback(SortedSearchCallback), new object[] {imp, sortAvail});

        // Simulate some lengthy work here. At the same time,
        // folder selection is executed on another thread.
        System.Threading.Thread.Sleep(3000);

        // If the folder selection attempt is still in progress,
        // then wait until it's finished.
        while (imp.IsBusy) ar.AsyncWaitHandle.WaitOne();

        // Disconnect from the server.
        imp.Disconnect();
    }
}
See Also