• DR-IT Software
  • Products
  • Documentation
  • Product page
  • Examples
  • API reference
  • Support
Show / Hide Table of Contents

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.

Inheritance
object
ImapSearchCriteria
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
Namespace: DRIT.Mail.Rfc.Imap
Assembly: DRIT.Mail.dll
Syntax
public sealed class ImapSearchCriteria

Methods

View Source

All()

Matches all messages (ALL).

Declaration
public ImapSearchCriteria All()
Returns
Type Description
ImapSearchCriteria

This criteria instance for chaining.

View Source

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 a AND b.

View Source

Answered()

Matches messages with the \Answered flag set.

Declaration
public ImapSearchCriteria Answered()
Returns
Type Description
ImapSearchCriteria

This criteria instance for chaining.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

Create()

Creates a new empty search criteria builder.

Declaration
public static ImapSearchCriteria Create()
Returns
Type Description
ImapSearchCriteria

A new ImapSearchCriteria instance.

View Source

Deleted()

Matches messages with the \Deleted flag set.

Declaration
public ImapSearchCriteria Deleted()
Returns
Type Description
ImapSearchCriteria

This criteria instance for chaining.

View Source

Draft()

Matches messages with the \Draft flag set.

Declaration
public ImapSearchCriteria Draft()
Returns
Type Description
ImapSearchCriteria

This criteria instance for chaining.

View Source

Flagged()

Matches messages with the \Flagged flag set.

Declaration
public ImapSearchCriteria Flagged()
Returns
Type Description
ImapSearchCriteria

This criteria instance for chaining.

View Source

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.

View Source

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. Message-ID).

string value

The header value to match.

Returns
Type Description
ImapSearchCriteria

This criteria instance for chaining.

View Source

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. $Junk).

Returns
Type Description
ImapSearchCriteria

This criteria instance for chaining.

View Source

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.

View Source

New()

Matches messages that are new (recent and unseen) — NEW.

Declaration
public ImapSearchCriteria New()
Returns
Type Description
ImapSearchCriteria

This criteria instance for chaining.

View Source

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 NOT a.

View Source

Old()

Matches messages that are old (not recent) — OLD.

Declaration
public ImapSearchCriteria Old()
Returns
Type Description
ImapSearchCriteria

This criteria instance for chaining.

View Source

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.

View Source

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 a OR b.

View Source

Recent()

Matches messages with the \Recent flag set.

Declaration
public ImapSearchCriteria Recent()
Returns
Type Description
ImapSearchCriteria

This criteria instance for chaining.

View Source

Seen()

Matches messages with the \Seen flag set.

Declaration
public ImapSearchCriteria Seen()
Returns
Type Description
ImapSearchCriteria

This criteria instance for chaining.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

Unanswered()

Matches messages without the \Answered flag set.

Declaration
public ImapSearchCriteria Unanswered()
Returns
Type Description
ImapSearchCriteria

This criteria instance for chaining.

View Source

Undeleted()

Matches messages without the \Deleted flag set.

Declaration
public ImapSearchCriteria Undeleted()
Returns
Type Description
ImapSearchCriteria

This criteria instance for chaining.

View Source

Unflagged()

Matches messages without the \Flagged flag set.

Declaration
public ImapSearchCriteria Unflagged()
Returns
Type Description
ImapSearchCriteria

This criteria instance for chaining.

View Source

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.

View Source

Unseen()

Matches messages without the \Seen flag set.

Declaration
public ImapSearchCriteria Unseen()
Returns
Type Description
ImapSearchCriteria

This criteria instance for chaining.

  • View Source
Back to top

DR-IT Software documentation

DR-IT Software · Products · Documentation index · Product page · Downloads · Support · Licensing

Generated by DocFX