Searching messages


C: SEARCH MARKED NOT TO "nobody@example.com"
S: * SEARCH 1 3-5 7
S: +OK Messages searched
C: SEARCH 1-5,15-20 LARGER 10000
S: * SEARCH 1 3-5 17
S: +OK Messages searched

The SEARCH command instructs the server to search messages in the currently open folder. The next whitespace delimited word specifies the set of messages to search. The remaining words specify the search criteria. The set of messages to search is specified in one of four ways:

MARKED

Search only the messages that have the MARKED flag already set.

UNMARKED

Search only the messages that do not have the MARKED flag set.

ALL

Search all messages.

range

range is a comma-separated range of message numbers to search. Consecutive message numbers may be given as A-B, indicating messages A through B, inclusive.

Each SEARCH command specifies a single search criteria. Simple criterias are combined to form more complicated searches by using a series of SEARCH and STORE commands. First, all messages have their MARKED flag cleared. The list of messages found by the first SEARCH MARKED command is fed into the STORE command, setting their marked flags. Then additional searches are performed, using SEARCH MARKED or SEARCH UNMARKED, with or without the NOT keyword, forming a complex query.

The NOT keyword optional follows, and indicates that the following search criteria specification should be logically inverted. For example, if the search is for messages with the subject line containing foo, the search will not be for messages whose subject line does not contain foo.

The available search criteria are:

REPLIED

Search for messages that have the REPLIED flag set.

DELETED

Search for messages that have the DELETED flag set.

DRAFT

Search for messages that have the DRAFT flag set.

SEEN

Search for messages that have the SEEN flag set.

FROM string

Search for messages that have string in their From: header.

TO string

Search for messages that have string in their To: header.

CC string

Search for messages that have string in their Cc: header.

BCC string

Search for messages that have string in their Bcc: header.

SUBJECT string

Search for messages that have string in their Subject: header.

HEADER header string

Search for messages that have string in their header (without the colon) header.

BODY string

Search for messages that have string in their content.

TEXT string

Search for messages that have string in their content or headers.

BEFORE mm-ddd-yyyy

Search for messages whose INTERNALDATE is earlier than mm-ddd-yyyy.

ON mm-ddd-yyyy

Search for messages whose INTERNALDATE is mm-ddd-yyyy.

SINCE mm-ddd-yyyy

Search for messages whose INTERNALDATE is on or after mm-ddd-yyyy.

SENTBEFORE mm-ddd-yyyy

Search for messages whose Date: header is prior to mm-ddd-yyyy.

SENTON mm-ddd-yyyy

Search for messages whose Date: header reads mm-ddd-yyyy.

SENTSINCE mm-ddd-yyyy

Search for messages whose Date: header reads on or after mm-ddd-yyyy.

LARGER n

Search for messages whose estimated size is more than n bytes.

SMALLER n

Search for messages whose estimated size is less than n bytes.

Note

All text strings above use the UTF-8 character set. For header or content searches, the search string must be converted to the header's (MIME-encoded) or content's character set. Searching should be case insensitive.

Date-based searches specify months by their short English names.

The server's * SEARCH reply enumerates messages found by the search. For extremely large folders, the server may send multiple * SEARCH replies in order to keep line lengths under the maximum. No * SEARCH replies are sent when no messages are found by the search criteria.