Ejemplo n.º 1
0
            public async Task <cMessageHandleList> SortExtendedAsync(cMethodControl pMC, iMailboxHandle pMailboxHandle, cFilter pFilter, cSort pSort, cTrace.cContext pParentContext)
            {
                var lContext = pParentContext.NewMethod(nameof(cSession), nameof(SortExtendedAsync), pMC, pMailboxHandle, pFilter, pSort);

                if (mDisposed)
                {
                    throw new ObjectDisposedException(nameof(cSession));
                }
                if (_ConnectionState != eConnectionState.selected)
                {
                    throw new InvalidOperationException(kInvalidOperationExceptionMessage.NotSelected);
                }
                if (pMailboxHandle == null)
                {
                    throw new ArgumentNullException(nameof(pMailboxHandle));
                }
                if (pFilter == null)
                {
                    throw new ArgumentNullException(nameof(pFilter));
                }
                if (pSort == null)
                {
                    throw new ArgumentNullException(nameof(pSort));
                }

                using (var lBuilder = new cCommandDetailsBuilder())
                {
                    lBuilder.Add(await mSelectExclusiveAccess.GetBlockAsync(pMC, lContext).ConfigureAwait(false)); // block select

                    var lSelectedMailbox = mMailboxCache.CheckIsSelectedMailbox(pMailboxHandle, pFilter.UIDValidity);

                    // special case
                    if (ReferenceEquals(pFilter, cFilter.None))
                    {
                        return(new cMessageHandleList());
                    }

                    if (pFilter.ContainsMessageHandles)
                    {
                        lBuilder.Add(await mMSNUnsafeBlock.GetTokenAsync(pMC, lContext).ConfigureAwait(false)); // wait until all commands that are msnunsafe complete, block all commands that are msnunsafe
                    }
                    lBuilder.AddUIDValidity(lSelectedMailbox.MessageCache.UIDValidity);                         // if a UIDValidity change happens while the command is running, disbelieve the results

                    lBuilder.Add(kSortExtendedCommandPart);
                    lBuilder.Add(pSort);
                    lBuilder.Add(cCommandPart.Space);
                    lBuilder.Add(pFilter, lSelectedMailbox, true, mEncodingPartFactory);

                    var lHook = new cCommandHookSearchExtended(lBuilder.Tag, lSelectedMailbox, true);
                    lBuilder.Add(lHook);

                    var lResult = await mPipeline.ExecuteAsync(pMC, lBuilder.EmitCommandDetails(), lContext).ConfigureAwait(false);

                    if (lResult.ResultType == eCommandResultType.ok)
                    {
                        lContext.TraceInformation("extended sort success");
                        if (lHook.MessageHandles == null)
                        {
                            throw new cUnexpectedServerActionException(fCapabilities.esort, "results not received on a successful extended sort", lContext);
                        }
                        return(lHook.MessageHandles);
                    }

                    if (lHook.MessageHandles != null)
                    {
                        lContext.TraceError("results received on a failed extended sort");
                    }

                    if (lResult.ResultType == eCommandResultType.no)
                    {
                        throw new cUnsuccessfulCompletionException(lResult.ResponseText, fCapabilities.esort, lContext);
                    }
                    throw new cProtocolErrorException(lResult, fCapabilities.esort, lContext);
                }
            }
Ejemplo n.º 2
0
        private async Task <List <cMessage> > ZZMessagesAsync(cMethodControl pMC, iMailboxHandle pMailboxHandle, cFilter pFilter, cSort pSort, cMessageCacheItems pItems, cMessageFetchConfiguration pConfiguration, cTrace.cContext pParentContext)
        {
            var lContext = pParentContext.NewMethod(nameof(cIMAPClient), nameof(ZZMessagesAsync), pMC, pMailboxHandle, pFilter, pSort, pItems);

            if (mDisposed)
            {
                throw new ObjectDisposedException(nameof(cIMAPClient));
            }

            var lSession = mSession;

            if (lSession == null || lSession.ConnectionState != eConnectionState.selected)
            {
                throw new InvalidOperationException(kInvalidOperationExceptionMessage.NotSelected);
            }

            if (pMailboxHandle == null)
            {
                throw new ArgumentNullException(nameof(pMailboxHandle));
            }
            if (pFilter == null)
            {
                throw new ArgumentNullException(nameof(pFilter));
            }
            if (pSort == null)
            {
                throw new ArgumentNullException(nameof(pSort));
            }
            if (pItems == null)
            {
                throw new ArgumentNullException(nameof(pItems));
            }

            cMessageCacheItems lItems;

            if (ReferenceEquals(pSort, cSort.None))
            {
                lItems = pItems;
            }

            /* de-implemented pending a requirement to complete it
             * else if (ReferenceEquals(pSort, cSort.ThreadOrderedSubject))
             * {
             *  if (lSession.Capabilities.ThreadOrderedSubject) return await ZMessagesThreadAsync(pMC, lSession, pHandle, eMessageThreadAlgorithm.orderedsubject, pFilter, pItems, pConfiguration, lContext).ConfigureAwait(false);
             *  lItems = new cCacheItems(pItems.Attributes | fCacheAttributes.envelope | fCacheAttributes.received, pItems.Names);
             * }
             * else if (ReferenceEquals(pSort, cSort.ThreadReferences))
             * {
             *  if (lSession.Capabilities.ThreadReferences) return await ZMessagesThreadAsync(pMC, lSession, pHandle, eMessageThreadAlgorithm.references, pFilter, pItems, pConfiguration, lContext).ConfigureAwait(false);
             *  lItems = new cCacheItems(pItems.Attributes | fCacheAttributes.envelope | fCacheAttributes.received, pItems.Names.Union(cHeaderFieldNames.References));
             * } */
            else
            {
                var lSortAttributes = pSort.Attributes(out var lSortDisplay);
                if (!lSortDisplay && lSession.Capabilities.Sort || lSortDisplay && lSession.Capabilities.SortDisplay)
                {
                    return(await ZMessagesSortAsync(pMC, lSession, pMailboxHandle, pSort, pFilter, pItems, pConfiguration, lContext).ConfigureAwait(false));
                }
                lItems = new cMessageCacheItems(pItems.Attributes | lSortAttributes, pItems.Names);
            }

            cMessageHandleList lMessageHandles;

            if (lSession.Capabilities.ESearch)
            {
                lMessageHandles = await lSession.SearchExtendedAsync(pMC, pMailboxHandle, pFilter, lContext).ConfigureAwait(false);
            }
            else
            {
                lMessageHandles = await lSession.SearchAsync(pMC, pMailboxHandle, pFilter, lContext).ConfigureAwait(false);
            }

            // get the properties
            await ZMessagesFetchAsync(pMC, lSession, lMessageHandles, lItems, pConfiguration, lContext).ConfigureAwait(false);

            if (ReferenceEquals(pSort, cSort.None))
            {
                return(ZMessagesFlatMessageList(lMessageHandles, lContext));
            }

            // client side sorting

            // de-implemented pending a requirement to complete it
            // if (ReferenceEquals(pSort, cSort.ThreadOrderedSubject)) return ZMessagesThreadOrderedSubject(lHandles, lContext);
            // if (ReferenceEquals(pSort, cSort.ThreadReferences)) return ZMessagesThreadReferences(lHandles, lContext);

            lMessageHandles.Sort(pSort);
            return(ZMessagesFlatMessageList(lMessageHandles, lContext));
        }
Ejemplo n.º 3
0
        private async Task <List <cMessage> > ZMessagesAsync(iMailboxHandle pMailboxHandle, cFilter pFilter, cSort pSort, cMessageCacheItems pItems, cMessageFetchConfiguration pConfiguration, cTrace.cContext pParentContext)
        {
            var lContext = pParentContext.NewMethod(nameof(cIMAPClient), nameof(ZMessagesAsync), pMailboxHandle, pFilter, pSort, pItems);

            if (pConfiguration == null)
            {
                using (var lToken = mCancellationManager.GetToken(lContext))
                {
                    var lMC = new cMethodControl(mTimeout, lToken.CancellationToken);
                    return(await ZZMessagesAsync(lMC, pMailboxHandle, pFilter, pSort, pItems, null, lContext).ConfigureAwait(false));
                }
            }
            else
            {
                var lMC = new cMethodControl(pConfiguration.Timeout, pConfiguration.CancellationToken);
                return(await ZZMessagesAsync(lMC, pMailboxHandle, pFilter, pSort, pItems, pConfiguration, lContext).ConfigureAwait(false));
            }
        }
Ejemplo n.º 4
0
        internal Task <List <cMessage> > MessagesAsync(iMailboxHandle pMailboxHandle, cFilter pFilter, cSort pSort, cMessageCacheItems pItems, cMessageFetchConfiguration pConfiguration)
        {
            var lContext = mRootContext.NewMethod(nameof(cIMAPClient), nameof(MessagesAsync));

            return(ZMessagesAsync(pMailboxHandle, pFilter, pSort, pItems, pConfiguration, lContext));
        }
Ejemplo n.º 5
0
        internal List <cMessage> Messages(iMailboxHandle pMailboxHandle, cFilter pFilter, cSort pSort, cMessageCacheItems pItems, cMessageFetchConfiguration pConfiguration)
        {
            var lContext = mRootContext.NewMethod(nameof(cIMAPClient), nameof(Messages));
            var lTask    = ZMessagesAsync(pMailboxHandle, pFilter, pSort, pItems, pConfiguration, lContext);

            mSynchroniser.Wait(lTask, lContext);
            return(lTask.Result);
        }
Ejemplo n.º 6
0
        private async Task <List <cMessage> > ZMessagesSortAsync(cMethodControl pMC, cSession pSession, iMailboxHandle pMailboxHandle, cSort pSort, cFilter pFilter, cMessageCacheItems pItems, cMessageFetchConfiguration pConfiguration, cTrace.cContext pParentContext)
        {
            var lContext = pParentContext.NewMethod(nameof(cIMAPClient), nameof(ZMessagesSortAsync), pMC, pMailboxHandle, pSort, pFilter, pItems);

            cMessageHandleList lMessageHandles;

            if (pSession.Capabilities.ESort)
            {
                lMessageHandles = await pSession.SortExtendedAsync(pMC, pMailboxHandle, pFilter, pSort, lContext).ConfigureAwait(false);
            }
            else
            {
                lMessageHandles = await pSession.SortAsync(pMC, pMailboxHandle, pFilter, pSort, lContext).ConfigureAwait(false);
            }

            await ZMessagesFetchAsync(pMC, pSession, lMessageHandles, pItems, pConfiguration, lContext).ConfigureAwait(false);

            return(ZMessagesFlatMessageList(lMessageHandles, lContext));
        }