Searching for email messages

Top  Previous  Next

You may search for email messages in a mailbox using the Imap#getMessages(String expression) or Imap#getMessageID(String expression) methods.

 

Search expressions

 

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.

UNANSWERED

Gets all messages that do not have the \Answered flag set.

 

 

Search variables

 

Variable

Description

<message-set>

A comma delimited list of 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

 

The example below queries the IMAP mailbox for all email messages that contain a subject containing the words "application" or "accepted".

 

Enumeration e = imap.getMessages("OR SUBJECT \"accepted\" SUBJECT \"application\"");

 

Example

 

The example below queries the IMAP mailbox for all email messages greater than 100K in size.

 

Enumeration e = imap.getMessages("LARGER 102400");

 

Example

 

The example below queries the IMAP mailbox for all email messages sent after March 1, 2005.

 

Enumeration e = imap.getMessages("SINCE 1-MAR-2005");

 

 

 

 

 





Home | Company | Products | Solutions | Purchase | Support | Services | Blog

© 2021 JSCAPE LLC