Ejemplo n.º 1
0
 /// <summary>
 /// Asynchronously store GMail-style labels for a set of messages.
 /// </summary>
 /// <remarks>
 /// Asynchronously updates the GMail-style labels 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 GMail-style labels 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, IStoreLabelsRequest request, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(StoreAsync(indexes, request, true, cancellationToken));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Store GMail-style labels for a set of messages.
 /// </summary>
 /// <remarks>
 /// Updates the GMail-style labels 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 GMail-style labels 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, IStoreLabelsRequest request, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(StoreAsync(indexes, request, false, cancellationToken).GetAwaiter().GetResult());
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Asynchronously store GMail-style labels for a set of messages.
 /// </summary>
 /// <remarks>
 /// Asynchronously updates the GMail-style labels 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 GMail-style labels 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, IStoreLabelsRequest request, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(StoreAsync(uids, request, true, cancellationToken));
 }
Ejemplo n.º 4
0
        async Task <IList <int> > StoreAsync(IList <int> indexes, IStoreLabelsRequest request, bool doAsync, CancellationToken cancellationToken)
        {
            if (indexes == null)
            {
                throw new ArgumentNullException(nameof(indexes));
            }

            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            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]);
            }

            string action;

            switch (request.Action)
            {
            case StoreAction.Add:
                if (request.Labels == null || request.Labels.Count == 0)
                {
                    return(new int[0]);
                }

                action = request.Silent ? "+X-GM-LABELS.SILENT" : "+X-GM-LABELS";
                break;

            case StoreAction.Remove:
                if (request.Labels == null || request.Labels.Count == 0)
                {
                    return(new int[0]);
                }

                action = request.Silent ? "-X-GM-LABELS.SILENT" : "-X-GM-LABELS";
                break;

            default:
                action = request.Silent ? "X-GM-LABELS.SILENT" : "X-GM-LABELS";
                break;
            }

            var set     = ImapUtils.FormatIndexSet(Engine, indexes);
            var @params = string.Empty;

            if (request.UnchangedSince.HasValue)
            {
                @params = string.Format(CultureInfo.InvariantCulture, " (UNCHANGEDSINCE {0})", request.UnchangedSince.Value);
            }

            var args   = new List <object> ();
            var list   = LabelListToString(request.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, request.UnchangedSince));
        }
Ejemplo n.º 5
0
        async Task <IList <UniqueId> > StoreAsync(IList <UniqueId> uids, IStoreLabelsRequest request, bool doAsync, CancellationToken cancellationToken)
        {
            if (uids == null)
            {
                throw new ArgumentNullException(nameof(uids));
            }

            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            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]);
            }

            string action;

            switch (request.Action)
            {
            case StoreAction.Add:
                if (request.Labels == null || request.Labels.Count == 0)
                {
                    return(new UniqueId[0]);
                }

                action = request.Silent ? "+X-GM-LABELS.SILENT" : "+X-GM-LABELS";
                break;

            case StoreAction.Remove:
                if (request.Labels == null || request.Labels.Count == 0)
                {
                    return(new UniqueId[0]);
                }

                action = request.Silent ? "-X-GM-LABELS.SILENT" : "-X-GM-LABELS";
                break;

            default:
                action = request.Silent ? "X-GM-LABELS.SILENT" : "X-GM-LABELS";
                break;
            }

            var         command    = new StringBuilder("UID STORE %s ");
            var         args       = new List <object> ();
            UniqueIdSet unmodified = null;

            if (request.UnchangedSince.HasValue)
            {
                command.Append("(UNCHANGEDSINCE ");
                command.Append(request.UnchangedSince.Value.ToString(CultureInfo.InvariantCulture));
                command.Append(") ");
            }

            command.Append(action);
            command.Append(' ');
            AppendLabelList(command, request.Labels, args);
            command.Append("\r\n");

            foreach (var ic in Engine.QueueCommands(cancellationToken, this, command.ToString(), 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, request.UnchangedSince);
            }

            if (unmodified == null)
            {
                return(new UniqueId[0]);
            }

            return(unmodified);
        }