Search Method
Searches the currently selected mailbox for
messages which meet specified condition.
This method can also sort the results but the IMAP server must support SORT extension for that. Gmail and Outlook.com still don't support SORT to the moment (Feb 2015). If sorting is not supported
by the server, this method will fail. To learn how check for an extension,
see MoveMessages method's example. It checks for MOVE extension, checking for SORT
can be done the same way.
Message numbers (or UIDs) are returned as array of numbers. Lower bound of the
array is 1.
By default, this method just returns message numbers or UIDs for all messages
in the mailbox. To search for specific items, specify non-empty search Condition.
Condition is a set of search criteria in IMAP4 format. Some popular search
keys are listed below:
arrIndices = ObjectName.Search(AsUID, [Condition], [Charset]) |
Parameters: | ||
AsUID As Boolean | If True, returned array will be array of UIDs (unique-IDs). Otherwise, message numbers will be returned | |
Condition As String | (optional) Search condition. Default is "ALL" (all messages in the currently selected mailbox returned) | |
Charset as String | (optional) Charset of the string that appear in search criteria. If not specified, default (US-ASCII) charset is assumed | |
OrderBy as String | (optional) Sorting rule. If not specified, SEARCH command instead of SORT is used and the messages get returned in their natural order in the mailbox | |
Return value As Variant | Array of Variant/Long, each value is UID or message number of the message. If error has occurred, return value is Empty |
Usage example:
' This sample searches Inbox and retrieves unread messages only Dim Mailer, SearchResults, Message, I 'Using visual basic to create object Set Mailer = CreateObject("MailBee.IMAP4") 'Using ASP to create object 'Set Mailer = Server.CreateObject("MailBee.IMAP4") 'In ASP use Response.Write instead of MsgBox Mailer.EnableLogging = True Mailer.LogFilePath = "C:\Temp\imap4_log.txt" Mailer.ClearLog Mailer.LicenseKey = "put your license key here" If Mailer.Connect("mailserver.com", 143, "MyName", "MyPassword") Then If Mailer.SelectMailbox("Inbox") Then SearchResults = Mailer.Search(False, "UNSEEN") ' Get list of message numbers of unread messages If Not IsEmpty(SearchResults) Then For I = LBound(SearchResults) To UBound(SearchResults) Set Message = Mailer.RetrieveSingleMessage(SearchResults(I), False) If Not Message Is Nothing Then MsgBox Message.BodyText End If Next End If End If Mailer.Disconnect End If
See Also:
Envelope.UID
Property
RetrieveEnvelopes Method
RetrieveEnvelopesEx Method
RetrieveSingleMessage Method
Copyright © 2002-2024, AfterLogic Corporation. All rights reserved.