FormatFlagsList() публичный статический Метод

Formats a flags list suitable for use with the APPEND command.
public static FormatFlagsList ( MessageFlags flags, int numUserFlags ) : string
flags MessageFlags The message flags.
numUserFlags int The number of user-defined flags.
Результат string
Пример #1
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);
        }
Пример #2
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));
        }