Skip to content

Commit

Permalink
Opened up more of the SearchQuery API to make it possible to serializ…
Browse files Browse the repository at this point in the history
…e/deserialize via JSON.

Fixes issue #331
  • Loading branch information
jstedfast committed Apr 30, 2016
1 parent 34c1462 commit 3ae737e
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 11 deletions.
1 change: 0 additions & 1 deletion MailKit/Net/Imap/ImapFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8104,7 +8104,6 @@ void BuildQuery (StringBuilder builder, SearchQuery query, List<string> args, bo
BinarySearchQuery binary;
UnarySearchQuery unary;
DateSearchQuery date;
bool isFlag;

if (builder.Length > 0)
builder.Append (' ');
Expand Down
11 changes: 10 additions & 1 deletion MailKit/Search/BinarySearchQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@ namespace MailKit.Search {
/// </remarks>
public class BinarySearchQuery : SearchQuery
{
internal BinarySearchQuery (SearchTerm term, SearchQuery left, SearchQuery right) : base (term)
/// <summary>
/// Initializes a new instance of the <see cref="T:MailKit.Search.BinarySearchQuery"/> class.
/// </summary>
/// <remarks>
/// Creates a new binary search query.
/// </remarks>
/// <param name="term">THe search term.</param>
/// <param name="left">The left expression.</param>
/// <param name="right">The right expression.</param>
public BinarySearchQuery (SearchTerm term, SearchQuery left, SearchQuery right) : base (term)
{
Right = right;
Left = left;
Expand Down
10 changes: 9 additions & 1 deletion MailKit/Search/DateSearchQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ namespace MailKit.Search {
/// </remarks>
public class DateSearchQuery : SearchQuery
{
internal DateSearchQuery (SearchTerm term, DateTime date) : base (term)
/// <summary>
/// Initializes a new instance of the <see cref="T:MailKit.Search.DateSearchQuery"/> class.
/// </summary>
/// <remarks>
/// Creates a new date-based search query.
/// </remarks>
/// <param name="term">The search term.</param>
/// <param name="date">The date.</param>
public DateSearchQuery (SearchTerm term, DateTime date) : base (term)
{
Date = date;
}
Expand Down
10 changes: 9 additions & 1 deletion MailKit/Search/HeaderSearchQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ namespace MailKit.Search {
/// </remarks>
public class HeaderSearchQuery : SearchQuery
{
internal HeaderSearchQuery (string field, string value) : base (SearchTerm.HeaderContains)
/// <summary>
/// Initializes a new instance of the <see cref="T:MailKit.Search.HeaderSearchQuery"/> class.
/// </summary>
/// <remarks>
/// Creates a new header search query.
/// </remarks>
/// <param name="field">The header field name.</param>
/// <param name="value">The value to match against.</param>
public HeaderSearchQuery (string field, string value) : base (SearchTerm.HeaderContains)
{
Field = field;
Value = value;
Expand Down
10 changes: 9 additions & 1 deletion MailKit/Search/NumericSearchQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ namespace MailKit.Search {
/// </remarks>
public class NumericSearchQuery : SearchQuery
{
internal NumericSearchQuery (SearchTerm term, ulong value) : base (term)
/// <summary>
/// Initializes a new instance of the <see cref="T:MailKit.Search.NumericSearchQuery"/> class.
/// </summary>
/// <remarks>
/// Creates a new numeric search query.
/// </remarks>
/// <param name="term">The search term.</param>
/// <param name="value">The numeric value.</param>
public NumericSearchQuery (SearchTerm term, ulong value) : base (term)
{
Value = value;
}
Expand Down
27 changes: 25 additions & 2 deletions MailKit/Search/SearchQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,35 @@ namespace MailKit.Search {
/// </remarks>
public class SearchQuery
{
internal SearchQuery (SearchTerm term)
/// <summary>
/// Initializes a new instance of the <see cref="T:MailKit.Search.SearchQuery"/> class.
/// </summary>
/// <remarks>
/// Creates a new <see cref="SearchQuery"/> that matches all messages.
/// </remarks>
public SearchQuery () : this (SearchTerm.All)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="T:MailKit.Search.SearchQuery"/> class.
/// </summary>
/// <remarks>
/// Creates a new <see cref="SearchQuery"/> with the specified search term.
/// </remarks>
protected SearchQuery (SearchTerm term)
{
Term = term;
}

internal SearchTerm Term {
/// <summary>
/// Get the search term used by the search query.
/// </summary>
/// <remarks>
/// Gets the search term used by the search query.
/// </remarks>
/// <value>The term.</value>
public SearchTerm Term {
get; private set;
}

Expand Down
204 changes: 203 additions & 1 deletion MailKit/Search/SearchTerm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,52 +25,254 @@
//

namespace MailKit.Search {
enum SearchTerm {
/// <summary>
/// A search term.
/// </summary>
/// <remarks>
/// The search term as used by <see cref="SearchQuery"/>.
/// </remarks>
public enum SearchTerm {
/// <summary>
/// A search term that matches all messages.
/// </summary>
All,

/// <summary>
/// A search term that logically combines 2 or more other
/// search expressions such that messages must match both
/// expressions.
/// </summary>
And,

/// <summary>
/// A search term that matches answered messages.
/// </summary>
Answered,

/// <summary>
/// A search term that matches messages that contain a specified
/// string within the <c>Bcc</c> header.
/// </summary>
BccContains,

/// <summary>
/// A search term that matches messages that contain a specified
/// string within the body of the message.
/// </summary>
BodyContains,

/// <summary>
/// A search term that matches messages that contain a specified
/// string within the <c>Cc</c> header.
/// </summary>
CcContains,

/// <summary>
/// A search term that matches deleted messages.
/// </summary>
Deleted,

/// <summary>
/// A search term that matches messages delivered after a specified date.
/// </summary>
DeliveredAfter,

/// <summary>
/// A search term that matches messages delivered before a specified date.
/// </summary>
DeliveredBefore,

/// <summary>
/// A search term that matches messages delivered on a specified date.
/// </summary>
DeliveredOn,

/// <summary>
/// A search term that matches draft messages.
/// </summary>
Draft,

/// <summary>
/// A search term that matches flagged messages.
/// </summary>
Flagged,

/// <summary>
/// A search term that matches messages that contain a specified
/// string within the <c>From</c> header.
/// </summary>
FromContains,

/// <summary>
/// A search term that modifies another search expression to allow
/// fuzzy matching.
/// </summary>
Fuzzy,

/// <summary>
/// A search term that matches messages that contain a specified
/// string within a particular header.
/// </summary>
HeaderContains,

/// <summary>
/// A search term that matches messages that contain a specified
/// keyword.
/// </summary>
Keyword,

/// <summary>
/// A search term that matches messages that are larger than a
/// specified number of bytes.
/// </summary>
LargerThan,

/// <summary>
/// A search term that matches messages that contain a specified
/// string anywhere within the message.
/// </summary>
MessageContains,

/// <summary>
/// A search term that matches messages that have the specified
/// modification sequence value.
/// </summary>
ModSeq,

/// <summary>
/// A search term that matches new messages.
/// </summary>
New,

/// <summary>
/// A search term that modifies another search expression such that
/// messages must match the logical inverse of the expression.
/// </summary>
Not,

/// <summary>
/// A search term that matches messages that have not been answered.
/// </summary>
NotAnswered,

/// <summary>
/// A search term that matches messages that have not been deleted.
/// </summary>
NotDeleted,

/// <summary>
/// A search term that matches messages that are not drafts.
/// </summary>
NotDraft,

/// <summary>
/// A search term that matches messages that have not been flagged.
/// </summary>
NotFlagged,

/// <summary>
/// A search term that matches messages that do not contain a specified
/// keyword.
/// </summary>
NotKeyword,

/// <summary>
/// A search term that matches messages that are not recent.
/// </summary>
NotRecent,

/// <summary>
/// A search term that matches messages that have not been seen.
/// </summary>
NotSeen,

/// <summary>
/// A search term that matches messages that are older than a specified date.
/// </summary>
Older,

/// <summary>
/// A search term that logically combines 2 or more other
/// search expressions such that messages only need to match
/// one of the expressions.
/// </summary>
Or,

/// <summary>
/// A search term that matches messages that are recent.
/// </summary>
Recent,

/// <summary>
/// A search term that matches messages that have been seen.
/// </summary>
Seen,

/// <summary>
/// A search term that matches messages that were sent after a specified date.
/// </summary>
SentAfter,

/// <summary>
/// A search term that matches messages that were sent before a specified date.
/// </summary>
SentBefore,

/// <summary>
/// A search term that matches messages that were sent on a specified date.
/// </summary>
SentOn,

/// <summary>
/// A search term that matches messages that are smaller than a
/// specified number of bytes.
/// </summary>
SmallerThan,

/// <summary>
/// A search term that matches messages that contain a specified
/// string within the <c>Subject</c> header.
/// </summary>
SubjectContains,

/// <summary>
/// A search term that matches messages that contain a specified
/// string within the <c>To</c> header.
/// </summary>
ToContains,

/// <summary>
/// A search term that matches messages included within a specified
/// set of unique identifiers.
/// </summary>
Uid,

/// <summary>
/// A search term that matches messages that are younger than a specified date.
/// </summary>
Younger,

// GMail SEARCH extensions

/// <summary>
/// A search term that matches messages with a specified GMail message identifier.
/// </summary>
GMailMessageId,

/// <summary>
/// A search term that matches messages with a specified GMail thread (conversation)
/// identifier.
/// </summary>
GMailThreadId,

/// <summary>
/// A search term that matches messages with the specified GMail labels.
/// </summary>
GMailLabels,

/// <summary>
/// A search term that uses the GMail search syntax.
/// </summary>
GMailRaw,
}
}
12 changes: 10 additions & 2 deletions MailKit/Search/TextSearchQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@ namespace MailKit.Search {
/// <remarks>
/// A text-based search query.
/// </remarks>
public sealed class TextSearchQuery : SearchQuery
public class TextSearchQuery : SearchQuery
{
internal TextSearchQuery (SearchTerm term, string text) : base (term)
/// <summary>
/// Initializes a new instance of the <see cref="T:MailKit.Search.TextSearchQuery"/> class.
/// </summary>
/// <remarks>
/// Creates a new text-based search query.
/// </remarks>
/// <param name="term">The search term.</param>
/// <param name="text">The text to match against.</param>
public TextSearchQuery (SearchTerm term, string text) : base (term)
{
Text = text;
}
Expand Down
Loading

0 comments on commit 3ae737e

Please sign in to comment.