本文整理汇总了C#中MailKit.Search.SearchQuery类的典型用法代码示例。如果您正苦于以下问题:C# SearchQuery类的具体用法?C# SearchQuery怎么用?C# SearchQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SearchQuery类属于MailKit.Search命名空间,在下文中一共展示了SearchQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanReduce
public bool CanReduce (SearchQuery expr)
{
if (expr.Term == SearchTerm.Not) {
var unary = (UnarySearchQuery) expr;
if (unary.Operand == SearchQuery.Answered)
return true;
if (unary.Operand == SearchQuery.Deleted)
return true;
if (unary.Operand == SearchQuery.Draft)
return true;
if (unary.Operand == SearchQuery.Flagged)
return true;
if (unary.Operand == SearchQuery.Recent)
return true;
if (unary.Operand == SearchQuery.Seen)
return true;
if (unary.Operand.Term == SearchTerm.Keyword)
return true;
if (unary.Operand.Term == SearchTerm.NotKeyword)
return true;
}
return false;
}
示例2: Reduce
public SearchQuery Reduce (SearchQuery expr)
{
if (expr.Term == SearchTerm.Not) {
var unary = (UnarySearchQuery) expr;
if (unary.Operand == SearchQuery.Answered)
return SearchQuery.NotAnswered;
if (unary.Operand == SearchQuery.Deleted)
return SearchQuery.NotDeleted;
if (unary.Operand == SearchQuery.Draft)
return SearchQuery.NotDraft;
if (unary.Operand == SearchQuery.Flagged)
return SearchQuery.NotFlagged;
if (unary.Operand == SearchQuery.Recent)
return SearchQuery.NotRecent;
if (unary.Operand == SearchQuery.Seen)
return SearchQuery.NotSeen;
if (unary.Operand.Term == SearchTerm.Keyword)
return new TextSearchQuery (SearchTerm.NotKeyword, ((TextSearchQuery) unary.Operand).Text);
if (unary.Operand.Term == SearchTerm.NotKeyword)
return new TextSearchQuery (SearchTerm.Keyword, ((TextSearchQuery) unary.Operand).Text);
}
return expr;
}
示例3: And
/// <summary>
/// Creates a conditional AND operation.
/// </summary>
/// <remarks>
/// A conditional AND operation only evaluates the second operand if the first operand evaluates to true.
/// </remarks>
/// <returns>A <see cref="BinarySearchQuery"/> representing the conditional AND operation.</returns>
/// <param name="left">The first operand.</param>
/// <param name="right">The second operand.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="left"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="right"/> is <c>null</c>.</para>
/// </exception>
public static BinarySearchQuery And (SearchQuery left, SearchQuery right)
{
if (left == null)
throw new ArgumentNullException ("left");
if (right == null)
throw new ArgumentNullException ("right");
return new BinarySearchQuery (SearchTerm.And, left, right);
}
示例4: Reduce
public SearchQuery Reduce (SearchQuery expr)
{
if (expr.Term == SearchTerm.And) {
var and = (BinarySearchQuery) expr;
if (and.Left.Term == SearchTerm.All)
return and.Right;
if (and.Right.Term == SearchTerm.All)
return and.Left;
} else if (expr.Term == SearchTerm.Or) {
var or = (BinarySearchQuery) expr;
if (or.Left.Term == SearchTerm.All)
return SearchQuery.All;
if (or.Right.Term == SearchTerm.All)
return SearchQuery.All;
} else if (expr.Term == SearchTerm.Not) {
var unary = (UnarySearchQuery) expr;
switch (unary.Operand.Term) {
case SearchTerm.NotAnswered: return SearchQuery.Answered;
case SearchTerm.Answered: return SearchQuery.NotAnswered;
case SearchTerm.NotDeleted: return SearchQuery.Deleted;
case SearchTerm.Deleted: return SearchQuery.NotDeleted;
case SearchTerm.NotDraft: return SearchQuery.Draft;
case SearchTerm.Draft: return SearchQuery.NotDraft;
case SearchTerm.NotFlagged: return SearchQuery.Flagged;
case SearchTerm.Flagged: return SearchQuery.NotFlagged;
case SearchTerm.NotRecent: return SearchQuery.Recent;
case SearchTerm.Recent: return SearchQuery.NotRecent;
case SearchTerm.NotSeen: return SearchQuery.Seen;
case SearchTerm.Seen: return SearchQuery.NotSeen;
}
if (unary.Operand.Term == SearchTerm.Keyword)
return new TextSearchQuery (SearchTerm.NotKeyword, ((TextSearchQuery) unary.Operand).Text);
if (unary.Operand.Term == SearchTerm.NotKeyword)
return new TextSearchQuery (SearchTerm.Keyword, ((TextSearchQuery) unary.Operand).Text);
}
return expr;
}
示例5: ThreadAsync
/// <summary>
/// Asynchronously thread the messages in the folder that match the search query using the specified threading algorithm.
/// </summary>
/// <remarks>
/// The <see cref="MessageThread.UniqueId"/> can be used with methods such as
/// <see cref="IMailFolder.GetMessage(UniqueId,CancellationToken,ITransferProgress)"/>.
/// </remarks>
/// <returns>An array of message threads.</returns>
/// <param name="algorithm">The threading algorithm to use.</param>
/// <param name="query">The search query.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="algorithm"/> is not supported.
/// </exception>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="query"/> is <c>null</c>.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// <para>One or more search terms in the <paramref name="query"/> are not supported by the mail store.</para>
/// <para>-or-</para>
/// <para>The server does not support the THREAD extension.</para>
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="IMailStore"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="IMailStore"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="IMailStore"/> is not authenticated.
/// </exception>
/// <exception cref="FolderNotOpenException">
/// The folder is not currently open.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="ProtocolException">
/// The server's response contained unexpected tokens.
/// </exception>
/// <exception cref="CommandException">
/// The command failed.
/// </exception>
public virtual Task<IList<MessageThread>> ThreadAsync (ThreadingAlgorithm algorithm, SearchQuery query, CancellationToken cancellationToken = default (CancellationToken))
{
if (query == null)
throw new ArgumentNullException ("query");
return Task.Factory.StartNew (() => {
lock (SyncRoot) {
return Thread (algorithm, query, cancellationToken);
}
}, cancellationToken, TaskCreationOptions.None, TaskScheduler.Default);
}
示例6: Search
/// <summary>
/// Searches the subset of UIDs in the folder for messages matching the specified query,
/// returning them in the preferred sort order.
/// </summary>
/// <remarks>
/// Searches the folder for messages matching the specified query and ordering,
/// returning only the requested search results.
/// </remarks>
/// <returns>The search results.</returns>
/// <param name="options">The search options.</param>
/// <param name="uids">The subset of UIDs</param>
/// <param name="query">The search query.</param>
/// <param name="orderBy">The sort order.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="uids"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="query"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="orderBy"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ArgumentException">
/// <para>One or more of the <paramref name="uids"/> is invalid.</para>
/// <para>-or-</para>
/// <para><paramref name="orderBy"/> is empty.</para>
/// </exception>
/// <exception cref="System.NotSupportedException">
/// <para>One or more search terms in the <paramref name="query"/> are not supported by the IMAP server.</para>
/// <para>-or-</para>
/// <para>The server does not support the ESORT extension.</para>
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="IMailStore"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="IMailStore"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="IMailStore"/> is not authenticated.
/// </exception>
/// <exception cref="FolderNotOpenException">
/// The folder is not currently open.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="ProtocolException">
/// The server's response contained unexpected tokens.
/// </exception>
/// <exception cref="CommandException">
/// The command failed.
/// </exception>
public abstract SearchResults Search (SearchOptions options, IList<UniqueId> uids, SearchQuery query, IList<OrderBy> orderBy, CancellationToken cancellationToken = default (CancellationToken));
示例7: SearchAsync
/// <summary>
/// Asynchronously searches the subset of UIDs in the folder for messages matching the specified query,
/// returning them in the preferred sort order.
/// </summary>
/// <remarks>
/// Asynchronously searches the folder for messages matching the specified query and ordering,
/// returning only the requested search results.
/// </remarks>
/// <returns>The search results.</returns>
/// <param name="options">The search options.</param>
/// <param name="uids">The subset of UIDs</param>
/// <param name="query">The search query.</param>
/// <param name="orderBy">The sort order.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="uids"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="query"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="orderBy"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ArgumentException">
/// <para>One or more of the <paramref name="uids"/> is invalid.</para>
/// <para>-or-</para>
/// <para><paramref name="orderBy"/> is empty.</para>
/// </exception>
/// <exception cref="System.NotSupportedException">
/// <para>One or more search terms in the <paramref name="query"/> are not supported by the IMAP server.</para>
/// <para>-or-</para>
/// <para>The server does not support the ESORT extension.</para>
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="IMailStore"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="IMailStore"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="IMailStore"/> is not authenticated.
/// </exception>
/// <exception cref="FolderNotOpenException">
/// The folder is not currently open.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="ProtocolException">
/// The server's response contained unexpected tokens.
/// </exception>
/// <exception cref="CommandException">
/// The command failed.
/// </exception>
public virtual Task<SearchResults> SearchAsync (SearchOptions options, IList<UniqueId> uids, SearchQuery query, IList<OrderBy> orderBy, CancellationToken cancellationToken = default (CancellationToken))
{
if (uids == null)
throw new ArgumentNullException ("uids");
if (query == null)
throw new ArgumentNullException ("query");
if (orderBy == null)
throw new ArgumentNullException ("orderBy");
if (orderBy.Count == 0)
throw new ArgumentException ("No sort order provided.", "orderBy");
return Task.Factory.StartNew (() => {
lock (SyncRoot) {
return Search (options, uids, query, orderBy, cancellationToken);
}
}, cancellationToken, TaskCreationOptions.None, TaskScheduler.Default);
}
示例8: SearchAsync
public Task<SearchResults> SearchAsync (SearchOptions options, IList<UniqueId> uids, SearchQuery query, IList<OrderBy> orderBy, CancellationToken cancellationToken = default (CancellationToken))
{
return SortAsync (options, uids, query, orderBy, cancellationToken);
}
示例9: SortAsync
/// <summary>
/// Asynchronously sort messages matching the specified query.
/// </summary>
/// <remarks>
/// The returned array of unique identifiers will be sorted in the preferred order and
/// can be used with <see cref="IMailFolder.GetMessage(UniqueId,CancellationToken,ITransferProgress)"/>.
/// </remarks>
/// <returns>An array of matching UIDs in the specified sort order.</returns>
/// <param name="uids">The subset of UIDs</param>
/// <param name="query">The search query.</param>
/// <param name="orderBy">The sort order.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="uids"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="query"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="orderBy"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ArgumentException">
/// <para><paramref name="uids"/> is empty.</para>
/// <para>-or-</para>
/// <para>One or more of the <paramref name="uids"/> is invalid.</para>
/// <para>-or-</para>
/// <para><paramref name="orderBy"/> is empty.</para>
/// </exception>
/// <exception cref="System.NotSupportedException">
/// <para>One or more search terms in the <paramref name="query"/> are not supported.</para>
/// <para>-or-</para>
/// <para>The server does not support sorting search results.</para>
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="IMailStore"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="IMailStore"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="IMailStore"/> is not authenticated.
/// </exception>
/// <exception cref="FolderNotOpenException">
/// The folder is not currently open.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="ProtocolException">
/// The server's response contained unexpected tokens.
/// </exception>
/// <exception cref="CommandException">
/// The command failed.
/// </exception>
public virtual Task<IList<UniqueId>> SortAsync (IList<UniqueId> uids, SearchQuery query, IList<OrderBy> orderBy, CancellationToken cancellationToken = default (CancellationToken))
{
if (uids == null)
throw new ArgumentNullException (nameof (uids));
if (query == null)
throw new ArgumentNullException (nameof (query));
if (orderBy == null)
throw new ArgumentNullException (nameof (orderBy));
if (orderBy.Count == 0)
throw new ArgumentException ("No sort order provided.", nameof (orderBy));
return Task.Factory.StartNew (() => {
lock (SyncRoot) {
return Sort (uids, query, orderBy, cancellationToken);
}
}, cancellationToken, TaskCreationOptions.None, TaskScheduler.Default);
}
示例10: Sort
/// <summary>
/// Sort messages matching the specified query.
/// </summary>
/// <remarks>
/// Searches the folder for messages matching the specified query, returning the search results in the specified sort order.
/// </remarks>
/// <returns>The search results.</returns>
/// <param name="options">The search options.</param>
/// <param name="uids">The subset of UIDs</param>
/// <param name="query">The search query.</param>
/// <param name="orderBy">The sort order.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="uids"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="query"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="orderBy"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ArgumentException">
/// <para><paramref name="uids"/> is empty.</para>
/// <para>-or-</para>
/// <para>One or more of the <paramref name="uids"/> is invalid.</para>
/// <para>-or-</para>
/// <para><paramref name="orderBy"/> is empty.</para>
/// </exception>
/// <exception cref="System.NotSupportedException">
/// <para>One or more search terms in the <paramref name="query"/> are not supported.</para>
/// <para>-or-</para>
/// <para>The server does not support the specified search options.</para>
/// <para>-or-</para>
/// <para>The server does not support sorting search results.</para>
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="IMailStore"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="IMailStore"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="IMailStore"/> is not authenticated.
/// </exception>
/// <exception cref="FolderNotOpenException">
/// The folder is not currently open.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="ProtocolException">
/// The server's response contained unexpected tokens.
/// </exception>
/// <exception cref="CommandException">
/// The command failed.
/// </exception>
public virtual SearchResults Sort (SearchOptions options, IList<UniqueId> uids, SearchQuery query, IList<OrderBy> orderBy, CancellationToken cancellationToken = default (CancellationToken))
{
var uidSet = new UidSearchQuery (uids);
if (query == null)
throw new ArgumentNullException (nameof (query));
return Sort (options, uidSet.And (query), orderBy, cancellationToken);
}
示例11: BuildQueryExpression
string BuildQueryExpression(SearchQuery query, List<string> args)
{
var builder = new StringBuilder ();
BuildQuery (builder, query, args, false);
return builder.ToString ();
}
示例12: BuildQuery
void BuildQuery (StringBuilder builder, SearchQuery query, List<string> args, bool parens, ref bool ascii)
{
TextSearchQuery text = null;
NumericSearchQuery numeric;
HeaderSearchQuery header;
BinarySearchQuery binary;
UnarySearchQuery unary;
DateSearchQuery date;
bool isFlag;
if (builder.Length > 0)
builder.Append (' ');
switch (query.Term) {
case SearchTerm.All:
builder.Append ("ALL");
break;
case SearchTerm.And:
binary = (BinarySearchQuery) query;
if (parens)
builder.Append ('(');
BuildQuery (builder, binary.Left, args, false, ref ascii);
BuildQuery (builder, binary.Right, args, false, ref ascii);
if (parens)
builder.Append (')');
break;
case SearchTerm.Answered:
builder.Append ("ANSWERED");
break;
case SearchTerm.BccContains:
text = (TextSearchQuery) query;
builder.Append ("BCC %S");
args.Add (text.Text);
break;
case SearchTerm.BodyContains:
text = (TextSearchQuery) query;
builder.Append ("BODY %S");
args.Add (text.Text);
break;
case SearchTerm.CcContains:
text = (TextSearchQuery) query;
builder.Append ("CC %S");
args.Add (text.Text);
break;
case SearchTerm.Deleted:
builder.Append ("DELETED");
break;
case SearchTerm.DeliveredAfter:
date = (DateSearchQuery) query;
builder.AppendFormat ("SINCE {0}", FormatDateTime (date.Date));
break;
case SearchTerm.DeliveredBefore:
date = (DateSearchQuery) query;
builder.AppendFormat ("BEFORE {0}", FormatDateTime (date.Date));
break;
case SearchTerm.DeliveredOn:
date = (DateSearchQuery) query;
builder.AppendFormat ("ON {0}", FormatDateTime (date.Date));
break;
case SearchTerm.Draft:
builder.Append ("DRAFT");
break;
case SearchTerm.Flagged:
builder.Append ("FLAGGED");
break;
case SearchTerm.FromContains:
text = (TextSearchQuery) query;
builder.Append ("FROM %S");
args.Add (text.Text);
break;
case SearchTerm.Fuzzy:
if ((Engine.Capabilities & ImapCapabilities.FuzzySearch) == 0)
throw new NotSupportedException ("The FUZZY search term is not supported by the IMAP server.");
builder.Append ("FUZZY");
unary = (UnarySearchQuery) query;
BuildQuery (builder, unary.Operand, args, true, ref ascii);
break;
case SearchTerm.HeaderContains:
header = (HeaderSearchQuery) query;
builder.AppendFormat ("HEADER {0} %S", header.Field);
args.Add (header.Value);
break;
case SearchTerm.Keyword:
text = (TextSearchQuery) query;
builder.Append ("KEYWORD %S");
args.Add (text.Text);
break;
case SearchTerm.LargerThan:
numeric = (NumericSearchQuery) query;
builder.AppendFormat ("LARGER {0}", numeric.Value);
break;
case SearchTerm.MessageContains:
text = (TextSearchQuery) query;
builder.Append ("TEXT %S");
args.Add (text.Text);
break;
case SearchTerm.ModSeq:
numeric = (NumericSearchQuery) query;
builder.AppendFormat ("MODSEQ {0}", numeric.Value);
//.........这里部分代码省略.........
示例13: Thread
/// <summary>
/// Threads the messages in the folder that match the search query using the specified threading algorithm.
/// </summary>
/// <remarks>
/// The <see cref="MessageThread.UniqueId"/> can be used with <see cref="IFolder.GetMessage(UniqueId,CancellationToken)"/>.
/// </remarks>
/// <returns>An array of message threads.</returns>
/// <param name="algorithm">The threading algorithm to use.</param>
/// <param name="query">The search query.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="algorithm"/> is not supported.
/// </exception>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="query"/> is <c>null</c>.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// <para>One or more search terms in the <paramref name="query"/> are not supported by the IMAP server.</para>
/// <para>-or-</para>
/// <para>The server does not support the THREAD extension.</para>
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="ImapClient"/> has been disposed.
/// </exception>
/// <exception cref="System.InvalidOperationException">
/// <para>The <see cref="ImapClient"/> is not connected.</para>
/// <para>-or-</para>
/// <para>The <see cref="ImapClient"/> is not authenticated.</para>
/// <para>-or-</para>
/// <para>The folder is not currently open.</para>
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="ImapProtocolException">
/// The server's response contained unexpected tokens.
/// </exception>
/// <exception cref="ImapCommandException">
/// The server replied with a NO or BAD response.
/// </exception>
public MessageThread[] Thread(ThreadingAlgorithm algorithm, SearchQuery query, CancellationToken cancellationToken)
{
var method = algorithm.ToString ().ToUpperInvariant ();
var args = new List<string> ();
if ((Engine.Capabilities & ImapCapabilities.Thread) == 0)
throw new NotSupportedException ("The IMAP server does not support the THREAD extension.");
if (!Engine.ThreadingAlgorithms.Contains (algorithm))
throw new ArgumentOutOfRangeException ("algorithm", "The specified threading algorithm is not supported.");
if (query == null)
throw new ArgumentNullException ("query");
CheckState (true, false);
var optimized = query.Optimize (new ImapSearchQueryOptimizer ());
var expr = BuildQueryExpression (optimized, args);
var command = "UID THREAD " + method + " UTF-8 ";
command += expr + "\r\n";
var ic = Engine.QueueCommand (cancellationToken, this, command, args.ToArray ());
ic.RegisterUntaggedHandler ("THREAD", ThreadMatches);
Engine.Wait (ic);
ProcessResponseCodes (ic, null);
if (ic.Result != ImapCommandResult.Ok)
throw new ImapCommandException ("THREAD", ic.Result);
return (MessageThread[]) ic.UserData;
}
示例14: BuildQuery
void BuildQuery(StringBuilder builder, SearchQuery query, List<string> args, bool parens)
{
NumericSearchQuery numeric;
HeaderSearchQuery header;
BinarySearchQuery binary;
UnarySearchQuery unary;
DateSearchQuery date;
TextSearchQuery text;
if (builder.Length > 0)
builder.Append (' ');
switch (query.Term) {
case SearchTerm.All:
builder.Append ("ALL");
break;
case SearchTerm.And:
binary = (BinarySearchQuery) query;
if (parens)
builder.Append ('(');
BuildQuery (builder, binary.Left, args, false);
BuildQuery (builder, binary.Right, args, false);
if (parens)
builder.Append (')');
break;
case SearchTerm.Answered:
builder.Append ("ANSWERED");
break;
case SearchTerm.BccContains:
text = (TextSearchQuery) query;
builder.Append ("BCC %S");
args.Add (text.Text);
break;
case SearchTerm.BodyContains:
text = (TextSearchQuery) query;
builder.Append ("BODY %S");
args.Add (text.Text);
break;
case SearchTerm.CcContains:
text = (TextSearchQuery) query;
builder.Append ("CC %S");
args.Add (text.Text);
break;
case SearchTerm.Deleted:
builder.Append ("DELETED");
break;
case SearchTerm.DeliveredAfter:
date = (DateSearchQuery) query;
builder.AppendFormat ("SINCE {0}", date.Date.ToString ("d-MMM-yyyy", CultureInfo.InvariantCulture));
break;
case SearchTerm.DeliveredBefore:
date = (DateSearchQuery) query;
builder.AppendFormat ("BEFORE {0}", date.Date.ToString ("d-MMM-yyyy", CultureInfo.InvariantCulture));
break;
case SearchTerm.DeliveredOn:
date = (DateSearchQuery) query;
builder.AppendFormat ("ON {0}", date.Date.ToString ("d-MMM-yyyy", CultureInfo.InvariantCulture));
break;
case SearchTerm.Draft:
builder.Append ("DRAFT");
break;
case SearchTerm.Flagged:
builder.Append ("FLAGGED");
break;
case SearchTerm.FromContains:
text = (TextSearchQuery) query;
builder.Append ("FROM %S");
args.Add (text.Text);
break;
case SearchTerm.HeaderContains:
header = (HeaderSearchQuery) query;
builder.AppendFormat ("HEADER {0} %S", header.Field);
args.Add (header.Value);
break;
case SearchTerm.Keyword:
text = (TextSearchQuery) query;
builder.Append ("KEYWORD %S");
args.Add (text.Text);
break;
case SearchTerm.LargerThan:
numeric = (NumericSearchQuery) query;
builder.AppendFormat ("LARGER {0}", numeric.Value);
break;
case SearchTerm.MessageContains:
text = (TextSearchQuery) query;
builder.Append ("TEXT %S");
args.Add (text.Text);
break;
case SearchTerm.ModSeq:
numeric = (NumericSearchQuery) query;
builder.AppendFormat ("MODSEQ {0}", numeric.Value);
break;
case SearchTerm.New:
builder.Append ("NEW");
break;
case SearchTerm.Not:
builder.Append ("NOT");
unary = (UnarySearchQuery) query;
BuildQuery (builder, unary.Operand, args, true);
break;
//.........这里部分代码省略.........
示例15: Search
/// <summary>
/// Searches the subset of UIDs in the folder for messages matching the specified query,
/// returning them in the preferred sort order.
/// </summary>
/// <remarks>
/// The returned array of unique identifiers will be sorted in the preferred order and
/// can be used with <see cref="IFolder.GetMessage(UniqueId,CancellationToken)"/>.
/// </remarks>
/// <returns>An array of matching UIDs.</returns>
/// <param name="uids">The subset of UIDs</param>
/// <param name="query">The search query.</param>
/// <param name="orderBy">The sort order.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="uids"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="query"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="orderBy"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ArgumentException">
/// <para><paramref name="uids"/> contains one or more invalid UIDs.</para>
/// <para>-or-</para>
/// <para><paramref name="orderBy"/> is empty.</para>
/// </exception>
/// <exception cref="System.NotSupportedException">
/// <para>One or more search terms in the <paramref name="query"/> are not supported by the IMAP server.</para>
/// <para>-or-</para>
/// <para>The server does not support the SORT extension.</para>
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="ImapClient"/> has been disposed.
/// </exception>
/// <exception cref="System.InvalidOperationException">
/// <para>The <see cref="ImapClient"/> is not connected.</para>
/// <para>-or-</para>
/// <para>The <see cref="ImapClient"/> is not authenticated.</para>
/// <para>-or-</para>
/// <para>The folder is not currently open.</para>
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="ImapProtocolException">
/// The server's response contained unexpected tokens.
/// </exception>
/// <exception cref="ImapCommandException">
/// The server replied with a NO or BAD response.
/// </exception>
public UniqueId[] Search(UniqueId[] uids, SearchQuery query, OrderBy[] orderBy, CancellationToken cancellationToken)
{
var set = ImapUtils.FormatUidSet (uids);
var args = new List<string> ();
if (query == null)
throw new ArgumentNullException ("query");
if (orderBy == null)
throw new ArgumentNullException ("orderBy");
if (orderBy.Length == 0)
throw new ArgumentException ("No sort order provided.", "orderBy");
CheckState (true, false);
if ((Engine.Capabilities & ImapCapabilities.Sort) == 0)
throw new NotSupportedException ("The IMAP server does not support the SORT extension.");
if (uids.Length == 0)
return new UniqueId[0];
var optimized = query.Optimize (new ImapSearchQueryOptimizer ());
var expr = BuildQueryExpression (optimized, args);
var order = BuildSortOrder (orderBy);
var command = "UID SORT " + order + " ";
if ((Engine.Capabilities & ImapCapabilities.ESort) != 0)
command += "RETURN () ";
command += "UTF-8 UID " + set + " " + expr + "\r\n";
var ic = Engine.QueueCommand (cancellationToken, this, command, args.ToArray ());
if ((Engine.Capabilities & ImapCapabilities.ESort) != 0)
ic.RegisterUntaggedHandler ("ESEARCH", ESearchMatches);
else
ic.RegisterUntaggedHandler ("SORT", SearchMatches);
Engine.Wait (ic);
ProcessResponseCodes (ic, null);
if (ic.Result != ImapCommandResult.Ok)
throw new ImapCommandException ("SORT", ic.Result);
return (UniqueId[]) ic.UserData;
}