| Visual Basic (Declaration) | |
|---|---|
Public Function BeginSearch( _ ByVal criteria As ICollection, _ ByVal state As Object _ ) As IAsyncResult | |
| Visual Basic (Usage) | Copy Code |
|---|---|
Dim instance As Mailbox Dim criteria As ICollection Dim state As Object Dim value As IAsyncResult value = instance.BeginSearch(criteria, state) | |
| C# | |
|---|---|
public IAsyncResult BeginSearch( ICollection criteria, object state ) | |
| Managed Extensions for C++ | |
|---|---|
public: IAsyncResult* BeginSearch( ICollection* criteria, Object* state ) | |
| C++/CLI | |
|---|---|
public: IAsyncResult^ BeginSearch( ICollection^ criteria, Object^ state ) | |
Parameters
- criteria
- A collection of one or more ImapSearchParameter objects, defining the type of search to perform.
- state
- User state information.
| Exception | Description |
|---|---|
| Dart.PowerTCP.Mail.ProtocolException | Bad IMAP protocol response received from server. |
| System.Net.Sockets.SocketException | The requested address is not valid in its context. |
| System.InvalidOperationException | BeginXXX method used without providing an EndXXX event handler. |
| System.InvalidCastException | Specified cast is invalid |
The following example demonstrates using the Mailbox.BeginSearch method. This example constructs the search "SEARCH FLAGGED SINCE 1-Feb-1994 NOT FROM 'Smith'"
| Visual Basic | Copy Code |
|---|---|
Private Sub AsynchronousSearchTest() ' Login Imap1.Login(Server, User, Pass) ' Construct the search "SEARCH FLAGGED SINCE 1-Feb-1994 NOT FROM 'Smith'" Dim Criteria As New ArrayList() Criteria.Add(New ImapSearchParameter(ImapCriterion.Flagged, "")) Criteria.Add(New ImapSearchParameter(ImapCriterion.Since, "1-Feb-1994")) Criteria.Add(New ImapSearchParameter(ImapCriterion.Not, "")) Criteria.Add(New ImapSearchParameter(ImapCriterion.From, "Smith")) ' Alternatively, ImapSearchParameter objects can be created like so ' Dim Param As New ImapSearchParameter() ' Param.Criterion = ImapCriterion.Flagged ' Param.Paramter = "" ' Criteria.Add(Param) ' Perform the search. This will occur on the default box INBOX. Imap1.CurrentMailbox.BeginSearch(Criteria, Nothing) End Sub Private Sub Imap1_EndSearch(ByVal sender As Object, ByVal e As Dart.PowerTCP.Mail.ImapMessageEventArgs) Handles Imap1.EndSearch If e.Exception Is Nothing Then ' The following messages meet the criteria Dim Msg As ImapMessages For Each Msg In e.Messages Debug.WriteLine("Message: " + Msg.Id) Next End Sub End Sub | |
| C# | Copy Code |
|---|---|
private void AsynchronousSearchTest() { // Login imap1.Login(Server, User, Pass); // Construct the search "SEARCH FLAGGED SINCE 1-Feb-1994 NOT FROM 'Smith'" ArrayList criteria = new ArrayList(); criteria.Add(new ImapSearchParameter(ImapCriterion.Flagged, "")); criteria.Add(new ImapSearchParameter(ImapCriterion.Since, "1-Feb-1994")); criteria.Add(new ImapSearchParameter(ImapCriterion.Not, "")); criteria.Add(new ImapSearchParameter(ImapCriterion.From, "Smith")); /* / Alternatively, ImapSearchParameter objects can be created like so / ImapSearchParameter param = new ImapSearchParameter(); / param.Criterion = ImapCriterion.Flagged; / param.Paramter = ""; / criteria.Add(param); */ // Perform the search. This will occur on the default box INBOX. imap1.CurrentMailbox.BeginSearch(criteria, null); } private void imap1_EndSearch(object sender, Dart.PowerTCP.Mail.ImapMessageEventArgs e) { if(e.Exception == null) { // The following messages meet the criteria foreach(ImapMessage msg in e.Messages) Debug.WriteLine("Message: " + msg.Id); } } | |
The Mailbox.BeginSearch method begins to asynchronously send the "SEARCH" command to the server along with all of the search restrictions specified ImapSearchParameter. Upon completion, the Imap.EndSearch event is raised. Proper use involves creating an object which implements ICollection, adding several ImapSearchParameters to this object, and passing this object into the Mailbox.Search method as criteria. Multiple values are combined with a logical AND. Other logical combinations can be represented using the ImapCriterion values ImapCriterion.Not and ImapCriterion.Or.
Target Platforms: Microsoft .NET Framework 2.0