Inheritance: CommandException
示例#1
0
        async Task <IList <int> > StoreAsync(IList <int> indexes, ulong?modseq, IList <Annotation> annotations, 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.");
            }

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

            CheckState(true, true);

            if (AnnotationAccess == AnnotationAccess.None)
            {
                throw new NotSupportedException("The ImapFolder does not support annotations.");
            }

            if (indexes.Count == 0 || annotations.Count == 0)
            {
                return(new int[0]);
            }

            var set     = ImapUtils.FormatIndexSet(indexes);
            var builder = new StringBuilder("STORE ");
            var values  = new List <object> ();

            builder.AppendFormat("{0} ", set);

            if (modseq.HasValue)
            {
                builder.AppendFormat(CultureInfo.InvariantCulture, "(UNCHANGEDSINCE {0}) ", modseq.Value);
            }

            ImapUtils.FormatAnnotations(builder, annotations, values, true);
            builder.Append("\r\n");

            var command = builder.ToString();
            var args    = values.ToArray();

            var ic = Engine.QueueCommand(cancellationToken, this, command, args);

            await Engine.RunAsync(ic, doAsync).ConfigureAwait(false);

            ProcessResponseCodes(ic, null);

            if (ic.Response != ImapCommandResponse.Ok)
            {
                throw ImapCommandException.Create("STORE", ic);
            }

            return(GetUnmodified(ic, modseq));
        }
示例#2
0
        async Task <IList <UniqueId> > StoreAsync(IList <UniqueId> uids, ulong?modseq, IList <Annotation> annotations, 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.");
            }

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

            CheckState(true, true);

            if (AnnotationAccess == AnnotationAccess.None)
            {
                throw new NotSupportedException("The ImapFolder does not support annotations.");
            }

            if (uids.Count == 0 || annotations.Count == 0)
            {
                return(new UniqueId[0]);
            }

            var         builder  = new StringBuilder("UID STORE %s ");
            var         values   = new List <object> ();
            UniqueIdSet modified = null;

            if (modseq.HasValue)
            {
                builder.AppendFormat(CultureInfo.InvariantCulture, "(UNCHANGEDSINCE {0}) ", modseq.Value);
            }

            ImapUtils.FormatAnnotations(builder, annotations, values, true);
            builder.Append("\r\n");

            var command = builder.ToString();
            var args    = values.ToArray();

            foreach (var ic in Engine.QueueCommands(cancellationToken, this, command, uids, args))
            {
                await Engine.RunAsync(ic, doAsync).ConfigureAwait(false);

                ProcessResponseCodes(ic, null);

                if (ic.Response != ImapCommandResponse.Ok)
                {
                    throw ImapCommandException.Create("STORE", ic);
                }

                if (modseq.HasValue)
                {
                    var rc = ic.RespCodes.OfType <ModifiedResponseCode> ().FirstOrDefault();

                    if (rc != null)
                    {
                        if (modified != null)
                        {
                            modified.AddRange(rc.UidSet);
                        }
                        else
                        {
                            modified = rc.UidSet;
                        }
                    }
                }
            }

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

            return(modified);
        }
示例#3
0
        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);
        }
示例#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));
        }
示例#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);
        }
示例#6
0
        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));
        }