async Task <IList <UniqueId> > StoreAsync(IList <UniqueId> uids, IStoreFlagsRequest request, bool doAsync, CancellationToken cancellationToken) { if (uids == null) { throw new ArgumentNullException(nameof(uids)); } if (request == null) { throw new ArgumentNullException(nameof(request)); } if (request.UnchangedSince.HasValue && !supportsModSeq) { throw new NotSupportedException("The ImapFolder does not support mod-sequences."); } CheckState(true, true); if (uids.Count == 0) { return(new UniqueId[0]); } int numKeywords = request.Keywords != null ? request.Keywords.Count : 0; string action; switch (request.Action) { case StoreAction.Add: if ((request.Flags & SettableFlags) == 0 && numKeywords == 0) { return(new UniqueId[0]); } action = request.Silent ? "+FLAGS.SILENT" : "+FLAGS"; break; case StoreAction.Remove: if ((request.Flags & SettableFlags) == 0 && numKeywords == 0) { return(new UniqueId[0]); } action = request.Silent ? "-FLAGS.SILENT" : "-FLAGS"; break; default: action = request.Silent ? "FLAGS.SILENT" : "FLAGS"; break; } var flaglist = ImapUtils.FormatFlagsList(request.Flags & PermanentFlags, request.Keywords != null ? request.Keywords.Count : 0); var keywordList = request.Keywords != null?request.Keywords.ToArray() : new object[0]; UniqueIdSet unmodified = null; var @params = string.Empty; if (request.UnchangedSince.HasValue) { @params = string.Format(CultureInfo.InvariantCulture, " (UNCHANGEDSINCE {0})", request.UnchangedSince.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, request.UnchangedSince); } if (unmodified == null) { return(new UniqueId[0]); } return(unmodified); }
/// <summary> /// Asynchronously store message flags and keywords for a set of messages. /// </summary> /// <remarks> /// Asynchronously updates the message flags and keywords for a set of messages. /// </remarks> /// <returns>The indexes of the messages that were not updated.</returns> /// <param name="indexes">The message indexes.</param> /// <param name="request">The message flags and keywords to store.</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="request"/> 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 <paramref name="request"/> specified an <see cref="IStoreRequest.UnchangedSince"/> value /// but 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> > StoreAsync(IList <int> indexes, IStoreFlagsRequest request, CancellationToken cancellationToken = default(CancellationToken)) { return(StoreAsync(indexes, request, true, cancellationToken)); }
/// <summary> /// Asynchronously store message flags and keywords for a set of messages. /// </summary> /// <remarks> /// Asynchronously updates the message flags and keywords for a set of messages. /// </remarks> /// <returns>The UIDs of the messages that were not updated.</returns> /// <param name="uids">The message UIDs.</param> /// <param name="request">The message flags and keywords to store.</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="request"/> 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 <paramref name="request"/> specified an <see cref="IStoreRequest.UnchangedSince"/> value /// but 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> > StoreAsync(IList <UniqueId> uids, IStoreFlagsRequest request, CancellationToken cancellationToken = default(CancellationToken)) { return(StoreAsync(uids, request, true, cancellationToken)); }
/// <summary> /// Store message flags and keywords for a set of messages. /// </summary> /// <remarks> /// Updates the message flags and keywords for a set of message. /// </remarks> /// <returns>The indexes of the messages that were not updated.</returns> /// <param name="indexes">The message indexes.</param> /// <param name="request">The message flags and keywords to store.</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="request"/> 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 <paramref name="request"/> specified an <see cref="IStoreRequest.UnchangedSince"/> value /// but 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> Store(IList <int> indexes, IStoreFlagsRequest request, CancellationToken cancellationToken = default(CancellationToken)) { return(StoreAsync(indexes, request, false, cancellationToken).GetAwaiter().GetResult()); }
async Task <IList <int> > StoreAsync(IList <int> indexes, IStoreFlagsRequest request, bool doAsync, CancellationToken cancellationToken) { if (indexes == null) { throw new ArgumentNullException(nameof(indexes)); } if (request == null) { throw new ArgumentNullException(nameof(request)); } if (request.UnchangedSince.HasValue && !supportsModSeq) { throw new NotSupportedException("The ImapFolder does not support mod-sequences."); } CheckState(true, true); if (indexes.Count == 0) { return(new int[0]); } int numKeywords = request.Keywords != null ? request.Keywords.Count : 0; string action; switch (request.Action) { case StoreAction.Add: if ((request.Flags & SettableFlags) == 0 && numKeywords == 0) { return(new int[0]); } action = request.Silent ? "+FLAGS.SILENT" : "+FLAGS"; break; case StoreAction.Remove: if ((request.Flags & SettableFlags) == 0 && numKeywords == 0) { return(new int[0]); } action = request.Silent ? "-FLAGS.SILENT" : "-FLAGS"; break; default: action = request.Silent ? "FLAGS.SILENT" : "FLAGS"; break; } var keywordList = request.Keywords != null?request.Keywords.ToArray() : new object[0]; var command = new StringBuilder("STORE "); ImapUtils.FormatIndexSet(Engine, command, indexes); command.Append(' '); if (request.UnchangedSince.HasValue) { command.Append("(UNCHANGEDSINCE "); command.Append(request.UnchangedSince.Value.ToString(CultureInfo.InvariantCulture)); command.Append(") "); } command.Append(action); command.Append(' '); ImapUtils.FormatFlagsList(command, request.Flags & PermanentFlags, request.Keywords != null ? request.Keywords.Count : 0); command.Append("\r\n"); var ic = Engine.QueueCommand(cancellationToken, this, command.ToString(), keywordList); await Engine.RunAsync(ic, doAsync).ConfigureAwait(false); ProcessResponseCodes(ic, null); if (ic.Response != ImapCommandResponse.Ok) { throw ImapCommandException.Create("STORE", ic); } return(GetUnmodified(ic, request.UnchangedSince)); }