Dart.Mail Namespace > Mailbox Class : Search Method |
Public Function Search( _ ByVal criteria() As ImapSearchParameter _ ) As ImapMessage()
Dim instance As Mailbox Dim criteria() As ImapSearchParameter Dim value() As ImapMessage value = instance.Search(criteria)
public ImapMessage[] Search( ImapSearchParameter[] criteria )
public: ImapMessage*[]* Search( ImapSearchParameter*[]* criteria )
public: array<ImapMessage^>^ Search( array<ImapSearchParameter^>^ criteria )
Exception | Description |
---|---|
ProtocolException | Bad IMAP protocol response received from server. |
System.Net.Sockets.SocketException | A communications failure has occurred. |
System.InvalidCastException | Specified cast is invalid. |
This method sends the "SEARCH" command to the server. Multiple ImapSearchParameters are combined with a logical AND. Other logical combinations can be represented using the ImapCriterion values ImapCriterion.Not and ImapCriterion.Or. See RFC 3501 or other on-line resources for guidance on how to use this powerful search tool.
If Imap.Session.AutoUtf8 is set to true, and the server advertises UTF8=ACCEPT, UTF8 will be used for encoding and decoding UNICODE strings.
private void getMessages(object state) { //Configure server and account info imap1.Session.RemoteEndPoint = new Dart.Mail.IPEndPoint(myServer, Imap.GetDefaultPort(imap1.Session)); imap1.Session.Username = myUsername; imap1.Session.Password = myPassword; //Connect and log into the account imap1.Connect(); imap1.Authenticate(); //Set the selected mailbox to the Inbox imap1.SelectedMailbox = imap1.Mailboxes["INBOX"]; // Construct the search "SEARCH SINCE 1-Jan-2012 NOT FROM JACKSON" ImapSearchParameter[] criteria = new ImapSearchParameter[] { new ImapSearchParameter(ImapCriterion.Since, "1-Jan-2012"), new ImapSearchParameter(ImapCriterion.Not, ""), new ImapSearchParameter(ImapCriterion.From, "JACKSON") }; // Perform the search ImapMessage[] messages = imap1.SelectedMailbox.Search(criteria); //Copy all messages that meet the criteria to the 'Save' mailbox foreach (ImapMessage imapMessage in messages) imapMessage.CopyTo(imap1.Mailboxes["Save"]); //Gracefully logout imap1.Close(); }
Private Sub getMessages(ByVal state As Object) 'Configure server and account info imap1.Session.RemoteEndPoint = New Dart.Mail.IPEndPoint(myServer, Imap.GetDefaultPort(imap1.Session)) imap1.Session.Username = myUsername imap1.Session.Password = myPassword 'Connect and log into the account imap1.Connect() imap1.Authenticate() 'Set the selected mailbox to the Inbox imap1.SelectedMailbox = imap1.Mailboxes("INBOX") ' Construct the search "SEARCH SINCE 1-Jan-2012 NOT FROM JACKSON" Dim criteria() As ImapSearchParameter = { New ImapSearchParameter(ImapCriterion.Since, "1-Jan-2012"), New ImapSearchParameter(ImapCriterion.Not, ""), New ImapSearchParameter(ImapCriterion.From, "JACKSON") } ' Perform the search Dim messages() As ImapMessage = imap1.SelectedMailbox.Search(criteria) 'Copy all messages that meet the criteria to the 'Save' mailbox For Each imapMessage As ImapMessage In messages imapMessage.CopyTo(imap1.Mailboxes("Save")) Next imapMessage 'Gracefully logout imap1.Close() End Sub