2889 lines
130 KiB
C#
2889 lines
130 KiB
C#
//
|
|
// ImapFolderFlags.cs
|
|
//
|
|
// Author: Jeffrey Stedfast <jestedfa@microsoft.com>
|
|
//
|
|
// Copyright (c) 2013-2020 .NET Foundation and Contributors
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
// in the Software without restriction, including without limitation the rights
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
// furnished to do so, subject to the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be included in
|
|
// all copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
// THE SOFTWARE.
|
|
//
|
|
|
|
using System;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Globalization;
|
|
using System.Threading.Tasks;
|
|
using System.Collections.Generic;
|
|
|
|
namespace MailKit.Net.Imap
|
|
{
|
|
public partial class ImapFolder
|
|
{
|
|
void ProcessUnmodified (ImapCommand ic, ref UniqueIdSet uids, ulong? modseq)
|
|
{
|
|
if (modseq.HasValue) {
|
|
foreach (var rc in ic.RespCodes.OfType<ModifiedResponseCode> ()) {
|
|
if (uids != null)
|
|
uids.AddRange (rc.UidSet);
|
|
else
|
|
uids = rc.UidSet;
|
|
}
|
|
}
|
|
}
|
|
|
|
IList<int> GetUnmodified (ImapCommand ic, ulong? modseq)
|
|
{
|
|
if (modseq.HasValue) {
|
|
var rc = ic.RespCodes.OfType<ModifiedResponseCode> ().FirstOrDefault ();
|
|
|
|
if (rc != null) {
|
|
var unmodified = new int[rc.UidSet.Count];
|
|
for (int i = 0; i < unmodified.Length; i++)
|
|
unmodified[i] = (int) (rc.UidSet[i].Id - 1);
|
|
|
|
return unmodified;
|
|
}
|
|
}
|
|
|
|
return new int[0];
|
|
}
|
|
|
|
async Task<IList<UniqueId>> ModifyFlagsAsync (IList<UniqueId> uids, ulong? modseq, MessageFlags flags, HashSet<string> keywords, string action, bool doAsync, CancellationToken cancellationToken)
|
|
{
|
|
if (uids == null)
|
|
throw new ArgumentNullException (nameof (uids));
|
|
|
|
if (modseq.HasValue && !supportsModSeq)
|
|
throw new NotSupportedException ("The ImapFolder does not support mod-sequences.");
|
|
|
|
CheckState (true, true);
|
|
|
|
if (uids.Count == 0)
|
|
return new UniqueId[0];
|
|
|
|
var flaglist = ImapUtils.FormatFlagsList (flags & PermanentFlags, keywords != null ? keywords.Count : 0);
|
|
var keywordList = keywords != null ? keywords.ToArray () : new object[0];
|
|
UniqueIdSet unmodified = null;
|
|
var @params = string.Empty;
|
|
|
|
if (modseq.HasValue)
|
|
@params = string.Format (CultureInfo.InvariantCulture, " (UNCHANGEDSINCE {0})", modseq.Value);
|
|
|
|
var command = string.Format ("UID STORE %s{0} {1} {2}\r\n", @params, action, flaglist);
|
|
|
|
foreach (var ic in Engine.QueueCommands (cancellationToken, this, command, uids, keywordList)) {
|
|
await Engine.RunAsync (ic, doAsync).ConfigureAwait (false);
|
|
|
|
ProcessResponseCodes (ic, null);
|
|
|
|
if (ic.Response != ImapCommandResponse.Ok)
|
|
throw ImapCommandException.Create ("STORE", ic);
|
|
|
|
ProcessUnmodified (ic, ref unmodified, modseq);
|
|
}
|
|
|
|
if (unmodified == null)
|
|
return new UniqueId[0];
|
|
|
|
return unmodified;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds a set of flags to the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Adds a set of flags to the specified messages.
|
|
/// </remarks>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="flags">The message flags to add.</param>
|
|
/// <param name="keywords">A set of user-defined flags to add.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="uids"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="uids"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No flags were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </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 override void AddFlags (IList<UniqueId> uids, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
bool emptyUserFlags = keywords == null || keywords.Count == 0;
|
|
|
|
if ((flags & SettableFlags) == 0 && emptyUserFlags)
|
|
throw new ArgumentException ("No flags were specified.", nameof (flags));
|
|
|
|
ModifyFlagsAsync (uids, null, flags, keywords, silent ? "+FLAGS.SILENT" : "+FLAGS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously adds a set of flags to the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Adds a set of flags to the specified messages.
|
|
/// </remarks>
|
|
/// <returns>An asynchronous task context.</returns>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="flags">The message flags to add.</param>
|
|
/// <param name="keywords">A set of user-defined flags to add.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="uids"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="uids"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No flags were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </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 override Task AddFlagsAsync (IList<UniqueId> uids, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
bool emptyUserFlags = keywords == null || keywords.Count == 0;
|
|
|
|
if ((flags & SettableFlags) == 0 && emptyUserFlags)
|
|
throw new ArgumentException ("No flags were specified.", nameof (flags));
|
|
|
|
return ModifyFlagsAsync (uids, null, flags, keywords, silent ? "+FLAGS.SILENT" : "+FLAGS", true, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Removes a set of flags from the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Removes a set of flags from the specified messages.
|
|
/// </remarks>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="flags">The message flags to remove.</param>
|
|
/// <param name="keywords">A set of user-defined flags to remove.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="uids"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="uids"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No flags were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </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 override void RemoveFlags (IList<UniqueId> uids, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if ((flags & SettableFlags) == 0 && (keywords == null || keywords.Count == 0))
|
|
throw new ArgumentException ("No flags were specified.", nameof (flags));
|
|
|
|
ModifyFlagsAsync (uids, null, flags, keywords, silent ? "-FLAGS.SILENT" : "-FLAGS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously removes a set of flags from the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Removes a set of flags from the specified messages.
|
|
/// </remarks>
|
|
/// <returns>An asynchronous task context.</returns>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="flags">The message flags to remove.</param>
|
|
/// <param name="keywords">A set of user-defined flags to remove.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="uids"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="uids"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No flags were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </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 override Task RemoveFlagsAsync (IList<UniqueId> uids, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if ((flags & SettableFlags) == 0 && (keywords == null || keywords.Count == 0))
|
|
throw new ArgumentException ("No flags were specified.", nameof (flags));
|
|
|
|
return ModifyFlagsAsync (uids, null, flags, keywords, silent ? "-FLAGS.SILENT" : "-FLAGS", true, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the flags of the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Sets the flags of the specified messages.
|
|
/// </remarks>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="flags">The message flags to set.</param>
|
|
/// <param name="keywords">A set of user-defined flags to set.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="uids"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// One or more of the <paramref name="uids"/> is invalid.
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </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 override void SetFlags (IList<UniqueId> uids, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
ModifyFlagsAsync (uids, null, flags, keywords, silent ? "FLAGS.SILENT" : "FLAGS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously sets the flags of the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Sets the flags of the specified messages.
|
|
/// </remarks>
|
|
/// <returns>An asynchronous task context.</returns>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="flags">The message flags to set.</param>
|
|
/// <param name="keywords">A set of user-defined flags to set.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="uids"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// One or more of the <paramref name="uids"/> is invalid.
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </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 override Task SetFlagsAsync (IList<UniqueId> uids, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
return ModifyFlagsAsync (uids, null, flags, keywords, silent ? "FLAGS.SILENT" : "FLAGS", true, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds a set of flags to the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Adds a set of flags to the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The unique IDs of the messages that were not updated.</returns>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="flags">The message flags to add.</param>
|
|
/// <param name="keywords">A set of user-defined flags to add.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="uids"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="uids"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No flags were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The <see cref="ImapFolder"/> does not support mod-sequences.
|
|
/// </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 override IList<UniqueId> AddFlags (IList<UniqueId> uids, ulong modseq, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if ((flags & SettableFlags) == 0 && (keywords == null || keywords.Count == 0))
|
|
throw new ArgumentException ("No flags were specified.", nameof (flags));
|
|
|
|
return ModifyFlagsAsync (uids, modseq, flags, keywords, silent ? "+FLAGS.SILENT" : "+FLAGS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously adds a set of flags to the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Adds a set of flags to the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The unique IDs of the messages that were not updated.</returns>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="flags">The message flags to add.</param>
|
|
/// <param name="keywords">A set of user-defined flags to add.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="uids"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="uids"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No flags were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The <see cref="ImapFolder"/> does not support mod-sequences.
|
|
/// </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 override Task<IList<UniqueId>> AddFlagsAsync (IList<UniqueId> uids, ulong modseq, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if ((flags & SettableFlags) == 0 && (keywords == null || keywords.Count == 0))
|
|
throw new ArgumentException ("No flags were specified.", nameof (flags));
|
|
|
|
return ModifyFlagsAsync (uids, modseq, flags, keywords, silent ? "+FLAGS.SILENT" : "+FLAGS", true, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Removes a set of flags from the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Removes a set of flags from the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The unique IDs of the messages that were not updated.</returns>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="flags">The message flags to remove.</param>
|
|
/// <param name="keywords">A set of user-defined flags to remove.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="uids"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="uids"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No flags were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The <see cref="ImapFolder"/> does not support mod-sequences.
|
|
/// </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 override IList<UniqueId> RemoveFlags (IList<UniqueId> uids, ulong modseq, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if ((flags & SettableFlags) == 0 && (keywords == null || keywords.Count == 0))
|
|
throw new ArgumentException ("No flags were specified.", nameof (flags));
|
|
|
|
return ModifyFlagsAsync (uids, modseq, flags, keywords, silent ? "-FLAGS.SILENT" : "-FLAGS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously removes a set of flags from the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Removes a set of flags from the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The unique IDs of the messages that were not updated.</returns>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="flags">The message flags to remove.</param>
|
|
/// <param name="keywords">A set of user-defined flags to remove.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="uids"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="uids"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No flags were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The <see cref="ImapFolder"/> does not support mod-sequences.
|
|
/// </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 override Task<IList<UniqueId>> RemoveFlagsAsync (IList<UniqueId> uids, ulong modseq, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if ((flags & SettableFlags) == 0 && (keywords == null || keywords.Count == 0))
|
|
throw new ArgumentException ("No flags were specified.", nameof (flags));
|
|
|
|
return ModifyFlagsAsync (uids, modseq, flags, keywords, silent ? "-FLAGS.SILENT" : "-FLAGS", true, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the flags of the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Sets the flags of the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The unique IDs of the messages that were not updated.</returns>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="flags">The message flags to set.</param>
|
|
/// <param name="keywords">A set of user-defined flags to set.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="uids"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="uids"/> is invalid.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The <see cref="ImapFolder"/> does not support mod-sequences.
|
|
/// </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 override IList<UniqueId> SetFlags (IList<UniqueId> uids, ulong modseq, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
return ModifyFlagsAsync (uids, modseq, flags, keywords, silent ? "FLAGS.SILENT" : "FLAGS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously sets the flags of the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Sets the flags of the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The unique IDs of the messages that were not updated.</returns>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="flags">The message flags to set.</param>
|
|
/// <param name="keywords">A set of user-defined flags to set.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="uids"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="uids"/> is invalid.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The <see cref="ImapFolder"/> does not support mod-sequences.
|
|
/// </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 override Task<IList<UniqueId>> SetFlagsAsync (IList<UniqueId> uids, ulong modseq, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
return ModifyFlagsAsync (uids, modseq, flags, keywords, silent ? "FLAGS.SILENT" : "FLAGS", true, cancellationToken);
|
|
}
|
|
|
|
async Task<IList<int>> ModifyFlagsAsync (IList<int> indexes, ulong? modseq, MessageFlags flags, HashSet<string> keywords, string action, bool doAsync, CancellationToken cancellationToken)
|
|
{
|
|
if (indexes == null)
|
|
throw new ArgumentNullException (nameof (indexes));
|
|
|
|
if (modseq.HasValue && !supportsModSeq)
|
|
throw new NotSupportedException ("The ImapFolder does not support mod-sequences.");
|
|
|
|
CheckState (true, true);
|
|
|
|
if (indexes.Count == 0)
|
|
return new int[0];
|
|
|
|
var flaglist = ImapUtils.FormatFlagsList (flags & PermanentFlags, keywords != null ? keywords.Count : 0);
|
|
var keywordList = keywords != null ? keywords.ToArray () : new object [0];
|
|
var set = ImapUtils.FormatIndexSet (indexes);
|
|
var @params = string.Empty;
|
|
|
|
if (modseq.HasValue)
|
|
@params = string.Format (CultureInfo.InvariantCulture, " (UNCHANGEDSINCE {0})", modseq.Value);
|
|
|
|
var format = string.Format ("STORE {0}{1} {2} {3}\r\n", set, @params, action, flaglist);
|
|
var ic = Engine.QueueCommand (cancellationToken, this, format, keywordList);
|
|
|
|
await Engine.RunAsync (ic, doAsync).ConfigureAwait (false);
|
|
|
|
ProcessResponseCodes (ic, null);
|
|
|
|
if (ic.Response != ImapCommandResponse.Ok)
|
|
throw ImapCommandException.Create ("STORE", ic);
|
|
|
|
return GetUnmodified (ic, modseq);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds a set of flags to the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Adds a set of flags to the specified messages.
|
|
/// </remarks>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="flags">The message flags to add.</param>
|
|
/// <param name="keywords">A set of user-defined flags to add.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="indexes"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="indexes"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No flags were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </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 override void AddFlags (IList<int> indexes, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if ((flags & SettableFlags) == 0 && (keywords == null || keywords.Count == 0))
|
|
throw new ArgumentException ("No flags were specified.", nameof (flags));
|
|
|
|
ModifyFlagsAsync (indexes, null, flags, keywords, silent ? "+FLAGS.SILENT" : "+FLAGS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously adds a set of flags to the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Adds a set of flags to the specified messages.
|
|
/// </remarks>
|
|
/// <returns>An asynchronous task context.</returns>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="flags">The message flags to add.</param>
|
|
/// <param name="keywords">A set of user-defined flags to add.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="indexes"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="indexes"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No flags were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </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 override Task AddFlagsAsync (IList<int> indexes, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if ((flags & SettableFlags) == 0 && (keywords == null || keywords.Count == 0))
|
|
throw new ArgumentException ("No flags were specified.", nameof (flags));
|
|
|
|
return ModifyFlagsAsync (indexes, null, flags, keywords, silent ? "+FLAGS.SILENT" : "+FLAGS", true, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Removes a set of flags from the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Removes a set of flags from the specified messages.
|
|
/// </remarks>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="flags">The message flags to remove.</param>
|
|
/// <param name="keywords">A set of user-defined flags to remove.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="indexes"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="indexes"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No flags were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </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 override void RemoveFlags (IList<int> indexes, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if ((flags & SettableFlags) == 0 && (keywords == null || keywords.Count == 0))
|
|
throw new ArgumentException ("No flags were specified.", nameof (flags));
|
|
|
|
ModifyFlagsAsync (indexes, null, flags, keywords, silent ? "-FLAGS.SILENT" : "-FLAGS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously removes a set of flags from the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Removes a set of flags from the specified messages.
|
|
/// </remarks>
|
|
/// <returns>An asynchronous task context.</returns>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="flags">The message flags to remove.</param>
|
|
/// <param name="keywords">A set of user-defined flags to remove.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="indexes"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="indexes"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No flags were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </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 override Task RemoveFlagsAsync (IList<int> indexes, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if ((flags & SettableFlags) == 0 && (keywords == null || keywords.Count == 0))
|
|
throw new ArgumentException ("No flags were specified.", nameof (flags));
|
|
|
|
return ModifyFlagsAsync (indexes, null, flags, keywords, silent ? "-FLAGS.SILENT" : "-FLAGS", true, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the flags of the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Sets the flags of the specified messages.
|
|
/// </remarks>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="flags">The message flags to set.</param>
|
|
/// <param name="keywords">A set of user-defined flags to set.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="indexes"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// One or more of the <paramref name="indexes"/> is invalid.
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </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 override void SetFlags (IList<int> indexes, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
ModifyFlagsAsync (indexes, null, flags, keywords, silent ? "FLAGS.SILENT" : "FLAGS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously sets the flags of the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Sets the flags of the specified messages.
|
|
/// </remarks>
|
|
/// <returns>An asynchronous task context.</returns>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="flags">The message flags to set.</param>
|
|
/// <param name="keywords">A set of user-defined flags to set.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="indexes"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// One or more of the <paramref name="indexes"/> is invalid.
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </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 override Task SetFlagsAsync (IList<int> indexes, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
return ModifyFlagsAsync (indexes, null, flags, keywords, silent ? "FLAGS.SILENT" : "FLAGS", true, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds a set of flags to the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Adds a set of flags to the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The indexes of the messages that were not updated.</returns>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="flags">The message flags to add.</param>
|
|
/// <param name="keywords">A set of user-defined flags to add.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="indexes"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="indexes"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No flags were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The <see cref="ImapFolder"/> does not support mod-sequences.
|
|
/// </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 override IList<int> AddFlags (IList<int> indexes, ulong modseq, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if ((flags & SettableFlags) == 0 && (keywords == null || keywords.Count == 0))
|
|
throw new ArgumentException ("No flags were specified.", nameof (flags));
|
|
|
|
return ModifyFlagsAsync (indexes, modseq, flags, keywords, silent ? "+FLAGS.SILENT" : "+FLAGS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously adds a set of flags to the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Adds a set of flags to the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The indexes of the messages that were not updated.</returns>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="flags">The message flags to add.</param>
|
|
/// <param name="keywords">A set of user-defined flags to add.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="indexes"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="indexes"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No flags were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The <see cref="ImapFolder"/> does not support mod-sequences.
|
|
/// </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 override Task<IList<int>> AddFlagsAsync (IList<int> indexes, ulong modseq, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if ((flags & SettableFlags) == 0 && (keywords == null || keywords.Count == 0))
|
|
throw new ArgumentException ("No flags were specified.", nameof (flags));
|
|
|
|
return ModifyFlagsAsync (indexes, modseq, flags, keywords, silent ? "+FLAGS.SILENT" : "+FLAGS", true, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Removes a set of flags from the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Removes a set of flags from the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The indexes of the messages that were not updated.</returns>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="flags">The message flags to remove.</param>
|
|
/// <param name="keywords">A set of user-defined flags to remove.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="indexes"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="indexes"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No flags were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The <see cref="ImapFolder"/> does not support mod-sequences.
|
|
/// </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 override IList<int> RemoveFlags (IList<int> indexes, ulong modseq, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if ((flags & SettableFlags) == 0 && (keywords == null || keywords.Count == 0))
|
|
throw new ArgumentException ("No flags were specified.", nameof (flags));
|
|
|
|
return ModifyFlagsAsync (indexes, modseq, flags, keywords, silent ? "-FLAGS.SILENT" : "-FLAGS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously removes a set of flags from the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Removes a set of flags from the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The indexes of the messages that were not updated.</returns>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="flags">The message flags to remove.</param>
|
|
/// <param name="keywords">A set of user-defined flags to remove.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="indexes"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="indexes"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No flags were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The <see cref="ImapFolder"/> does not support mod-sequences.
|
|
/// </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 override Task<IList<int>> RemoveFlagsAsync (IList<int> indexes, ulong modseq, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if ((flags & SettableFlags) == 0 && (keywords == null || keywords.Count == 0))
|
|
throw new ArgumentException ("No flags were specified.", nameof (flags));
|
|
|
|
return ModifyFlagsAsync (indexes, modseq, flags, keywords, silent ? "-FLAGS.SILENT" : "-FLAGS", true, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the flags of the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Sets the flags of the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The indexes of the messages that were not updated.</returns>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="flags">The message flags to set.</param>
|
|
/// <param name="keywords">A set of user-defined flags to set.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="indexes"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// One or more of the <paramref name="indexes"/> is invalid.
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The <see cref="ImapFolder"/> does not support mod-sequences.
|
|
/// </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 override IList<int> SetFlags (IList<int> indexes, ulong modseq, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
return ModifyFlagsAsync (indexes, modseq, flags, keywords, silent ? "FLAGS.SILENT" : "FLAGS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously sets the flags of the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Sets the flags of the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The indexes of the messages that were not updated.</returns>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="flags">The message flags to set.</param>
|
|
/// <param name="keywords">A set of user-defined flags to set.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageFlagsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <paramref name="indexes"/> is <c>null</c>.
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// One or more of the <paramref name="indexes"/> is invalid.
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The <see cref="ImapFolder"/> does not support mod-sequences.
|
|
/// </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 override Task<IList<int>> SetFlagsAsync (IList<int> indexes, ulong modseq, MessageFlags flags, HashSet<string> keywords, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
return ModifyFlagsAsync (indexes, modseq, flags, keywords, silent ? "FLAGS.SILENT" : "FLAGS", true, cancellationToken);
|
|
}
|
|
|
|
string LabelListToString (IList<string> labels, ICollection<object> args)
|
|
{
|
|
var list = new StringBuilder ("(");
|
|
|
|
for (int i = 0; i < labels.Count; i++) {
|
|
if (i > 0)
|
|
list.Append (' ');
|
|
|
|
if (labels[i] == null) {
|
|
list.Append ("NIL");
|
|
continue;
|
|
}
|
|
|
|
switch (labels[i]) {
|
|
case "\\AllMail":
|
|
case "\\Drafts":
|
|
case "\\Important":
|
|
case "\\Inbox":
|
|
case "\\Spam":
|
|
case "\\Sent":
|
|
case "\\Starred":
|
|
case "\\Trash":
|
|
list.Append (labels[i]);
|
|
break;
|
|
default:
|
|
list.Append ("%S");
|
|
args.Add (Engine.EncodeMailboxName (labels[i]));
|
|
break;
|
|
}
|
|
}
|
|
|
|
list.Append (')');
|
|
|
|
return list.ToString ();
|
|
}
|
|
|
|
async Task<IList<UniqueId>> ModifyLabelsAsync (IList<UniqueId> uids, ulong? modseq, IList<string> labels, string action, bool doAsync, CancellationToken cancellationToken)
|
|
{
|
|
if (uids == null)
|
|
throw new ArgumentNullException (nameof (uids));
|
|
|
|
if ((Engine.Capabilities & ImapCapabilities.GMailExt1) == 0)
|
|
throw new NotSupportedException ("The IMAP server does not support the Google Mail extensions.");
|
|
|
|
CheckState (true, true);
|
|
|
|
if (uids.Count == 0)
|
|
return new UniqueId[0];
|
|
|
|
var @params = string.Empty;
|
|
|
|
if (modseq.HasValue)
|
|
@params = string.Format (CultureInfo.InvariantCulture, " (UNCHANGEDSINCE {0})", modseq.Value);
|
|
|
|
var args = new List<object> ();
|
|
var list = LabelListToString (labels, args);
|
|
var command = string.Format ("UID STORE %s{0} {1} {2}\r\n", @params, action, list);
|
|
UniqueIdSet unmodified = null;
|
|
|
|
foreach (var ic in Engine.QueueCommands (cancellationToken, this, command, uids, args.ToArray ())) {
|
|
await Engine.RunAsync (ic, doAsync).ConfigureAwait (false);
|
|
|
|
ProcessResponseCodes (ic, null);
|
|
|
|
if (ic.Response != ImapCommandResponse.Ok)
|
|
throw ImapCommandException.Create ("STORE", ic);
|
|
|
|
ProcessUnmodified (ic, ref unmodified, modseq);
|
|
}
|
|
|
|
if (unmodified == null)
|
|
return new UniqueId[0];
|
|
|
|
return unmodified;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add a set of labels to the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Adds a set of labels to the specified messages.
|
|
/// </remarks>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="labels">The labels to add.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</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="labels"/> 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>No labels were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override void AddLabels (IList<UniqueId> uids, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
if (labels.Count == 0)
|
|
throw new ArgumentException ("No labels were specified.", nameof (labels));
|
|
|
|
ModifyLabelsAsync (uids, null, labels, silent ? "+X-GM-LABELS.SILENT" : "+X-GM-LABELS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously add a set of labels to the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Adds a set of labels to the specified messages.
|
|
/// </remarks>
|
|
/// <returns>An asynchronous task context.</returns>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="labels">The labels to add.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</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="labels"/> 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>No labels were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override Task AddLabelsAsync (IList<UniqueId> uids, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
if (labels.Count == 0)
|
|
throw new ArgumentException ("No labels were specified.", nameof (labels));
|
|
|
|
return ModifyLabelsAsync (uids, null, labels, silent ? "+X-GM-LABELS.SILENT" : "+X-GM-LABELS", true, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove a set of labels from the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Removes a set of labels from the specified messages.
|
|
/// </remarks>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="labels">The labels to remove.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</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="labels"/> 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>No labels were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override void RemoveLabels (IList<UniqueId> uids, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
if (labels.Count == 0)
|
|
throw new ArgumentException ("No labels were specified.", nameof (labels));
|
|
|
|
ModifyLabelsAsync (uids, null, labels, silent ? "-X-GM-LABELS.SILENT" : "-X-GM-LABELS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously remove a set of labels from the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Removes a set of labels from the specified messages.
|
|
/// </remarks>
|
|
/// <returns>An asynchronous task context.</returns>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="labels">The labels to remove.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</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="labels"/> 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>No labels were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override Task RemoveLabelsAsync (IList<UniqueId> uids, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
if (labels.Count == 0)
|
|
throw new ArgumentException ("No labels were specified.", nameof (labels));
|
|
|
|
return ModifyLabelsAsync (uids, null, labels, silent ? "-X-GM-LABELS.SILENT" : "-X-GM-LABELS", true, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set the labels of the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Sets the labels of the specified messages.
|
|
/// </remarks>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="labels">The labels to set.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</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="labels"/> is <c>null</c>.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// One or more of the <paramref name="uids"/> is invalid.
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override void SetLabels (IList<UniqueId> uids, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
ModifyLabelsAsync (uids, null, labels, silent ? "X-GM-LABELS.SILENT" : "X-GM-LABELS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously set the labels of the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Sets the labels of the specified messages.
|
|
/// </remarks>
|
|
/// <returns>An asynchronous task context.</returns>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="labels">The labels to set.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</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="labels"/> is <c>null</c>.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// One or more of the <paramref name="uids"/> is invalid.
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override Task SetLabelsAsync (IList<UniqueId> uids, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
return ModifyLabelsAsync (uids, null, labels, silent ? "X-GM-LABELS.SILENT" : "X-GM-LABELS", true, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add a set of labels to the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Adds a set of labels to the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The unique IDs of the messages that were not updated.</returns>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="labels">The labels to add.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</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="labels"/> 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>No labels were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override IList<UniqueId> AddLabels (IList<UniqueId> uids, ulong modseq, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
if (labels.Count == 0)
|
|
throw new ArgumentException ("No labels were specified.", nameof (labels));
|
|
|
|
return ModifyLabelsAsync (uids, modseq, labels, silent ? "+X-GM-LABELS.SILENT" : "+X-GM-LABELS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously add a set of labels to the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Adds a set of labels to the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The unique IDs of the messages that were not updated.</returns>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="labels">The labels to add.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</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="labels"/> 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>No labels were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override Task<IList<UniqueId>> AddLabelsAsync (IList<UniqueId> uids, ulong modseq, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
if (labels.Count == 0)
|
|
throw new ArgumentException ("No labels were specified.", nameof (labels));
|
|
|
|
return ModifyLabelsAsync (uids, modseq, labels, silent ? "+X-GM-LABELS.SILENT" : "+X-GM-LABELS", true, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove a set of labels from the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Removes a set of labels from the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The unique IDs of the messages that were not updated.</returns>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="labels">The labels to remove.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</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="labels"/> 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>No labels were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override IList<UniqueId> RemoveLabels (IList<UniqueId> uids, ulong modseq, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
if (labels.Count == 0)
|
|
throw new ArgumentException ("No labels were specified.", nameof (labels));
|
|
|
|
return ModifyLabelsAsync (uids, modseq, labels, silent ? "-X-GM-LABELS.SILENT" : "-X-GM-LABELS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously remove a set of labels from the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Removes a set of labels from the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The unique IDs of the messages that were not updated.</returns>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="labels">The labels to remove.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</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="labels"/> 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>No labels were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override Task<IList<UniqueId>> RemoveLabelsAsync (IList<UniqueId> uids, ulong modseq, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
if (labels.Count == 0)
|
|
throw new ArgumentException ("No labels were specified.", nameof (labels));
|
|
|
|
return ModifyLabelsAsync (uids, modseq, labels, silent ? "-X-GM-LABELS.SILENT" : "-X-GM-LABELS", true, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set the labels of the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Sets the labels of the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The unique IDs of the messages that were not updated.</returns>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="labels">The labels to set.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</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="labels"/> is <c>null</c>.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// One or more of the <paramref name="uids"/> is invalid.
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override IList<UniqueId> SetLabels (IList<UniqueId> uids, ulong modseq, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
return ModifyLabelsAsync (uids, modseq, labels, silent ? "X-GM-LABELS.SILENT" : "X-GM-LABELS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously set the labels of the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Sets the labels of the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The unique IDs of the messages that were not updated.</returns>
|
|
/// <param name="uids">The UIDs of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="labels">The labels to set.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</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="labels"/> is <c>null</c>.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// One or more of the <paramref name="uids"/> is invalid.
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override Task<IList<UniqueId>> SetLabelsAsync (IList<UniqueId> uids, ulong modseq, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
return ModifyLabelsAsync (uids, modseq, labels, silent ? "X-GM-LABELS.SILENT" : "X-GM-LABELS", true, cancellationToken);
|
|
}
|
|
|
|
async Task<IList<int>> ModifyLabelsAsync (IList<int> indexes, ulong? modseq, IList<string> labels, string action, bool doAsync, CancellationToken cancellationToken)
|
|
{
|
|
if (indexes == null)
|
|
throw new ArgumentNullException (nameof (indexes));
|
|
|
|
if ((Engine.Capabilities & ImapCapabilities.GMailExt1) == 0)
|
|
throw new NotSupportedException ("The IMAP server does not support the Google Mail extensions.");
|
|
|
|
CheckState (true, true);
|
|
|
|
if (indexes.Count == 0)
|
|
return new int[0];
|
|
|
|
var set = ImapUtils.FormatIndexSet (indexes);
|
|
var @params = string.Empty;
|
|
|
|
if (modseq.HasValue)
|
|
@params = string.Format (CultureInfo.InvariantCulture, " (UNCHANGEDSINCE {0})", modseq.Value);
|
|
|
|
var args = new List<object> ();
|
|
var list = LabelListToString (labels, args);
|
|
var format = string.Format ("STORE {0}{1} {2} {3}\r\n", set, @params, action, list);
|
|
var ic = Engine.QueueCommand (cancellationToken, this, format, args.ToArray ());
|
|
|
|
await Engine.RunAsync (ic, doAsync).ConfigureAwait (false);
|
|
|
|
ProcessResponseCodes (ic, null);
|
|
|
|
if (ic.Response != ImapCommandResponse.Ok)
|
|
throw ImapCommandException.Create ("STORE", ic);
|
|
|
|
return GetUnmodified (ic, modseq);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add a set of labels to the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Adds a set of labels to the specified messages.
|
|
/// </remarks>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="labels">The labels to add.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <para><paramref name="indexes"/> is <c>null</c>.</para>
|
|
/// <para>-or-</para>
|
|
/// <para><paramref name="labels"/> is <c>null</c>.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="indexes"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No labels were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override void AddLabels (IList<int> indexes, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
if (labels.Count == 0)
|
|
throw new ArgumentException ("No labels were specified.", nameof (labels));
|
|
|
|
ModifyLabelsAsync (indexes, null, labels, silent ? "+X-GM-LABELS.SILENT" : "+X-GM-LABELS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously add a set of labels to the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Adds a set of labels to the specified messages.
|
|
/// </remarks>
|
|
/// <returns>An asynchronous task context.</returns>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="labels">The labels to add.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <para><paramref name="indexes"/> is <c>null</c>.</para>
|
|
/// <para>-or-</para>
|
|
/// <para><paramref name="labels"/> is <c>null</c>.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="indexes"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No labels were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override Task AddLabelsAsync (IList<int> indexes, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
if (labels.Count == 0)
|
|
throw new ArgumentException ("No labels were specified.", nameof (labels));
|
|
|
|
return ModifyLabelsAsync (indexes, null, labels, silent ? "+X-GM-LABELS.SILENT" : "+X-GM-LABELS", true, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove a set of labels from the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Removes a set of labels from the specified messages.
|
|
/// </remarks>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="labels">The labels to remove.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <para><paramref name="indexes"/> is <c>null</c>.</para>
|
|
/// <para>-or-</para>
|
|
/// <para><paramref name="labels"/> is <c>null</c>.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="indexes"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No labels were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override void RemoveLabels (IList<int> indexes, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
if (labels.Count == 0)
|
|
throw new ArgumentException ("No labels were specified.", nameof (labels));
|
|
|
|
ModifyLabelsAsync (indexes, null, labels, silent ? "-X-GM-LABELS.SILENT" : "-X-GM-LABELS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously remove a set of labels from the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Removes a set of labels from the specified messages.
|
|
/// </remarks>
|
|
/// <returns>An asynchronous task context.</returns>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="labels">The labels to remove.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <para><paramref name="indexes"/> is <c>null</c>.</para>
|
|
/// <para>-or-</para>
|
|
/// <para><paramref name="labels"/> is <c>null</c>.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="indexes"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No labels were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override Task RemoveLabelsAsync (IList<int> indexes, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
if (labels.Count == 0)
|
|
throw new ArgumentException ("No labels were specified.", nameof (labels));
|
|
|
|
return ModifyLabelsAsync (indexes, null, labels, silent ? "-X-GM-LABELS.SILENT" : "-X-GM-LABELS", true, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the labels of the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Sets the labels of the specified messages.
|
|
/// </remarks>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="labels">The labels to set.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <para><paramref name="indexes"/> is <c>null</c>.</para>
|
|
/// <para>-or-</para>
|
|
/// <para><paramref name="labels"/> is <c>null</c>.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// One or more of the <paramref name="indexes"/> is invalid.
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override void SetLabels (IList<int> indexes, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
ModifyLabelsAsync (indexes, null, labels, silent ? "X-GM-LABELS.SILENT" : "X-GM-LABELS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously sets the labels of the specified messages.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Sets the labels of the specified messages.
|
|
/// </remarks>
|
|
/// <returns>An asynchronous task context.</returns>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="labels">The labels to set.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <para><paramref name="indexes"/> is <c>null</c>.</para>
|
|
/// <para>-or-</para>
|
|
/// <para><paramref name="labels"/> is <c>null</c>.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// One or more of the <paramref name="indexes"/> is invalid.
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override Task SetLabelsAsync (IList<int> indexes, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
return ModifyLabelsAsync (indexes, null, labels, silent ? "X-GM-LABELS.SILENT" : "X-GM-LABELS", true, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add a set of labels to the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Adds a set of labels to the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The indexes of the messages that were not updated.</returns>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="labels">The labels to add.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <para><paramref name="indexes"/> is <c>null</c>.</para>
|
|
/// <para>-or-</para>
|
|
/// <para><paramref name="labels"/> is <c>null</c>.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="indexes"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No labels were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override IList<int> AddLabels (IList<int> indexes, ulong modseq, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
if (labels.Count == 0)
|
|
throw new ArgumentException ("No labels were specified.", nameof (labels));
|
|
|
|
return ModifyLabelsAsync (indexes, modseq, labels, silent ? "+X-GM-LABELS.SILENT" : "+X-GM-LABELS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously add a set of labels to the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Adds a set of labels to the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The indexes of the messages that were not updated.</returns>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="labels">The labels to add.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <para><paramref name="indexes"/> is <c>null</c>.</para>
|
|
/// <para>-or-</para>
|
|
/// <para><paramref name="labels"/> is <c>null</c>.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="indexes"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No labels were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override Task<IList<int>> AddLabelsAsync (IList<int> indexes, ulong modseq, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
if (labels.Count == 0)
|
|
throw new ArgumentException ("No labels were specified.", nameof (labels));
|
|
|
|
return ModifyLabelsAsync (indexes, modseq, labels, silent ? "+X-GM-LABELS.SILENT" : "+X-GM-LABELS", true, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove a set of labels from the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Removes a set of labels from the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The indexes of the messages that were not updated.</returns>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="labels">The labels to remove.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <para><paramref name="indexes"/> is <c>null</c>.</para>
|
|
/// <para>-or-</para>
|
|
/// <para><paramref name="labels"/> is <c>null</c>.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="indexes"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No labels were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override IList<int> RemoveLabels (IList<int> indexes, ulong modseq, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
if (labels.Count == 0)
|
|
throw new ArgumentException ("No labels were specified.", nameof (labels));
|
|
|
|
return ModifyLabelsAsync (indexes, modseq, labels, silent ? "-X-GM-LABELS.SILENT" : "-X-GM-LABELS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously remove a set of labels from the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Removes a set of labels from the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The indexes of the messages that were not updated.</returns>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="labels">The labels to remove.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <para><paramref name="indexes"/> is <c>null</c>.</para>
|
|
/// <para>-or-</para>
|
|
/// <para><paramref name="labels"/> is <c>null</c>.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// <para>One or more of the <paramref name="indexes"/> is invalid.</para>
|
|
/// <para>-or-</para>
|
|
/// <para>No labels were specified.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override Task<IList<int>> RemoveLabelsAsync (IList<int> indexes, ulong modseq, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
if (labels.Count == 0)
|
|
throw new ArgumentException ("No labels were specified.", nameof (labels));
|
|
|
|
return ModifyLabelsAsync (indexes, modseq, labels, silent ? "-X-GM-LABELS.SILENT" : "-X-GM-LABELS", true, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set the labels of the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Sets the labels of the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The indexes of the messages that were not updated.</returns>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="labels">The labels to set.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <para><paramref name="indexes"/> is <c>null</c>.</para>
|
|
/// <para>-or-</para>
|
|
/// <para><paramref name="labels"/> is <c>null</c>.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// One or more of the <paramref name="indexes"/> is invalid.
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override IList<int> SetLabels (IList<int> indexes, ulong modseq, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
return ModifyLabelsAsync (indexes, modseq, labels, silent ? "X-GM-LABELS.SILENT" : "X-GM-LABELS", false, cancellationToken).GetAwaiter ().GetResult ();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asynchronously set the labels of the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Sets the labels of the specified messages only if their mod-sequence value is less than the specified value.
|
|
/// </remarks>
|
|
/// <returns>The indexes of the messages that were not updated.</returns>
|
|
/// <param name="indexes">The indexes of the messages.</param>
|
|
/// <param name="modseq">The mod-sequence value.</param>
|
|
/// <param name="labels">The labels to set.</param>
|
|
/// <param name="silent">If set to <c>true</c>, no <see cref="MailFolder.MessageLabelsChanged"/> events will be emitted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <exception cref="System.ArgumentNullException">
|
|
/// <para><paramref name="indexes"/> is <c>null</c>.</para>
|
|
/// <para>-or-</para>
|
|
/// <para><paramref name="labels"/> is <c>null</c>.</para>
|
|
/// </exception>
|
|
/// <exception cref="System.ArgumentException">
|
|
/// One or more of the <paramref name="indexes"/> is invalid.
|
|
/// </exception>
|
|
/// <exception cref="System.ObjectDisposedException">
|
|
/// The <see cref="ImapClient"/> has been disposed.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotConnectedException">
|
|
/// The <see cref="ImapClient"/> is not connected.
|
|
/// </exception>
|
|
/// <exception cref="ServiceNotAuthenticatedException">
|
|
/// The <see cref="ImapClient"/> is not authenticated.
|
|
/// </exception>
|
|
/// <exception cref="FolderNotOpenException">
|
|
/// The <see cref="ImapFolder"/> is not currently open in read-write mode.
|
|
/// </exception>
|
|
/// <exception cref="System.NotSupportedException">
|
|
/// The IMAP server does not support the Google Mail Extensions.
|
|
/// </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 override Task<IList<int>> SetLabelsAsync (IList<int> indexes, ulong modseq, IList<string> labels, bool silent, CancellationToken cancellationToken = default (CancellationToken))
|
|
{
|
|
if (labels == null)
|
|
throw new ArgumentNullException (nameof (labels));
|
|
|
|
return ModifyLabelsAsync (indexes, modseq, labels, silent ? "X-GM-LABELS.SILENT" : "X-GM-LABELS", true, cancellationToken);
|
|
}
|
|
}
|
|
}
|