Class ImapSearchCriteria
A fluent builder for IMAP SEARCH criteria (RFC 9051 §6.4.4).
Produces the SEARCH argument string (e.g.
FROM "alice" SINCE 1-Jan-2026 UNSEEN). Multiple criteria
chained on the same instance are implicitly ANDed (the IMAP default).
Use Or(ImapSearchCriteria, ImapSearchCriteria) / Not(ImapSearchCriteria) for explicit boolean logic.
Inherited Members
Namespace: DRIT.Mail.Rfc.Imap
Assembly: DRIT.Mail.dll
Syntax
public sealed class ImapSearchCriteria
Methods
View SourceAll()
Matches all messages (ALL).
Declaration
public ImapSearchCriteria All()
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
And(ImapSearchCriteria, ImapSearchCriteria)
Combines two criteria with a logical AND. In IMAP, AND is implicit when multiple keys are listed, so this concatenates the two criteria's terms.
Declaration
public static ImapSearchCriteria And(ImapSearchCriteria a, ImapSearchCriteria b)
Parameters
| Type | Name | Description |
|---|---|---|
| ImapSearchCriteria | a | The first criteria. |
| ImapSearchCriteria | b | The second criteria. |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | A new criteria representing |
Answered()
Matches messages with the \Answered flag set.
Declaration
public ImapSearchCriteria Answered()
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Bcc(string)
Matches messages bcc'd to the specified address (BCC).
Declaration
public ImapSearchCriteria Bcc(string address)
Parameters
| Type | Name | Description |
|---|---|---|
| string | address | The address to match. |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Before(DateTimeOffset)
Matches messages whose internal date is before the specified date
(BEFORE).
Declaration
public ImapSearchCriteria Before(DateTimeOffset date)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTimeOffset | date | The date threshold (exclusive). |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Body(string)
Matches messages whose body contains the specified text (BODY).
Declaration
public ImapSearchCriteria Body(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text to match in the body. |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Cc(string)
Matches messages cc'd to the specified address (CC).
Declaration
public ImapSearchCriteria Cc(string address)
Parameters
| Type | Name | Description |
|---|---|---|
| string | address | The address to match. |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Create()
Creates a new empty search criteria builder.
Declaration
public static ImapSearchCriteria Create()
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | A new ImapSearchCriteria instance. |
Deleted()
Matches messages with the \Deleted flag set.
Declaration
public ImapSearchCriteria Deleted()
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Draft()
Matches messages with the \Draft flag set.
Declaration
public ImapSearchCriteria Draft()
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Flagged()
Matches messages with the \Flagged flag set.
Declaration
public ImapSearchCriteria Flagged()
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
From(string)
Matches messages from the specified address (FROM).
Declaration
public ImapSearchCriteria From(string address)
Parameters
| Type | Name | Description |
|---|---|---|
| string | address | The address to match (substring match server-side). |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Header(string, string)
Matches messages with the specified header value (HEADER).
Declaration
public ImapSearchCriteria Header(string name, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The header name (e.g. |
| string | value | The header value to match. |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Keyword(string)
Matches messages with the specified user-defined keyword set (KEYWORD).
Declaration
public ImapSearchCriteria Keyword(string keyword)
Parameters
| Type | Name | Description |
|---|---|---|
| string | keyword | The keyword (e.g. |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Larger(long)
Matches messages larger than the specified size in bytes (LARGER).
Declaration
public ImapSearchCriteria Larger(long size)
Parameters
| Type | Name | Description |
|---|---|---|
| long | size | The size threshold in bytes (exclusive). |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
New()
Matches messages that are new (recent and unseen) — NEW.
Declaration
public ImapSearchCriteria New()
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Not(ImapSearchCriteria)
Negates a criteria (NOT). The operand is parenthesized if
it contains multiple terms (implicit AND).
Declaration
public static ImapSearchCriteria Not(ImapSearchCriteria a)
Parameters
| Type | Name | Description |
|---|---|---|
| ImapSearchCriteria | a | The criteria to negate. |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | A new criteria representing |
Old()
Matches messages that are old (not recent) — OLD.
Declaration
public ImapSearchCriteria Old()
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
On(DateTimeOffset)
Matches messages whose internal date is the specified date (ON).
Declaration
public ImapSearchCriteria On(DateTimeOffset date)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTimeOffset | date | The date to match. |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Or(ImapSearchCriteria, ImapSearchCriteria)
Combines two criteria with a logical OR (OR). Each operand
is parenthesized if it contains multiple terms (implicit AND).
Declaration
public static ImapSearchCriteria Or(ImapSearchCriteria a, ImapSearchCriteria b)
Parameters
| Type | Name | Description |
|---|---|---|
| ImapSearchCriteria | a | The first criteria. |
| ImapSearchCriteria | b | The second criteria. |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | A new criteria representing |
Recent()
Matches messages with the \Recent flag set.
Declaration
public ImapSearchCriteria Recent()
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Seen()
Matches messages with the \Seen flag set.
Declaration
public ImapSearchCriteria Seen()
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
SentBefore(DateTimeOffset)
Matches messages whose Date header is before the specified date
(SENTBEFORE).
Declaration
public ImapSearchCriteria SentBefore(DateTimeOffset date)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTimeOffset | date | The date threshold (exclusive). |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
SentOn(DateTimeOffset)
Matches messages whose Date header is the specified date (SENTON).
Declaration
public ImapSearchCriteria SentOn(DateTimeOffset date)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTimeOffset | date | The date to match. |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
SentSince(DateTimeOffset)
Matches messages whose Date header is on or after the specified
date (SENTSINCE).
Declaration
public ImapSearchCriteria SentSince(DateTimeOffset date)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTimeOffset | date | The date threshold (inclusive). |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Since(DateTimeOffset)
Matches messages whose internal date is on or after the specified
date (SINCE).
Declaration
public ImapSearchCriteria Since(DateTimeOffset date)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTimeOffset | date | The date threshold (inclusive). |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Smaller(long)
Matches messages smaller than the specified size in bytes (SMALLER).
Declaration
public ImapSearchCriteria Smaller(long size)
Parameters
| Type | Name | Description |
|---|---|---|
| long | size | The size threshold in bytes (exclusive). |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Subject(string)
Matches messages with the specified subject text (SUBJECT).
Declaration
public ImapSearchCriteria Subject(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The subject text to match (substring match server-side). |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Text(string)
Matches messages whose header or body contains the specified text (TEXT).
Declaration
public ImapSearchCriteria Text(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text to match. |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
To(string)
Matches messages addressed to the specified address (TO).
Declaration
public ImapSearchCriteria To(string address)
Parameters
| Type | Name | Description |
|---|---|---|
| string | address | The address to match. |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
ToCommandString()
Returns the SEARCH argument string (e.g.
FROM "alice" SINCE 1-Jan-2026 UNSEEN).
Declaration
public string ToCommandString()
Returns
| Type | Description |
|---|---|
| string | The command string for this criteria. |
Uid(ImapMessageSet)
Matches messages in the specified UID set (UID).
Declaration
public ImapSearchCriteria Uid(ImapMessageSet set)
Parameters
| Type | Name | Description |
|---|---|---|
| ImapMessageSet | set | The UID set to match. |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Unanswered()
Matches messages without the \Answered flag set.
Declaration
public ImapSearchCriteria Unanswered()
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Undeleted()
Matches messages without the \Deleted flag set.
Declaration
public ImapSearchCriteria Undeleted()
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Unflagged()
Matches messages without the \Flagged flag set.
Declaration
public ImapSearchCriteria Unflagged()
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Unkeyword(string)
Matches messages without the specified user-defined keyword (UNKEYWORD).
Declaration
public ImapSearchCriteria Unkeyword(string keyword)
Parameters
| Type | Name | Description |
|---|---|---|
| string | keyword | Specifies the keyword value. |
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |
Unseen()
Matches messages without the \Seen flag set.
Declaration
public ImapSearchCriteria Unseen()
Returns
| Type | Description |
|---|---|
| ImapSearchCriteria | This criteria instance for chaining. |