You may search for email messages in a mailbox using the GetMessages(String expression) or GetMessageID(String expression) methods.
Search expressions
The following table lists the valid expressions and their description.
Expression
|
Description
|
<message set>
|
Gets all messages with indexes listed.
|
ALL
|
Gets all messages.
|
ANSWERED
|
Gets all messages that have the \Answered flag set.
|
BCC <string>
|
Gets all messages whose Bcc header contains the given string.
|
BEFORE <date>
|
Gets all messages whose internal date is before the given date.
|
BODY <string>
|
Gets all messages whose message body contains the given string.
|
CC <string>
|
Gets all messages whose Cc header contains the given string.
|
DELETED
|
Gets all messages that have the \Deleted flag set.
|
DRAFT
|
Gets all messages that have the \Draft flag set.
|
FLAGGED
|
Gets all messages with the \Flagged flag set.
|
FROM <string>
|
Gets all messages whose From header contains the given string.
|
HEADER <name> <string>
|
Gets all messages where the specified header name contains the given string.
|
KEYWORD <flag>
|
Gets all messages with the given flag set.
|
LARGER <integer>
|
Gets all messages that are larger than given number of bytes.
|
NEW
|
Gets all messages with the \Recent flag set but the \Seen flag not set.
|
NOT <expression>
|
Gets all messages that do not match the specified search key.
|
OLD
|
Gets all messages that do not have the \Recent flag set.
|
ON <date>
|
Gets all messages whose internal date match the given date.
|
OR <expression> <expression>
|
Gets all messages that match either search key.
|
RECENT
|
Gets all messages that have the \Recent flag set.
|
SEEN
|
Gets all messages that have the \Seen flag set.
|
SENTBEFORE <date>
|
Gets all messages that were sent before the given date.
|
SENTON <date>
|
Gets all messages that were sent on the given date
|
SINCE <date>
|
Gets all message that have an internal on or after the given date.
|
SMALLER <number>
|
Gets all message that are smaller then given number of bytes.
|
SUBJECT <string>
|
Gets all messages whose Subject header contain the given string.
|
TEXT <string>
|
Gets all messages whose headers or body contain the given string.
|
TO <string>
|
Gets all messages whose To header contains the given string.
|
UID <message set>
|
Gets all messages with unique identifiers listed.
|
Search variables
The following tables lists the valid search variables and their description.
Variable
|
Description
|
<message-set>
|
A comma delimited list of one-based message indexes.
Example
1,2,3
|
<string>
|
An escape-quoted string value.
Example
"\"testing\""
|
<date>
|
A date in the format DD-MMM-YYYY.
Example
5-MAY-2001
|
<integer>
|
A valid integer value.
Example
5
|
<flag>
|
A valid keyword flag of Seen, Answered, Flagged, Deleted, Draft or Recent
Example
Seen
|
<expression>
|
A valid search expression.
Example
SINCE 1-MAR-2005
|
Example 1
This example queries the IMAP mailbox for all email messages whose subject contains the words "application" or "accepted".
[C#]
IEnumerator e = myImap.GetMessages("OR SUBJECT \"accepted\" SUBJECT \"application\"");
[Visual Basic]
Dim e As IEnumerator = myImap.GetMessages("OR SUBJECT \"accepted\" SUBJECT \"application\"")
Example 2
This example queries the IMAP mailbox for all email messages greater than 100K in size.
[C#]
IEnumerator e = myImap.GetMessages("LARGER 102400");
[Visual Basic]
Dim e As IEnumerator = myImap.GetMessages("LARGER 102400")
Example 3
This example queries the IMAP mailbox for all email messages sent after March 1, 2005.
[C#]
IEnumerator e = myImap.GetMessages("SINCE 1-MAR-2005");
[Visual Basic]
Dim e As IEnumerator = myImap.GetMessgaes("SINCE 1-MAR-2005")
|